diff --git a/src/basicAppBar.tsx b/src/basicAppBar.tsx index 1d1dce4..780b0d2 100644 --- a/src/basicAppBar.tsx +++ b/src/basicAppBar.tsx @@ -19,7 +19,8 @@ export default function BasicAppBar(): JSX.Element { setState({ menuOpen: open }); }; - const preset = useBeamlineConfigStore((state) => state.preset); + const beamlineConfig = useBeamlineConfigStore(); + const updateBeamstop = useBeamstopStore((state) => state.updateBeamstop); const updateCameraTube = useCameraTubeStore( (state) => state.updateCameraTube, @@ -73,7 +74,7 @@ export default function BasicAppBar(): JSX.Element { disablePortal id="combo-box-demo" options={Object.keys(presetList)} - value={preset} + value={beamlineConfig.preset} sx={{ width: 300, color: "white" }} renderInput={(params) => ( void; updateEnergy: (newEnergy: number | null, newUnits: EnergyUnits) => void; updateEnergyUnits: (newUnits: EnergyUnits) => void; - update: (newConfig: Partial) => void; + update: (newConfig: Partial) => void; } export const useBeamlineConfigStore = create((set) => ({ @@ -69,5 +69,5 @@ export const useBeamlineConfigStore = create((set) => ({ energy: state.energy.to(newUnits), userEnergy: state.energy.to(newUnits).toNumber(), })), - update: (newConfig: Partial) => set({ ...newConfig }), + update: (newConfig: Partial) => set({ ...newConfig }), })); diff --git a/src/plot/plotUtils.ts b/src/plot/plotUtils.ts index d5c515a..b8c373a 100644 --- a/src/plot/plotUtils.ts +++ b/src/plot/plotUtils.ts @@ -23,9 +23,14 @@ export const getDomains = ( ? detector.upperBound.x : detector.upperBound.y; + const minAxis = + detector.lowerBound.x > detector.lowerBound.y + ? detector.lowerBound.x + : detector.lowerBound.y; + return { - xAxis: new NumericRange(Math.round(-offset), Math.round(maxAxis + offset)), - yAxis: new NumericRange(Math.round(-offset), Math.round(maxAxis + offset)), + xAxis: new NumericRange(Math.round(minAxis - offset), Math.round(maxAxis + offset)), + yAxis: new NumericRange(Math.round(minAxis - offset), Math.round(maxAxis + offset)), }; }; @@ -110,19 +115,19 @@ export class Plotter { centre: newcentreVec, endPointX: new Vector3( newcentreVec.x + - mathjs - .multiply(mathjs.divide(diameter, 2), this.scaleFactor) - .to(this.xunit) - .toNumber(), + mathjs + .multiply(mathjs.divide(diameter, 2), this.scaleFactor) + .to(this.xunit) + .toNumber(), newcentreVec.y, ), endPointY: new Vector3( newcentreVec.x, newcentreVec.y + - mathjs - .multiply(mathjs.divide(diameter, 2), this.scaleFactor) - .to(this.yunit) - .toNumber(), + mathjs + .multiply(mathjs.divide(diameter, 2), this.scaleFactor) + .to(this.yunit) + .toNumber(), ), }; } @@ -142,15 +147,15 @@ export class Plotter { centre: centreVec, endPointX: new Vector3( centreVec.x + - mathjs.divide(diameter, 2).to(this.xunit).toNumber() + - mathjs.unit(clearance, "xpixel").to(this.xunit).toNumber(), + mathjs.divide(diameter, 2).to(this.xunit).toNumber() + + mathjs.unit(clearance, "xpixel").to(this.xunit).toNumber(), centreVec.y, ), endPointY: new Vector3( centreVec.x, centreVec.y + - mathjs.divide(diameter, 2).to(this.yunit).toNumber() + - mathjs.unit(clearance, "ypixel").to(this.yunit).toNumber(), + mathjs.divide(diameter, 2).to(this.yunit).toNumber() + + mathjs.unit(clearance, "ypixel").to(this.yunit).toNumber(), ), }; } @@ -172,27 +177,27 @@ export class Plotter { centre: newcentreVec, endPointX: new Vector3( newcentreVec.x + - mathjs - .multiply(mathjs.divide(diameter, 2), this.scaleFactor) - .to(this.xunit) - .toNumber() + - mathjs - .multiply(mathjs.unit(clearance, "xpixel"), this.scaleFactor) - .to(this.xunit) - .toNumber(), + mathjs + .multiply(mathjs.divide(diameter, 2), this.scaleFactor) + .to(this.xunit) + .toNumber() + + mathjs + .multiply(mathjs.unit(clearance, "xpixel"), this.scaleFactor) + .to(this.xunit) + .toNumber(), newcentreVec.y, ), endPointY: new Vector3( newcentreVec.x, newcentreVec.y + - mathjs - .multiply(mathjs.divide(diameter, 2), this.scaleFactor) - .to(this.yunit) - .toNumber() + - mathjs - .multiply(mathjs.unit(clearance, "ypixel"), this.scaleFactor) - .to(this.yunit) - .toNumber(), + mathjs + .multiply(mathjs.divide(diameter, 2), this.scaleFactor) + .to(this.yunit) + .toNumber() + + mathjs + .multiply(mathjs.unit(clearance, "ypixel"), this.scaleFactor) + .to(this.yunit) + .toNumber(), ), }; }; @@ -228,18 +233,18 @@ export class Plotter { ), upperBound: new Vector3( lowerBound.x.to(this.xunit).toNumber() + - mathjs - .multiply(mathjs.unit(resolution.width, "xpixel"), this.scaleFactor) - .to(this.xunit) - .toNumber(), + mathjs + .multiply(mathjs.unit(resolution.width, "xpixel"), this.scaleFactor) + .to(this.xunit) + .toNumber(), lowerBound.y.to(this.yunit).toNumber() + - mathjs - .multiply( - mathjs.unit(resolution.height, "ypixel"), - this.scaleFactor, - ) - .to(this.yunit) - .toNumber(), + mathjs + .multiply( + mathjs.unit(resolution.height, "ypixel"), + this.scaleFactor, + ) + .to(this.yunit) + .toNumber(), ), }; } diff --git a/src/utils/units.ts b/src/utils/units.ts index a17ffb9..07df33c 100644 --- a/src/utils/units.ts +++ b/src/utils/units.ts @@ -1,7 +1,7 @@ -import * as math from "mathjs"; +import * as mathjs from "mathjs"; -export const CSPEED = math.unit(299792458, "m/s"); -export const PLANCK = math.unit(6.62607015e-34, "J s"); +export const CSPEED = mathjs.unit(299792458, "m/s"); +export const PLANCK = mathjs.unit(6.62607015e-34, "J s"); export enum DistanceUnits { millimetre = "mm", @@ -46,7 +46,7 @@ export interface UnitConfig { * @returns - wavelength in nm */ export const energy2WavelengthConverter = (energy: math.Unit): math.Unit => { - const result = math.divide(math.multiply(PLANCK, CSPEED), energy.toSI()); + const result = mathjs.divide(mathjs.multiply(PLANCK, CSPEED), energy.toSI()); if (typeof result == "number" || !("units" in result)) { throw TypeError("units for constants h and c are wrong"); @@ -62,7 +62,7 @@ export const energy2WavelengthConverter = (energy: math.Unit): math.Unit => { export const wavelength2EnergyConverter = ( wavelength: math.Unit, ): math.Unit => { - const result = math.divide(math.multiply(PLANCK, CSPEED), wavelength.toSI()); + const result = mathjs.divide(mathjs.multiply(PLANCK, CSPEED), wavelength.toSI()); if (typeof result == "number" || !("units" in result)) { throw TypeError("units for constants h and c are wrong"); } @@ -95,9 +95,7 @@ export const enforceRangeLimits = ( max: number, value: number, ): number => { - if (value > max) { - return max; - } + if (value > max) return max; if (value < min) return min; return value; };