diff --git a/src/basicAppBar.tsx b/src/basicAppBar.tsx index cc165f3..1d1dce4 100644 --- a/src/basicAppBar.tsx +++ b/src/basicAppBar.tsx @@ -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 } = diff --git a/src/calculations/numericRange.ts b/src/calculations/numericRange.ts index ed4b3dd..08181cd 100644 --- a/src/calculations/numericRange.ts +++ b/src/calculations/numericRange.ts @@ -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; diff --git a/src/calculations/qrange.test.ts b/src/calculations/qrange.test.ts index de782e6..294290e 100644 --- a/src/calculations/qrange.test.ts +++ b/src/calculations/qrange.test.ts @@ -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); }); diff --git a/src/calculations/qrange.ts b/src/calculations/qrange.ts index 7b70fbf..ac3c8fe 100644 --- a/src/calculations/qrange.ts +++ b/src/calculations/qrange.ts @@ -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 } - -} \ No newline at end of file + return { + visibleQmin: visibleQmin, + visibleQmax: visibleQmax, + fullQMax: fullQMax, + fullQMin: fullQMin, + }; +} diff --git a/src/calculations/qspace.test.ts b/src/calculations/qspace.test.ts index 0a9854d..d48968c 100644 --- a/src/calculations/qspace.test.ts +++ b/src/calculations/qspace.test.ts @@ -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 }); diff --git a/src/calculations/qspace.ts b/src/calculations/qspace.ts index 9ed604d..8d472bc 100644 --- a/src/calculations/qspace.ts +++ b/src/calculations/qspace.ts @@ -2,55 +2,63 @@ import { Vector3, Vector4 } from "three"; import { Detector } from "../utils/types"; export interface DiffractionCrystalEnvironment { - wavelength: number; - referenceNormal: Vector3; - strokesVector: Vector4; + wavelength: number; + referenceNormal: Vector3; + strokesVector: Vector4; } export interface DetectorProperties extends Detector { - origin: Vector3; - beamVector: Vector3; + origin: Vector3; + beamVector: Vector3; } export default class QSpace { - detProps: DetectorProperties; - kmod: number; - reference: Vector3; - strokes: Vector4; - qScale: number; - mki: Vector3; + detProps: DetectorProperties; + kmod: number; + reference: Vector3; + strokes: Vector4; + qScale: number; + mki: Vector3; - constructor(detProps: DetectorProperties, diffexp: DiffractionCrystalEnvironment, qScale: number) { - this.detProps = detProps; - detProps.beamVector.normalize() - this.qScale = qScale - this.mki = new Vector3().copy(detProps.beamVector).negate() - this.kmod = this.qScale / diffexp.wavelength; - this.reference = diffexp.referenceNormal; - this.strokes = diffexp.strokesVector; - } + constructor( + detProps: DetectorProperties, + diffexp: DiffractionCrystalEnvironment, + qScale: number, + ) { + this.detProps = detProps; + detProps.beamVector.normalize(); + this.qScale = qScale; + this.mki = new Vector3().copy(detProps.beamVector).negate(); + this.kmod = this.qScale / diffexp.wavelength; + this.reference = diffexp.referenceNormal; + this.strokes = diffexp.strokesVector; + } - convertToQ(q: Vector3) { - const qLength = q.length(); - if (qLength > 0) { - q.multiplyScalar(this.kmod / qLength); - q.add(this.mki) - } else { - q.add(this.mki); - } + convertToQ(q: Vector3) { + const qLength = q.length(); + if (qLength > 0) { + q.multiplyScalar(this.kmod / qLength); + q.add(this.mki); + } else { + q.add(this.mki); } + } - qFromPixelPosition(x: number, y: number) { - const q = new Vector3(); - q.set(-this.detProps.pixelSize.height * (x), -this.detProps.pixelSize.width * (y), 0); - q.add(this.detProps.origin); - this.convertToQ(q); - return q - } + qFromPixelPosition(x: number, y: number) { + const q = new Vector3(); + q.set( + -this.detProps.pixelSize.height * x, + -this.detProps.pixelSize.width * y, + 0, + ); + q.add(this.detProps.origin); + this.convertToQ(q); + return q; + } - setDiffractionCrystalEnviroment(diffexp: DiffractionCrystalEnvironment) { - this.kmod = this.qScale / diffexp.wavelength; - this.reference = diffexp.referenceNormal; - this.strokes = diffexp.strokesVector; - } + setDiffractionCrystalEnviroment(diffexp: DiffractionCrystalEnvironment) { + this.kmod = this.qScale / diffexp.wavelength; + this.reference = diffexp.referenceNormal; + this.strokes = diffexp.strokesVector; + } } diff --git a/src/calculations/qvalue.ts b/src/calculations/qvalue.ts index 2afc1df..6b11486 100644 --- a/src/calculations/qvalue.ts +++ b/src/calculations/qvalue.ts @@ -2,29 +2,52 @@ import { Beamstop } from "../utils/types"; import { Ray } from "./ray"; import { Vector3 } from "three"; -export const calculateQValue = (distance: number, cameraLength: number, wavelength: number): number | null => { - if (cameraLength === 0 || wavelength == 0) { - return null; - } - if (cameraLength < 0 || distance < 0 || wavelength < 0) { - return null; - } - return 4 * Math.PI * Math.sin(Math.atan(distance / cameraLength) / 2) / wavelength; +export const calculateQValue = ( + distance: number, + cameraLength: number, + wavelength: number, +): number | null => { + if (cameraLength === 0 || wavelength == 0) { + return null; + } + if (cameraLength < 0 || distance < 0 || wavelength < 0) { + return null; + } + return ( + (4 * Math.PI * Math.sin(Math.atan(distance / cameraLength) / 2)) / + wavelength + ); }; -export const calculateDistanceFromQValue = (qValue: number, cameraLength: number, wavelength: number): number | null => { - if (qValue < 0 || cameraLength < 0 || wavelength < 0) { - return null; - } - const temp = wavelength * qValue / (4 * Math.PI); +export const calculateDistanceFromQValue = ( + qValue: number, + cameraLength: number, + wavelength: number, +): number | null => { + if (qValue < 0 || cameraLength < 0 || wavelength < 0) { + return null; + } + const temp = (wavelength * qValue) / (4 * Math.PI); - if (Math.abs(temp) >= Math.sqrt(2) / 2) { - return null; - } - return Math.tan(2 * Math.asin(temp)) * cameraLength; + if (Math.abs(temp) >= Math.sqrt(2) / 2) { + return null; + } + return Math.tan(2 * Math.asin(temp)) * cameraLength; }; -export const getPointForQ = (qValue: number, angle: number, cameralength: number, wavelength: number, beamstop: Beamstop): Vector3 => { - const ray = new Ray(new Vector3(Math.cos(angle), Math.sin(angle)), new Vector3(beamstop.centre.x ?? 0, beamstop.centre.y ?? 0)); - return ray.getPointAtDistance(1.0e3 * (calculateDistanceFromQValue(qValue, cameralength, wavelength) ?? 0)); +export const getPointForQ = ( + qValue: number, + angle: number, + cameralength: number, + wavelength: number, + beamstop: Beamstop, +): Vector3 => { + const ray = new Ray( + new Vector3(Math.cos(angle), Math.sin(angle)), + new Vector3(beamstop.centre.x ?? 0, beamstop.centre.y ?? 0), + ); + return ray.getPointAtDistance( + 1.0e3 * + (calculateDistanceFromQValue(qValue, cameralength, wavelength) ?? 0), + ); }; diff --git a/src/calculations/ray.ts b/src/calculations/ray.ts index a4fe889..fd075d5 100644 --- a/src/calculations/ray.ts +++ b/src/calculations/ray.ts @@ -51,8 +51,8 @@ export class Ray { const b = 2 * coeffOfx2 * this.direction.x * this.initial_point.x + coeffOfxy * - (this.direction.x * this.initial_point.y + - this.direction.y * this.initial_point.x) + + (this.direction.x * this.initial_point.y + + this.direction.y * this.initial_point.x) + 2 * coeffOfy2 * this.direction.y * this.initial_point.y + coeffOfx * this.direction.x + coeffOfy * this.direction.y; @@ -140,6 +140,6 @@ export class Ray { (ymax - this.initial_point.y) / this.direction.y, ), ); - return this.getParameterRange(result!.min, result!.max) + return this.getParameterRange(result!.min, result!.max); } } diff --git a/src/data-entry/beamProperties.tsx b/src/data-entry/beamProperties.tsx index a81a4d2..574d876 100644 --- a/src/data-entry/beamProperties.tsx +++ b/src/data-entry/beamProperties.tsx @@ -41,9 +41,7 @@ export default function BeampropertiesDataEntry() { }); const energyUnits = useBeamlineConfigStore((state) => state.beamEnergyUnits); - const updateConfig = useBeamlineConfigStore( - (state) => state.update, - ); + const updateConfig = useBeamlineConfigStore((state) => state.update); const handleEnergy = (event: React.ChangeEvent) => { if (energyUnits === EnergyUnits.electronVolts && event.target.value) { updateConfig({ energy: parseFloat(event.target.value) / 1000 }); @@ -90,8 +88,9 @@ export default function BeampropertiesDataEntry() { const handleCameraLength = (event: React.ChangeEvent) => { updateConfig({ - cameraLength: - parseFloat(event.target.value) ? parseFloat(event.target.value) : null, + cameraLength: parseFloat(event.target.value) + ? parseFloat(event.target.value) + : null, }); }; @@ -113,7 +112,9 @@ export default function BeampropertiesDataEntry() { label="units" value={energyUnits} onChange={(event) => - updateConfig({ beamEnergyUnits: event.target.value as EnergyUnits }) + updateConfig({ + beamEnergyUnits: event.target.value as EnergyUnits, + }) } > @@ -140,7 +141,9 @@ export default function BeampropertiesDataEntry() { label="units" value={wavelengthUnits} onChange={(event) => - updateConfig({ wavelengthUnits: event.target.value as WavelengthUnits }) + updateConfig({ + wavelengthUnits: event.target.value as WavelengthUnits, + }) } > diff --git a/src/data-entry/beamlineconfigStore.ts b/src/data-entry/beamlineconfigStore.ts index 2617aaa..0f82ce6 100644 --- a/src/data-entry/beamlineconfigStore.ts +++ b/src/data-entry/beamlineconfigStore.ts @@ -23,5 +23,6 @@ export const useBeamlineConfigStore = create((set) => ({ beamEnergyUnits: EnergyUnits.kiloElectronVolts, angleUnits: AngleUnits.radians, wavelengthUnits: WavelengthUnits.nanmometres, - update: (storeConfig: Partial) => set({ ...storeConfig }), + update: (storeConfig: Partial) => + set({ ...storeConfig }), })); diff --git a/src/data-entry/beamstop.tsx b/src/data-entry/beamstop.tsx index 058bdd7..f5abedd 100644 --- a/src/data-entry/beamstop.tsx +++ b/src/data-entry/beamstop.tsx @@ -9,7 +9,7 @@ import { TextField, } from "@mui/material"; import { DistanceUnits } from "../utils/units"; -import { useBeamstopStore } from "./beamstopStore"; +import { BeamstopStore, useBeamstopStore } from "./beamstopStore"; import { useDetectorStore } from "./detectorStore"; export default function BeamStopDataEntry(): JSX.Element { @@ -26,17 +26,21 @@ export default function BeamStopDataEntry(): JSX.Element { }); }; - const diameter = useBeamstopStore((state) => { + const diameter = useBeamstopStore((state) => { if (state.diameterUnits === DistanceUnits.micrometre) { return 1000 * state.diameter; } return state.diameter; }); - const diameterUnits = useBeamstopStore((state) => state.diameterUnits); + const diameterUnits = useBeamstopStore( + (state: BeamstopStore) => state.diameterUnits, + ); const updateUnits = useBeamstopStore((state) => state.updateUnits); - const clearance = useBeamstopStore((state) => state.clearance); + const clearance = useBeamstopStore( + (state: BeamstopStore) => state.clearance, + ); const updateClearance = useBeamstopStore((state) => state.updateClearance); const handleClearance = (event: React.ChangeEvent) => { updateClearance( diff --git a/src/data-entry/cameraTubeStore.ts b/src/data-entry/cameraTubeStore.ts index a9b09c5..b8d7f68 100644 --- a/src/data-entry/cameraTubeStore.ts +++ b/src/data-entry/cameraTubeStore.ts @@ -1,10 +1,10 @@ -import { CircularDevice, SerialisedVector2 } from "../utils/types"; +import { CircularDevice, SimpleVector2 } from "../utils/types"; import { create } from "zustand"; import { DistanceUnits } from "../utils/units"; export interface CameraTubeStore extends CircularDevice { diameterUnits: DistanceUnits; - updateCentre: (centre: Partial) => void; + updateCentre: (centre: Partial) => void; updateUnits: (newUnits: DistanceUnits) => void; updateCameraTube: (presetCameraTube: CircularDevice) => void; } @@ -16,7 +16,7 @@ export const useCameraTubeStore = create((set) => ({ }, diameter: 1, diameterUnits: DistanceUnits.millimetre, - updateCentre: (newCentre: Partial) => + updateCentre: (newCentre: Partial) => set((state) => ({ centre: { ...state.centre, ...newCentre } })), updateUnits: (newUnits: DistanceUnits) => set({ diameterUnits: newUnits }), updateCameraTube: (presetCameraTube: CircularDevice) => set(presetCameraTube), diff --git a/src/plot/centrePlot.tsx b/src/plot/centrePlot.tsx index 4c2c01c..b461ded 100644 --- a/src/plot/centrePlot.tsx +++ b/src/plot/centrePlot.tsx @@ -69,14 +69,28 @@ export default function CentrePlot(): JSX.Element { // issue here needs working on const domains = getDomains(detector, cameraTube); - const getQRange = (detectorHeight: number, cameraTube: CircularDevice, beamstop: Beamstop): { visableRange: number, nonVisableRange: number } => { - const cameraTubeBottom = Math.sqrt((Math.pow(cameraTube.diameter / 2, 2) - Math.pow((beamstop.centre.x ?? 0) - (cameraTube.centre.x ?? 0), 2))) + (cameraTube.centre.y ?? 0); + const getQRange = ( + detectorHeight: number, + cameraTube: CircularDevice, + beamstop: Beamstop, + ): { visableRange: number; nonVisableRange: number } => { + const cameraTubeBottom = + Math.sqrt( + Math.pow(cameraTube.diameter / 2, 2) - + Math.pow((beamstop.centre.x ?? 0) - (cameraTube.centre.x ?? 0), 2), + ) + (cameraTube.centre.y ?? 0); const shorterEdge = Math.min(detectorHeight, cameraTubeBottom); - const clearance = (beamstop.centre.y ?? 0) + (beamstop.clearance ?? 0) + (beamstop.diameter / 2) + const clearance = + (beamstop.centre.y ?? 0) + + (beamstop.clearance ?? 0) + + beamstop.diameter / 2; if (clearance > shorterEdge) { - return { visableRange: beamstop.centre.y ?? 0, nonVisableRange: beamstop.centre.y ?? 0 } + return { + visableRange: beamstop.centre.y ?? 0, + nonVisableRange: beamstop.centre.y ?? 0, + }; } - return { visableRange: shorterEdge, nonVisableRange: clearance } + return { visableRange: shorterEdge, nonVisableRange: clearance }; }; const qrange = getQRange(detector.resolution.height, cameraTube, beamstop); @@ -111,17 +125,17 @@ export default function CentrePlot(): JSX.Element { beamstop.centre.y ?? 0, ), new Vector3( - (beamstop.centre.x ?? 0), + beamstop.centre.x ?? 0, (beamstop.centre.y ?? 0) + - (beamstop.diameter / 2) + - (beamstop.clearance ?? 0) + beamstop.diameter / 2 + + (beamstop.clearance ?? 0), ), new Vector3( cameraTube.centre.x ?? 0, cameraTube.centre.y ?? 0, ), new Vector3( - (cameraTube.centre.x ?? 0), + cameraTube.centre.x ?? 0, (cameraTube.centre.y ?? 0) + cameraTube.diameter / 2, ), new Vector3(0, 0), @@ -152,13 +166,14 @@ export default function CentrePlot(): JSX.Element { id="camera tube" /> )} - {(plotConfig.qrange && plotConfig.beamstop) && ( + {plotConfig.qrange && plotConfig.beamstop && ( )} - {(plotConfig.qrange && plotConfig.beamstop) && ( + /> + )} + {plotConfig.qrange && plotConfig.beamstop && ( { - plotConfig.update({ beamstop: checked }) - plotConfig.update({ qrange: checked }) - } - } + plotConfig.update({ beamstop: checked }); + plotConfig.update({ qrange: checked }); + }} /> } label="Beamstop" @@ -74,7 +73,9 @@ export default function LegendBar(): JSX.Element { control={ plotConfig.update({ mask: checked })} + onChange={(_, checked) => + plotConfig.update({ mask: checked }) + } /> } label="Mask" diff --git a/src/presets/detectors.json b/src/presets/detectors.json index 60764f0..565c61b 100644 --- a/src/presets/detectors.json +++ b/src/presets/detectors.json @@ -26,4 +26,4 @@ }, "pixelSize": 0.2 } -} \ No newline at end of file +} diff --git a/src/results/resultsStore.ts b/src/results/resultsStore.ts index 2126c71..ebdd356 100644 --- a/src/results/resultsStore.ts +++ b/src/results/resultsStore.ts @@ -3,25 +3,20 @@ import QSpace from "../calculations/qspace"; import NumericRange from "../calculations/numericRange"; interface ScatteringQuantity { - name: string, - minValue: number, - maxValue: number, - RequestedMin: number, - RequestedMax: number, + name: string; + minValue: number; + maxValue: number; + RequestedMin: number; + RequestedMax: number; } export interface ResultStore { - selected: string, - q: ScatteringQuantity, - qUnits: WavelengthUnits, - qspace: QSpace - twoTheta: ScatteringQuantity - thetaUnits: AngleUnits - visableQRange: NumericRange - fullQRange: NumericRange + selected: string; + q: ScatteringQuantity; + qUnits: WavelengthUnits; + qspace: QSpace; + twoTheta: ScatteringQuantity; + thetaUnits: AngleUnits; + visableQRange: NumericRange; + fullQRange: NumericRange; } - - - - - diff --git a/src/utils/units.ts b/src/utils/units.ts index 4554a1b..83f35f5 100644 --- a/src/utils/units.ts +++ b/src/utils/units.ts @@ -35,9 +35,9 @@ export const PLANCK = 6.62607015e-34; // unit converters to keep logic in one place export const energy2WavelengthConverter = (energy: number): number => { - return PLANCK * energy -} + return (PLANCK *CSPEED)/energy; +}; export const wavelength2EnergyConverter = (wavelength: number): number => { - return PLANCK / wavelength -} \ No newline at end of file + return (PLANCK *CSPEED)/ wavelength; +};