diff --git a/src/calculations/numericRange.ts b/src/calculations/numericRange.ts index a411c42..0bfcc2b 100644 --- a/src/calculations/numericRange.ts +++ b/src/calculations/numericRange.ts @@ -21,7 +21,6 @@ export default class NumericRange { return other.min >= this.min && other.max <= this.max; } - toString(): string { return `(min:${this.min}, max:${this.max})`; } @@ -38,17 +37,14 @@ export default class NumericRange { ); } - equals(other: NumericRange): boolean { return this.min === other.min && this.max === other.max; } - apply(func: (value: number) => number): NumericRange { return new NumericRange(func(this.min), func(this.max)); } - inPlaceApply(func: (value: number) => number): NumericRange { this.min = func(this.min); this.max = func(this.max); diff --git a/src/calculations/qvalue.ts b/src/calculations/qvalue.ts index 2a59726..a9fde63 100644 --- a/src/calculations/qvalue.ts +++ b/src/calculations/qvalue.ts @@ -43,11 +43,21 @@ export const getPointForQ = ( beamstopCentre: UnitVector, ): UnitVector => { const ray = new Ray( - new Vector2(Math.cos(angle.toSI().toNumber()), Math.sin(angle.toSI().toNumber())), - new Vector2(beamstopCentre.x.toSI().toNumber(), beamstopCentre.y.toSI().toNumber()), + new Vector2( + Math.cos(angle.toSI().toNumber()), + Math.sin(angle.toSI().toNumber()), + ), + new Vector2( + beamstopCentre.x.toSI().toNumber(), + beamstopCentre.y.toSI().toNumber(), + ), ); const result = ray.getPointAtDistance( - (calculateDistanceFromQValue(qValue.toSI().toNumber(), cameralength.toSI().toNumber(), wavelength.toSI().toNumber())) ?? 0, + calculateDistanceFromQValue( + qValue.toSI().toNumber(), + cameralength.toSI().toNumber(), + wavelength.toSI().toNumber(), + ) ?? 0, ); - return { x: mathjs.unit(result.x, "m"), y: mathjs.unit(result.y, "m") } + return { x: mathjs.unit(result.x, "m"), y: mathjs.unit(result.y, "m") }; }; diff --git a/src/calculations/unitRange.ts b/src/calculations/unitRange.ts index fca123c..00263f8 100644 --- a/src/calculations/unitRange.ts +++ b/src/calculations/unitRange.ts @@ -2,67 +2,75 @@ import * as mathjs from "mathjs"; import NumericRange from "./numericRange"; export default class UnitRange { - min: mathjs.Unit; - max: mathjs.Unit; + min: mathjs.Unit; + max: mathjs.Unit; - constructor(min: mathjs.Unit, max: mathjs.Unit) { - this.min = min; - this.max = max; + constructor(min: mathjs.Unit, max: mathjs.Unit) { + this.min = min; + this.max = max; - if (mathjs.larger(min, max)) { - const temp = max.clone(); - this.max = min; - this.min = temp; - } + if (mathjs.larger(min, max)) { + const temp = max.clone(); + this.max = min; + this.min = temp; } + } - to(units: string): UnitRange { - return new UnitRange(this.min.to(units), this.max.to(units)) - } + to(units: string): UnitRange { + return new UnitRange(this.min.to(units), this.max.to(units)); + } - containsValue(value: mathjs.Unit): boolean { - return mathjs.largerEq(value, this.min) && mathjs.largerEq(value, this.max); - } + containsValue(value: mathjs.Unit): boolean { + return mathjs.largerEq(value, this.min) && mathjs.largerEq(value, this.max); + } - containsRange(other: UnitRange): boolean { - console.log(`${other.min.formatUnits()} ${this.min.formatUnits()}`) - console.log(`${other.min.formatUnits()} ${this.min.formatUnits()}`) - return mathjs.smallerEq(this.min, other.min) && mathjs.largerEq(this.max, other.max,); - } + containsRange(other: UnitRange): boolean { + return ( + mathjs.smallerEq(this.min, other.min) && + mathjs.largerEq(this.max, other.max) + ); + } - toString(): string { - return `(min:${this.min.toString()}, max:${this.max.toString()})`; - } + toString(): string { + return `(min:${this.min.toString()}, max:${this.max.toString()})`; + } + intersect(other: UnitRange): UnitRange | null { + if ( + mathjs.larger(other.min, this.max) || + mathjs.larger(this.min, other.max) + ) + return null; - intersect(other: UnitRange): UnitRange | null { - if (mathjs.larger(other.min, this.max) || mathjs.larger(this.min, other.max)) return null; + return new UnitRange( + mathjs.max(other.min, this.min), + mathjs.min(other.max, this.max), + ); + } - return new UnitRange( - mathjs.max(other.min, this.min), - mathjs.min(other.max, this.max), - ); - } + equals(other: UnitRange): boolean { + return ( + mathjs.equal(this.min, other.min) && mathjs.equal(this.max, other.max) + ); + } - equals(other: UnitRange): boolean { - return mathjs.equal(this.min, other.min) && mathjs.equal(this.max, other.max); - } + apply(func: (value: mathjs.Unit) => mathjs.Unit): UnitRange { + return new UnitRange(func(this.min), func(this.max)); + } + inPlaceApply(func: (value: mathjs.Unit) => mathjs.Unit): UnitRange { + this.min = func(this.min); + this.max = func(this.max); + return this; + } - apply(func: (value: mathjs.Unit) => mathjs.Unit): UnitRange { - return new UnitRange(func(this.min), func(this.max)); - } - - inPlaceApply(func: (value: mathjs.Unit) => mathjs.Unit): UnitRange { - this.min = func(this.min); - this.max = func(this.max); - return this; - } - - static fromNumericRange(range: NumericRange | null, units: string): UnitRange { - return new UnitRange( - mathjs.unit(range?.min ?? NaN, units), - mathjs.unit(range?.max ?? NaN, units), - ) - } + static fromNumericRange( + range: NumericRange | null, + units: string, + ): UnitRange { + return new UnitRange( + mathjs.unit(range?.min ?? NaN, units), + mathjs.unit(range?.max ?? NaN, units), + ); + } } diff --git a/src/plot/centrePlot.tsx b/src/plot/centrePlot.tsx index a84ee33..453611c 100644 --- a/src/plot/centrePlot.tsx +++ b/src/plot/centrePlot.tsx @@ -12,11 +12,7 @@ import { Vector3 } from "three"; import { useBeamstopStore } from "../data-entry/beamstopStore"; import { useDetectorStore } from "../data-entry/detectorStore"; import { useCameraTubeStore } from "../data-entry/cameraTubeStore"; -import { - UnitVector, - Plotter, - getDomains, -} from "./plotUtils"; +import { UnitVector, Plotter, getDomains } from "./plotUtils"; import { usePlotStore } from "./plotStore"; import { BeamlineConfig, @@ -71,32 +67,32 @@ export default function CentrePlot(): JSX.Element { return { centre: state.centre, diameter: state.diameter }; }); - - const scaleFactor: mathjs.Unit | null = null; - if ( - beamlineConfig.cameraLength && - beamlineConfig.wavelength - ) { - // const scaleFactor = mathjs.divide(2e-12 * Math.PI, mathjs.multiply(mathjs.unit(beamlineConfig.cameraLength, "m"), beamlineConfig.wavelength)); + let scaleFactor: mathjs.Unit | null = null; + if (beamlineConfig.cameraLength && beamlineConfig.wavelength) { + scaleFactor = mathjs.divide( + 2 * Math.PI, + mathjs.multiply( + mathjs.unit(beamlineConfig.cameraLength, "m"), + beamlineConfig.wavelength.to("m"), + ), + ); } // evil :( :( :( :() /* eslint-disable */ if (mathjs.Unit.UNITS.xpixel) { - delete mathjs.Unit.UNITS.xpixel + delete mathjs.Unit.UNITS.xpixel; } if (mathjs.Unit.UNITS.ypixel) { - delete mathjs.Unit.UNITS.ypixel + delete mathjs.Unit.UNITS.ypixel; } /* eslint-enable */ // evil :( :( :( :() - mathjs.createUnit("xpixel", detector.pixelSize.width.toString()); mathjs.createUnit("ypixel", detector.pixelSize.height.toString()); - const { ptMin, ptMax, visibleQRange, fullQRange } = computeQrange( detector, beamstop, @@ -105,54 +101,64 @@ export default function CentrePlot(): JSX.Element { ); // I am about here - const visibleQRangeUnits = UnitRange.fromNumericRange(visibleQRange, "m^-1").to("nm^-1"); - const fullQRangeUnits = UnitRange.fromNumericRange(fullQRange, "m^-1").to("nm^-1") + const visibleQRangeUnits = UnitRange.fromNumericRange( + visibleQRange, + "m^-1", + ).to("nm^-1"); + const fullQRangeUnits = UnitRange.fromNumericRange(fullQRange, "m^-1").to( + "nm^-1", + ); const minPoint: UnitVector = { x: mathjs.unit(ptMin.x, "m"), - y: mathjs.unit(ptMin.y, "m") - } + y: mathjs.unit(ptMin.y, "m"), + }; const maxPoint: UnitVector = { x: mathjs.unit(ptMax.x, "m"), - y: mathjs.unit(ptMax.y, "m") - } + y: mathjs.unit(ptMax.y, "m"), + }; const beamstopCentre: UnitVector = { x: mathjs.unit(beamstop.centre.x ?? NaN, "xpixel"), - y: mathjs.unit(beamstop.centre.y ?? NaN, "ypixel") - } + y: mathjs.unit(beamstop.centre.y ?? NaN, "ypixel"), + }; const cameraTubeCentre: UnitVector = { x: mathjs.unit(cameraTube.centre.x ?? NaN, "xpixel"), - y: mathjs.unit(cameraTube.centre.y ?? NaN, "ypixel") - } + y: mathjs.unit(cameraTube.centre.y ?? NaN, "ypixel"), + }; - const plotter = new Plotter(plotConfig.plotAxes, scaleFactor) + const plotter = new Plotter(plotConfig.plotAxes, scaleFactor); const plotBeamstop = plotter.createPlotEllipse( beamstopCentre, - beamstop.diameter + beamstop.diameter, + beamstopCentre, ); const plotCameraTube = plotter.createPlotEllipse( cameraTubeCentre, - cameraTube.diameter + cameraTube.diameter, + beamstopCentre, ); const plotClearance = plotter.createPlotEllipseClearance( beamstopCentre, beamstop.diameter, - beamstop.clearance ?? 0 + beamstop.clearance ?? 0, + beamstopCentre, ); const plotDetector = plotter.createPlotRectangle( detector.resolution, + beamstopCentre, ); const plotVisibleRange = plotter.createPlotRange( minPoint, maxPoint, + beamstopCentre, ); // I am up to here @@ -175,15 +181,14 @@ export default function CentrePlot(): JSX.Element { result = mathjs.unit(value, state.qUnits); } return result; - } + }; return new UnitRange( getUnit(state.requestedMin), - getUnit(state.requestedMax) - ) + getUnit(state.requestedMax), + ); }); - let plotRequestedRange = { start: new Vector3(0, 0), end: new Vector3(0, 0), @@ -209,11 +214,12 @@ export default function CentrePlot(): JSX.Element { ); plotRequestedRange = plotter.createPlotRange( requestedMinPt, - requestedMaxPt + requestedMaxPt, + beamstopCentre, ); } - + console.log(plotDetector); const domains = getDomains(plotDetector, plotConfig.plotAxes); @@ -359,7 +365,10 @@ export default function CentrePlot(): JSX.Element { - + ); diff --git a/src/plot/plotStore.ts b/src/plot/plotStore.ts index 2fa1213..aacc91f 100644 --- a/src/plot/plotStore.ts +++ b/src/plot/plotStore.ts @@ -4,7 +4,7 @@ import { create } from "zustand"; export enum PlotAxes { milimeter = "mm", pixel = "pixel", - reciprocal = "mm^-1", + reciprocal = "nm^-1", } export interface PlotConfig { diff --git a/src/plot/plotUtils.ts b/src/plot/plotUtils.ts index 4d6ff4a..d5c515a 100644 --- a/src/plot/plotUtils.ts +++ b/src/plot/plotUtils.ts @@ -4,9 +4,6 @@ import { PlotAxes } from "./plotStore"; import { Vector3 } from "three"; import * as mathjs from "mathjs"; - - - // Questionable is this how you would do this think about it a little more export const getDomains = ( detector: PlotRectangle, @@ -17,6 +14,10 @@ export const getDomains = ( offset = 100; } + if (axes === PlotAxes.reciprocal) { + offset = 10; + } + const maxAxis = detector.upperBound.x > detector.upperBound.y ? detector.upperBound.x @@ -39,18 +40,15 @@ export interface PlotEllipse { } export interface UnitVector { - x: math.Unit, - y: math.Unit + x: math.Unit; + y: math.Unit; } - export interface PlotRectangle { upperBound: Vector3; lowerBound: Vector3; } - - export interface PlotRange { start: Vector3; end: Vector3; @@ -75,21 +73,56 @@ export class Plotter { createPlotEllipse( centre: UnitVector, diameter: math.Unit, + beamstopCentre: UnitVector, ): PlotEllipse { - const centreVec = new Vector3( - centre.x.to(this.xunit).toNumber(), - centre.y.to(this.yunit).toNumber(), - ); + if (this.plotAxes !== PlotAxes.reciprocal) { + const centreVec = new Vector3( + centre.x.to(this.xunit).toNumber(), + centre.y.to(this.yunit).toNumber(), + ); + return { + centre: centreVec, + endPointX: new Vector3( + centreVec.x + mathjs.divide(diameter, 2).to(this.xunit).toNumber(), + centreVec.y, + ), + endPointY: new Vector3( + centreVec.x, + centreVec.y + mathjs.divide(diameter, 2).to(this.yunit).toNumber(), + ), + }; + } + + if (!this.scaleFactor) { + throw TypeError("reciprocal units need a scaleFactor"); + } + const newcentre = Plotter.convert2QSpace( + centre, + this.scaleFactor, + beamstopCentre, + ); + const newcentreVec = new Vector3( + newcentre.x.to(this.xunit).toNumber(), + newcentre.y.to(this.yunit).toNumber(), + ); return { - centre: centreVec, + centre: newcentreVec, endPointX: new Vector3( - centreVec.x + mathjs.divide(diameter, 2).to(this.xunit).toNumber(), - centreVec.y, + newcentreVec.x + + mathjs + .multiply(mathjs.divide(diameter, 2), this.scaleFactor) + .to(this.xunit) + .toNumber(), + newcentreVec.y, ), endPointY: new Vector3( - centreVec.x, - centreVec.y + mathjs.divide(diameter, 2).to(this.yunit).toNumber(), + newcentreVec.x, + newcentreVec.y + + mathjs + .multiply(mathjs.divide(diameter, 2), this.scaleFactor) + .to(this.yunit) + .toNumber(), ), }; } @@ -98,43 +131,166 @@ export class Plotter { centre: UnitVector, diameter: math.Unit, clearance: number, + beamstopCentre: UnitVector, ): PlotEllipse => { + if (this.plotAxes !== PlotAxes.reciprocal) { + const centreVec = new Vector3( + centre.x.to(this.xunit).toNumber(), + centre.y.to(this.yunit).toNumber(), + ); + return { + centre: centreVec, + endPointX: new Vector3( + centreVec.x + + 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(), + ), + }; + } - const centreVec = new Vector3( - centre.x.to(this.xunit).toNumber(), - centre.y.to(this.yunit).toNumber(), - ); + if (!this.scaleFactor) { + throw TypeError("reciprocal units need a scaleFactor"); + } + const newcentre = Plotter.convert2QSpace( + centre, + this.scaleFactor, + beamstopCentre, + ); + const newcentreVec = new Vector3( + newcentre.x.to(this.xunit).toNumber(), + newcentre.y.to(this.yunit).toNumber(), + ); return { - centre: centreVec, + centre: newcentreVec, endPointX: new Vector3( - centreVec.x + mathjs.divide(diameter, 2).to(this.xunit).toNumber() + mathjs.unit(clearance, "xpixel").to(this.xunit).toNumber(), - centreVec.y, + 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(), + newcentreVec.y, ), endPointY: new Vector3( - centreVec.x, - centreVec.y + mathjs.divide(diameter, 2).to(this.yunit).toNumber() + mathjs.unit(clearance, "ypixel").to(this.yunit).toNumber(), + 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(), ), }; }; createPlotRectangle( resolution: { height: number; width: number }, + beamstopCentre: UnitVector, ): PlotRectangle { + if (this.plotAxes !== PlotAxes.reciprocal) { + return { + lowerBound: new Vector3(0, 0), + upperBound: new Vector3( + mathjs.unit(resolution.width, "xpixel").to(this.xunit).toNumber(), + mathjs.unit(resolution.height, "ypixel").to(this.yunit).toNumber(), + ), + }; + } + + if (!this.scaleFactor) { + throw TypeError("reciprocal units need a scaleFactor"); + } + + const lowerBound = Plotter.convert2QSpace( + { x: mathjs.unit(0, "xpixel"), y: mathjs.unit(0, "ypixel") }, + this.scaleFactor, + beamstopCentre, + ); + return { - lowerBound: new Vector3(0, 0), - upperBound: new Vector3(mathjs.unit(resolution.width, "xpixel").to(this.xunit).toNumber(), mathjs.unit(resolution.height, "ypixel").to(this.yunit).toNumber()), + lowerBound: new Vector3( + lowerBound.x.to(this.xunit).toNumber(), + lowerBound.y.to(this.yunit).toNumber(), + ), + upperBound: new Vector3( + lowerBound.x.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(), + ), }; } createPlotRange = ( startPoint: UnitVector, endPoint: UnitVector, + beamstopCentre: UnitVector, ): PlotRange => { + if (this.plotAxes === PlotAxes.reciprocal) { + if (!this.scaleFactor) { + throw TypeError("reciprocal units need a scaleFactor"); + } + startPoint = Plotter.convert2QSpace( + startPoint, + this.scaleFactor, + beamstopCentre, + ); + endPoint = Plotter.convert2QSpace( + endPoint, + this.scaleFactor, + beamstopCentre, + ); + } + return { - start: new Vector3(startPoint.x.to(this.xunit).toNumber(), startPoint.y.to(this.yunit).toNumber()), - end: new Vector3(endPoint.x.to(this.xunit).toNumber(), endPoint.y.to(this.yunit).toNumber()), + start: new Vector3( + startPoint.x.to(this.xunit).toNumber(), + startPoint.y.to(this.yunit).toNumber(), + ), + end: new Vector3( + endPoint.x.to(this.xunit).toNumber(), + endPoint.y.to(this.yunit).toNumber(), + ), }; }; -} + static convert2QSpace = ( + value: UnitVector, + scaleFactor: mathjs.Unit, + beamstopCentre: UnitVector, + ): UnitVector => { + return { + x: mathjs.multiply( + scaleFactor, + mathjs.subtract(value.x, beamstopCentre.x), + ), + y: mathjs.multiply( + scaleFactor, + mathjs.subtract(value.y, beamstopCentre.y), + ), + }; + }; +} diff --git a/src/presets/presetConfigs.json b/src/presets/presetConfigs.json index b172cfb..69a704d 100644 --- a/src/presets/presetConfigs.json +++ b/src/presets/presetConfigs.json @@ -51,4 +51,4 @@ "maxCameraLength": 9.9, "cameraLengthStep": 2 } -} \ No newline at end of file +} diff --git a/src/results/rangeDiagram.tsx b/src/results/rangeDiagram.tsx index 7baf394..298c25e 100644 --- a/src/results/rangeDiagram.tsx +++ b/src/results/rangeDiagram.tsx @@ -22,8 +22,8 @@ export function RangeDiagram(props: { fullRange: UnitRange; requestedRange: UnitRange; }): JSX.Element { - console.log(props.requestedRange.min.formatUnits()) - const svgRange = props.visibleRange.max.toNumber() - props.visibleRange.min.toNumber(); + const svgRange = + props.visibleRange.max.toNumber() - props.visibleRange.min.toNumber(); const requestedMax = (props.requestedRange.max.toNumber() / svgRange) * 100; const requestedMin = (props.requestedRange.min.toNumber() / svgRange) * 100; const rectColour = props.visibleRange.containsRange(props.requestedRange) diff --git a/src/results/rangeTable.tsx b/src/results/rangeTable.tsx index 9f5d078..74626e9 100644 --- a/src/results/rangeTable.tsx +++ b/src/results/rangeTable.tsx @@ -21,10 +21,7 @@ import { } from "./scatteringQuantities"; import UnitRange from "../calculations/unitRange"; - -export default function RangeTable(props: { - qRange: UnitRange; -}): JSX.Element { +export default function RangeTable(props: { qRange: UnitRange }): JSX.Element { const resultsStore = useResultStore(); const updateQUnits = useResultStore((state) => state.updateQUnits); const updateSUnits = useResultStore((state) => state.updateSUnits); @@ -43,10 +40,13 @@ export default function RangeTable(props: { const handleDunits = (event: SelectChangeEvent) => { updateDUnits(event.target.value as WavelengthUnits); }; - const qRange = props.qRange.to(resultsStore.qUnits as string) - const sRange = props.qRange.apply(convertBetweenQAndS).to(resultsStore.sUnits as string); - const dRange = props.qRange.apply(convertBetweenQAndD).to(resultsStore.dUnits as string); - + const qRange = props.qRange.to(resultsStore.qUnits as string); + const sRange = props.qRange + .apply(convertBetweenQAndS) + .to(resultsStore.sUnits as string); + const dRange = props.qRange + .apply(convertBetweenQAndD) + .to(resultsStore.dUnits as string); return ( @@ -66,10 +66,14 @@ export default function RangeTable(props: { {ScatteringOptions.q} - {isNaN(qRange.min.toNumber()) ? "" : qRange.min.toNumber().toFixed(4)} + {isNaN(qRange.min.toNumber()) + ? "" + : qRange.min.toNumber().toFixed(4)} - {isNaN(qRange.max.toNumber()) ? "" : qRange.max.toNumber().toFixed(4)} + {isNaN(qRange.max.toNumber()) + ? "" + : qRange.max.toNumber().toFixed(4)} @@ -95,10 +99,14 @@ export default function RangeTable(props: { {ScatteringOptions.s} - {isNaN(sRange.min.toNumber()) ? "" : sRange.min.toNumber().toFixed(4)} + {isNaN(sRange.min.toNumber()) + ? "" + : sRange.min.toNumber().toFixed(4)} - {isNaN(sRange.max.toNumber()) ? "" : sRange.max.toNumber().toFixed(4)} + {isNaN(sRange.max.toNumber()) + ? "" + : sRange.max.toNumber().toFixed(4)} @@ -124,10 +132,14 @@ export default function RangeTable(props: { {ScatteringOptions.d} - {isNaN(dRange.min.toNumber()) ? "" : dRange.min.toNumber().toFixed(4)} + {isNaN(dRange.min.toNumber()) + ? "" + : dRange.min.toNumber().toFixed(4)} - {isNaN(dRange.max.toNumber()) ? "" : dRange.max.toNumber().toFixed(4)} + {isNaN(dRange.max.toNumber()) + ? "" + : dRange.max.toNumber().toFixed(4)} diff --git a/src/results/resultsBar.tsx b/src/results/resultsBar.tsx index 300fc7b..db6a000 100644 --- a/src/results/resultsBar.tsx +++ b/src/results/resultsBar.tsx @@ -12,9 +12,7 @@ import { } from "@mui/material"; import NumericRange from "../calculations/numericRange"; import { ScatteringOptions, useResultStore } from "./resultsStore"; -import { - parseNumericInput, -} from "../utils/units"; +import { parseNumericInput } from "../utils/units"; import { RangeDiagram, MessageDiagram } from "./rangeDiagram"; import Radio from "@mui/material/Radio"; import RadioGroup from "@mui/material/RadioGroup"; @@ -55,19 +53,32 @@ export default function ResultsBar(props: { if (props.visableQRange && props.fullQrange && requestedRange) { switch (resultStore.requested) { case ScatteringOptions.d: - diagramVisible = props.visableQRange.apply(convertBetweenQAndD).to("nm"); + diagramVisible = props.visableQRange + .apply(convertBetweenQAndD) + .to("nm"); diagramFull = props.fullQrange.apply(convertBetweenQAndD).to("nm"); - diagramRequested = UnitRange.fromNumericRange(requestedRange, resultStore.dUnits as string).to("nm"); + diagramRequested = UnitRange.fromNumericRange( + requestedRange, + resultStore.dUnits as string, + ).to("nm"); break; case ScatteringOptions.s: - diagramVisible = props.visableQRange.apply(convertBetweenQAndS).to("nm"); + diagramVisible = props.visableQRange + .apply(convertBetweenQAndS) + .to("nm"); diagramFull = props.fullQrange.apply(convertBetweenQAndS).to("nm"); - diagramRequested = UnitRange.fromNumericRange(requestedRange, resultStore.sUnits as string).to("nm"); + diagramRequested = UnitRange.fromNumericRange( + requestedRange, + resultStore.sUnits as string, + ).to("nm"); break; default: diagramVisible = props.visableQRange.to("nm^-1"); diagramFull = props.fullQrange.to("nm^-1"); - diagramRequested = UnitRange.fromNumericRange(requestedRange, resultStore.qUnits as string).to("nm^-1"); + diagramRequested = UnitRange.fromNumericRange( + requestedRange, + resultStore.qUnits as string, + ).to("nm^-1"); } } diff --git a/src/results/scatteringQuantities.ts b/src/results/scatteringQuantities.ts index ad43fc7..6d4c5c4 100644 --- a/src/results/scatteringQuantities.ts +++ b/src/results/scatteringQuantities.ts @@ -1,17 +1,17 @@ import * as mathjs from "mathjs"; export const convertBetweenQAndS = (quantity: mathjs.Unit): math.Unit => { - return mathjs.divide(1,quantity); + return mathjs.divide(1, quantity); }; export const convertBetweenQAndD = (quantity: mathjs.Unit): mathjs.Unit => { - return mathjs.divide( (2 * Math.PI) , quantity); + return mathjs.divide(2 * Math.PI, quantity); }; export const convertFromDTooS = (quantity: mathjs.Unit): mathjs.Unit => { - return mathjs.divide(quantity ,(2 * Math.PI)); + return mathjs.divide(quantity, 2 * Math.PI); }; export const convertFromStooD = (quantity: mathjs.Unit): mathjs.Unit => { - return mathjs.multiply(quantity ,(2 * Math.PI)); + return mathjs.multiply(quantity, 2 * Math.PI); }; diff --git a/src/utils/units.ts b/src/utils/units.ts index 2608909..a17ffb9 100644 --- a/src/utils/units.ts +++ b/src/utils/units.ts @@ -3,7 +3,6 @@ import * as math from "mathjs"; export const CSPEED = math.unit(299792458, "m/s"); export const PLANCK = math.unit(6.62607015e-34, "J s"); - export enum DistanceUnits { millimetre = "mm", micrometre = "um",