Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Sep 22, 2023
1 parent 2c8cdea commit 2bbccac
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 215 deletions.
4 changes: 1 addition & 3 deletions src/basicAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export default function BasicAppBar(): JSX.Element {
const updateCameraTube = useCameraTubeStore(
(state) => state.updateCameraTube,
);
const updateBeamlineConfig = useBeamlineConfigStore(
(state) => state.update,
);
const updateBeamlineConfig = useBeamlineConfigStore((state) => state.update);
const updateDetector = useDetectorStore((state) => state.updateDetector);
const handlePreset = (preset: string) => {
const { beamstop, cameraTube, detector, ...beamlineConfig } =
Expand Down
2 changes: 1 addition & 1 deletion src/calculations/numericRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class NumericRange {

intersect(other: NumericRange | null): NumericRange | null {
if (other === null) {
return null
return null;
}
if (other.min > this.max || this.min > other.max) return null;

Expand Down
69 changes: 37 additions & 32 deletions src/calculations/qrange.test.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
import { test } from "vitest";
import { computeQrange } from "./qrange";
import { BeamlineConfig, Beamstop, CircularDevice, Detector } from "../utils/types";
import {
BeamlineConfig,
Beamstop,
CircularDevice,
Detector,
} from "../utils/types";

test("Test getting q from pixel position ", () => {
const detector: Detector = {
resolution: {
height: 1679,
width: 1465,
},
pixelSize: {
height: 0.172,
width: 0.172
}
}
const beamstop: Beamstop = {
centre: { x: 738, y: 100 },
diameter: 4,
clearance: 10
}
const beamConfig: BeamlineConfig = {
angle: 1.57,
cameraLength: 1.9,
minWavelength: 6.2e-2,
maxWavelength: 0.335,
minCameraLength: 0,
maxCameraLength: 4,
energy: 60,
wavelength: 2e-2
}
const cameraTube: CircularDevice = {
centre: { x: 738, y: 840 },
diameter: 310
}
const detector: Detector = {
resolution: {
height: 1679,
width: 1465,
},
pixelSize: {
height: 0.172,
width: 0.172,
},
};
const beamstop: Beamstop = {
centre: { x: 738, y: 100 },
diameter: 4,
clearance: 10,
};
const beamConfig: BeamlineConfig = {
angle: 1.57,
cameraLength: 1.9,
minWavelength: 6.2e-2,
maxWavelength: 0.335,
minCameraLength: 0,
maxCameraLength: 4,
energy: 60,
wavelength: 2e-2,
};
const cameraTube: CircularDevice = {
centre: { x: 738, y: 840 },
diameter: 310,
};

const result = computeQrange(detector, beamstop, cameraTube, beamConfig)
console.log(result)
const result = computeQrange(detector, beamstop, cameraTube, beamConfig);
console.log(result);
});
141 changes: 101 additions & 40 deletions src/calculations/qrange.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,114 @@
import QSpace, { DetectorProperties, DiffractionCrystalEnvironment } from "../calculations/qspace";
import { BeamlineConfig, Beamstop, CircularDevice, Detector } from "../utils/types";
import QSpace, {
DetectorProperties,
DiffractionCrystalEnvironment,
} from "../calculations/qspace";
import {
BeamlineConfig,
Beamstop,
CircularDevice,
Detector,
} from "../utils/types";
import { Vector3, Vector4 } from "three";
import { Ray } from "../calculations/ray";

export function computeQrange(
detector: Detector,
beamstop: Beamstop,
cameraTube: CircularDevice,
beamProperties: BeamlineConfig,
) {
const initialPosition = new Vector3(
beamstop.clearance ??
0 * Math.cos(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0),
beamstop.clearance ??
0 * Math.sin(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0),
);

export function computeQrange(detector: Detector, beamstop: Beamstop, cameraTube: CircularDevice, beamProperties: BeamlineConfig) {
const initialPosition = new Vector3(beamstop.clearance ?? 0 * Math.cos(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0),
beamstop.clearance ?? 0 * Math.sin(beamProperties.angle ?? 0) + (beamstop.centre.y ?? 0))
const ray = new Ray(
new Vector3(
Math.cos(beamProperties.angle ?? 0),
Math.sin(beamProperties.angle ?? 0),
),
initialPosition,
);
let t1 = ray.getRectangleIntersectionParameterRange(
new Vector3(0, detector.resolution.height),
detector.resolution.width,
detector.resolution.height,
);

const ray = new Ray(new Vector3(Math.cos(beamProperties.angle ?? 0), Math.sin(beamProperties.angle ?? 0)), initialPosition);
let t1 = ray.getRectangleIntersectionParameterRange(new Vector3(0, detector.resolution.height), detector.resolution.width, detector.resolution.height)
if (t1 != null && cameraTube != null && cameraTube.diameter != 0) {
t1 = t1.intersect(
ray.getCircleIntersectionParameterRange(
(cameraTube.diameter ?? 0) / 2,
new Vector3(cameraTube.centre.x ?? 0, cameraTube.centre.y ?? 0),
),
);
}
console.log(t1);
if (
t1 === null ||
beamProperties.wavelength == null ||
beamProperties.cameraLength == null
) {
return null;
}

if (t1 != null && cameraTube != null && cameraTube.diameter != 0) {
t1 = t1.intersect(ray.getCircleIntersectionParameterRange((cameraTube.diameter ?? 0) / 2, new Vector3(cameraTube.centre.x ?? 0, cameraTube.centre.y ?? 0)));
}
console.log(t1)
if (t1 === null || beamProperties.wavelength == null || beamProperties.cameraLength == null) {
return null
}
const ptMin = ray.getPoint(t1.min);
const ptMax = ray.getPoint(t1.max);

const ptMin = ray.getPoint(t1.min);
const ptMax = ray.getPoint(t1.max);
const detProps: DetectorProperties = {
...detector,
origin: new Vector3(
beamstop.centre.x ?? 0,
beamstop.centre.y ?? 0,
beamProperties.cameraLength * 1e-3,
),
beamVector: new Vector3(0, 0, 1),
};

const detProps: DetectorProperties = {
...detector,
origin: new Vector3(beamstop.centre.x ?? 0, beamstop.centre.y ?? 0, beamProperties.cameraLength * 1e-3),
beamVector: new Vector3(0, 0, 1)
}
const diffCrystEnv: DiffractionCrystalEnvironment = {
wavelength: beamProperties.wavelength * 1e10,
referenceNormal: new Vector3(0, 1, 0),
strokesVector: new Vector4(1, 1, 0, 0),
};

const diffCrystEnv: DiffractionCrystalEnvironment = {
wavelength: beamProperties.wavelength * 1e10,
referenceNormal: new Vector3(0, 1, 0),
strokesVector: new Vector4(1, 1, 0, 0)
}
const qspace = new QSpace(detProps, diffCrystEnv, 2 * Math.PI);

const qspace = new QSpace(detProps, diffCrystEnv, 2 * Math.PI)
// get visible range
const visibleQmin = qspace.qFromPixelPosition(
ptMin.x / detector.pixelSize.width,
ptMin.y / detector.pixelSize.height,
);
const visibleQmax = qspace.qFromPixelPosition(
ptMax.x / detector.pixelSize.width,
ptMax.y / detector.pixelSize.height,
);

// get visible range
const visibleQmin = qspace.qFromPixelPosition(ptMin.x / detector.pixelSize.width, ptMin.y / detector.pixelSize.height)
const visibleQmax = qspace.qFromPixelPosition(ptMax.x / detector.pixelSize.width, ptMax.y / detector.pixelSize.height)
detProps.origin.z = beamProperties.minCameraLength * 1e3;
qspace.setDiffractionCrystalEnviroment({
...diffCrystEnv,
wavelength: beamProperties.minCameraLength * 1e10,
});
const fullQMin = qspace.qFromPixelPosition(
ptMin.x / detector.pixelSize.width,
ptMin.y / detector.pixelSize.height,
);

detProps.origin.z = beamProperties.minCameraLength * 1e3
qspace.setDiffractionCrystalEnviroment({ ...diffCrystEnv, wavelength: beamProperties.minCameraLength * 1e10 })
const fullQMin = qspace.qFromPixelPosition(ptMin.x / detector.pixelSize.width, ptMin.y / detector.pixelSize.height)
detProps.origin.z = beamProperties.maxCameraLength * 1e3;
qspace.setDiffractionCrystalEnviroment({
...diffCrystEnv,
wavelength: beamProperties.maxCameraLength * 1e10,
});
const fullQMax = qspace.qFromPixelPosition(
ptMax.x / detector.pixelSize.width,
ptMax.y / detector.pixelSize.height,
);

detProps.origin.z = beamProperties.maxCameraLength * 1e3
qspace.setDiffractionCrystalEnviroment({ ...diffCrystEnv, wavelength: beamProperties.maxCameraLength * 1e10 })
const fullQMax = qspace.qFromPixelPosition(ptMax.x / detector.pixelSize.width, ptMax.y / detector.pixelSize.height)

return { visibleQmin: visibleQmin, visibleQmax: visibleQmax, fullQMax: fullQMax, fullQMin: fullQMin }

}
return {
visibleQmin: visibleQmin,
visibleQmax: visibleQmax,
fullQMax: fullQMax,
fullQMin: fullQMin,
};
}
42 changes: 21 additions & 21 deletions src/calculations/qspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { Vector4, Vector3 } from "three";
import QSpace, { DetectorProperties } from "./qspace";

test("Test getting q from pixel position ", () => {
const detProps: DetectorProperties = {
resolution: {
height: 1,
width: 1
},
pixelSize: {
height: 1,
width: 1
},
origin: new Vector3(0, 0, 0),
beamVector: new Vector3(1, 1, 0),
}
const detProps: DetectorProperties = {
resolution: {
height: 1,
width: 1,
},
pixelSize: {
height: 1,
width: 1,
},
origin: new Vector3(0, 0, 0),
beamVector: new Vector3(1, 1, 0),
};

const diffCrystEnv = {
wavelength: 1,
referenceNormal: new Vector3(1, 1, 1),
strokesVector: new Vector4(1, 0, 1, 0),
}
const diffCrystEnv = {
wavelength: 1,
referenceNormal: new Vector3(1, 1, 1),
strokesVector: new Vector4(1, 0, 1, 0),
};

const qspace = new QSpace(detProps, diffCrystEnv, 1)
const result = qspace.qFromPixelPosition(1, 1)
expect(result).toBeInstanceOf(Vector3)
// do better testing when you understand it better
const qspace = new QSpace(detProps, diffCrystEnv, 1);
const result = qspace.qFromPixelPosition(1, 1);
expect(result).toBeInstanceOf(Vector3);
// do better testing when you understand it better
});
Loading

0 comments on commit 2bbccac

Please sign in to comment.