From a11fe519cc8c28993859053deef67a2c1656e255 Mon Sep 17 00:00:00 2001 From: tizayi Date: Mon, 20 Nov 2023 15:15:24 +0000 Subject: [PATCH] beamstop color option --- .github/dependabot.yml | 2 +- src/calculations/numericRange.ts | 4 +- src/calculations/qrange.ts | 2 +- src/calculations/ray.ts | 27 ++++---- src/data-entry/beamProperties.tsx | 92 +++++++++++---------------- src/data-entry/beamlineconfigStore.ts | 1 + src/plot/centrePlot.tsx | 80 ++++++++++++++--------- src/plot/legendBar.tsx | 44 ++++++++----- src/plot/plotStore.ts | 6 +- src/plot/plotUtils.ts | 12 ++-- src/presets/presetConfigs.json | 6 +- src/results/rangeDiagram.tsx | 8 +-- src/results/resultsBar.tsx | 13 ++-- src/sideMenu.tsx | 1 - src/typings/index.d.ts | 7 -- src/utils/colourPicker.tsx | 77 ++++++++++++---------- src/utils/types.ts | 1 + src/utils/units.ts | 4 +- 18 files changed, 206 insertions(+), 181 deletions(-) delete mode 100644 src/typings/index.d.ts diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 66b3a48..edd4766 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,4 +7,4 @@ updates: - package-ecosystem: "npm" directory: "/" schedule: - interval: "daily" \ No newline at end of file + interval: "daily" diff --git a/src/calculations/numericRange.ts b/src/calculations/numericRange.ts index 0578272..099e2a8 100644 --- a/src/calculations/numericRange.ts +++ b/src/calculations/numericRange.ts @@ -78,8 +78,8 @@ export default class NumericRange { /** * Applys a function to the range in place - * @param func - * @returns + * @param func + * @returns */ inPlaceApply(func: (value: number) => number): NumericRange { this.min = func(this.min); diff --git a/src/calculations/qrange.ts b/src/calculations/qrange.ts index 0cb1332..7d3c01b 100644 --- a/src/calculations/qrange.ts +++ b/src/calculations/qrange.ts @@ -10,7 +10,7 @@ import { Ray } from "../calculations/ray"; import NumericRange from "./numericRange"; /** - * Compute the viable and full qranges + * Compute the viable and full qranges * @param detector Detector object with data on how the detector e * @param beamstop * @param cameraTube diff --git a/src/calculations/ray.ts b/src/calculations/ray.ts index b348de2..749b598 100644 --- a/src/calculations/ray.ts +++ b/src/calculations/ray.ts @@ -32,20 +32,23 @@ export class Ray { } /** - * Find where the ray insects with a circle. - */ - public getCircleIntersectionParameterRange(radius: number, centre: Vector2): NumericRange | null { + * Find where the ray insects with a circle. + */ + public getCircleIntersectionParameterRange( + radius: number, + centre: Vector2, + ): NumericRange | null { const diff = this.initial_point.clone().add(centre.multiplyScalar(-1)); const a = this.direction.dot(this.direction); - const b = 2*diff.dot(this.direction); - const c = (diff.dot(diff) - Math.pow(radius,2)); + const b = 2 * diff.dot(this.direction); + const c = diff.dot(diff) - Math.pow(radius, 2); const discriminant = Math.pow(b, 2) - 4 * a * c; - + if (discriminant < 0) return null; let t1: number; let t2: number; - + if (a == 0) { if (b == 0) return c == 0 ? new NumericRange(0, Number.POSITIVE_INFINITY) : null; @@ -84,7 +87,7 @@ export class Ray { return null; return this.getParameterRange(result.min, result.max); } - + result = result.intersect( new NumericRange( (ymin - this.initial_point.y) / this.direction.y, @@ -92,12 +95,10 @@ export class Ray { ), ); - if(result ==null){ + if (result == null) { return null; - } - + } + return this.getParameterRange(result.min, result.max); } } - - diff --git a/src/data-entry/beamProperties.tsx b/src/data-entry/beamProperties.tsx index 9b46dd1..b36b2db 100644 --- a/src/data-entry/beamProperties.tsx +++ b/src/data-entry/beamProperties.tsx @@ -24,6 +24,8 @@ import { useBeamlineConfigStore } from "./beamlineconfigStore"; import { MathUtils } from "three/src/Three.js"; export default function BeampropertiesDataEntry() { + const beamlineConfig = useBeamlineConfigStore(); + const minWavelength = useBeamlineConfigStore((state) => { if (state.wavelengthUnits === WavelengthUnits.angstroms) { return nanometres2Angstroms(state.minWavelength); @@ -38,60 +40,39 @@ export default function BeampropertiesDataEntry() { return state.maxWavelength; }); - const cameraLength = useBeamlineConfigStore((state) => state.cameraLength); - const minCameraLength = useBeamlineConfigStore( - (state) => state.minCameraLength, - ); - const maxCameraLength = useBeamlineConfigStore( - (state) => state.maxCameraLength, - ); - - const energy = useBeamlineConfigStore((state) => state.energy); - const energyUnits = useBeamlineConfigStore((state) => state.beamEnergyUnits); - - const updateConfig = useBeamlineConfigStore((state) => state.update); - - const angle = useBeamlineConfigStore((state) => state.angle); - const angleUnits = useBeamlineConfigStore((state) => state.angleUnits); - const handleAngleUnits = (event: SelectChangeEvent) => { const newUnits = event.target.value as AngleUnits; - let newAngle = angle; + let newAngle = beamlineConfig.angle; if ( newAngle !== null && newUnits === AngleUnits.degrees && - angleUnits === AngleUnits.radians + beamlineConfig.angleUnits === AngleUnits.radians ) { newAngle = MathUtils.radToDeg(newAngle); } else if ( newAngle !== null && newUnits === AngleUnits.radians && - angleUnits === AngleUnits.degrees + beamlineConfig.angleUnits === AngleUnits.degrees ) { newAngle = MathUtils.degToRad(newAngle); } - updateConfig({ + beamlineConfig.update({ angle: newAngle, angleUnits: newUnits, }); }; const handleAngle = (event: React.ChangeEvent) => { - updateConfig({ angle: parseNumericInput(event.target.value) }); + beamlineConfig.update({ angle: parseNumericInput(event.target.value) }); }; - const wavelength = useBeamlineConfigStore((state) => state.wavelength); - const wavelengthUnits = useBeamlineConfigStore( - (state) => state.wavelengthUnits, - ); - const handleWavelength = (event: React.ChangeEvent) => { const newWavelength = parseNumericInput(event.target.value); let newEnergy: number | null = null; if (newWavelength === null) { - updateConfig({ + beamlineConfig.update({ energy: newEnergy, wavelength: newWavelength, }); @@ -99,7 +80,7 @@ export default function BeampropertiesDataEntry() { } // account for wavelength units - if (wavelengthUnits === WavelengthUnits.angstroms) { + if (beamlineConfig.wavelengthUnits === WavelengthUnits.angstroms) { newEnergy = wavelength2EnergyConverter( angstroms2Nanometres(newWavelength), ); @@ -108,11 +89,11 @@ export default function BeampropertiesDataEntry() { } // account for energy units - if (energyUnits === EnergyUnits.electronVolts) { + if (beamlineConfig.beamEnergyUnits === EnergyUnits.electronVolts) { newEnergy = electronVots2KiloElectronVolts(newEnergy); } - updateConfig({ + beamlineConfig.update({ energy: newEnergy, wavelength: newWavelength, }); @@ -120,21 +101,21 @@ export default function BeampropertiesDataEntry() { const handleWavelengthUnits = (event: SelectChangeEvent) => { const newUnits = event.target.value as WavelengthUnits; - let newWavelength = wavelength; + let newWavelength = beamlineConfig.wavelength; if ( newWavelength !== null && newUnits === WavelengthUnits.angstroms && - wavelengthUnits === WavelengthUnits.nanmometres + beamlineConfig.wavelengthUnits === WavelengthUnits.nanmometres ) { newWavelength = nanometres2Angstroms(newWavelength); } else if ( newWavelength !== null && newUnits === WavelengthUnits.nanmometres && - wavelengthUnits === WavelengthUnits.angstroms + beamlineConfig.wavelengthUnits === WavelengthUnits.angstroms ) { newWavelength = angstroms2Nanometres(newWavelength); } - updateConfig({ + beamlineConfig.update({ wavelength: newWavelength, wavelengthUnits: newUnits, }); @@ -145,14 +126,14 @@ export default function BeampropertiesDataEntry() { let newWavelength: number | null = null; if (newEnergy === null) { - updateConfig({ + beamlineConfig.update({ energy: newEnergy, wavelength: newWavelength, }); return; } - if (energyUnits === EnergyUnits.electronVolts) { + if (beamlineConfig.beamEnergyUnits === EnergyUnits.electronVolts) { newWavelength = energy2WavelengthConverter( electronVots2KiloElectronVolts(newEnergy), ); @@ -160,11 +141,11 @@ export default function BeampropertiesDataEntry() { newWavelength = energy2WavelengthConverter(newEnergy); } - if (wavelengthUnits === WavelengthUnits.angstroms) { + if (beamlineConfig.wavelengthUnits === WavelengthUnits.angstroms) { newWavelength = angstroms2Nanometres(newWavelength); } - updateConfig({ + beamlineConfig.update({ energy: newEnergy, wavelength: newWavelength, }); @@ -172,28 +153,28 @@ export default function BeampropertiesDataEntry() { const handleEnergyUnits = (event: SelectChangeEvent) => { const newUnits = event.target.value as EnergyUnits; - let newEnergy = energy; + let newEnergy = beamlineConfig.energy; if ( newEnergy !== null && newUnits === EnergyUnits.electronVolts && - energyUnits === EnergyUnits.kiloElectronVolts + beamlineConfig.beamEnergyUnits === EnergyUnits.kiloElectronVolts ) { newEnergy = kiloElectronVolts2ElectronVots(newEnergy); } else if ( newEnergy != null && newUnits === EnergyUnits.kiloElectronVolts && - energyUnits === EnergyUnits.electronVolts + beamlineConfig.beamEnergyUnits === EnergyUnits.electronVolts ) { newEnergy = electronVots2KiloElectronVolts(newEnergy); } - updateConfig({ + beamlineConfig.update({ energy: newEnergy, beamEnergyUnits: event.target.value as EnergyUnits, }); }; const handleCameraLength = (event: React.ChangeEvent) => { - updateConfig({ + beamlineConfig.update({ cameraLength: parseNumericInput(event.target.value), }); }; @@ -206,7 +187,7 @@ export default function BeampropertiesDataEntry() { @@ -214,7 +195,7 @@ export default function BeampropertiesDataEntry() { @@ -252,21 +233,24 @@ export default function BeampropertiesDataEntry() { - Minimum allowed wavelength: {minWavelength} {wavelengthUnits}{" "} + Minimum allowed wavelength: {minWavelength}{" "} + {beamlineConfig.wavelengthUnits}{" "} - Maximum allowed wavelength: {maxWavelength} {wavelengthUnits} + Maximum allowed wavelength: {maxWavelength}{" "} + {beamlineConfig.wavelengthUnits} Camera Length: @@ -287,7 +271,7 @@ export default function BeampropertiesDataEntry() {