diff --git a/src/app.tsx b/src/app.tsx index 6a24873..2ab2219 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -11,8 +11,8 @@ export default function App(): JSX.Element { - - + + diff --git a/src/calculations/circularDevice.ts b/src/calculations/circularDevice.ts index 024ee1c..49fcca8 100644 --- a/src/calculations/circularDevice.ts +++ b/src/calculations/circularDevice.ts @@ -1,12 +1,9 @@ import Vector2D from "./vector"; +/** + * Represents devices which have a circular profile such as a beam stop or camera + */ export interface CircularDevice { centre: Vector2D; diameter: number; -} - -// rememeber i wont make beamstop or camera tube classes as they both just implement circular device - -// this exists so that we can keep a record of the diameter in both mm diameter and px diameter - -// think about quantitiy \ No newline at end of file +} \ No newline at end of file diff --git a/src/calculations/ray.test.ts b/src/calculations/ray.test.ts new file mode 100644 index 0000000..228dcea --- /dev/null +++ b/src/calculations/ray.test.ts @@ -0,0 +1,11 @@ +import { expect, test } from "vitest"; +import { Ray } from "./ray"; +import Vector2D from "./vector"; + +test("Getting a point from a ray", () => { + const ray1 = new Ray(new Vector2D(1, 1), new Vector2D(1, 1)); + const vector1 = ray1.getPoint(5) + const vector2 = new Vector2D(6, 6) + expect(vector1?.equals(vector2)) +}); + diff --git a/src/calculations/ray.ts b/src/calculations/ray.ts index 66c69bd..9c6a422 100644 --- a/src/calculations/ray.ts +++ b/src/calculations/ray.ts @@ -13,6 +13,11 @@ export class Ray { this.initial_point = initial_point; } + /** + * Returns a point in the ray + * @param scalar + * @returns + */ getPoint(scalar: number): Vector2D | null { if (scalar < 0) return null; const result = new Vector2D(this.direction.x, this.direction.y); @@ -54,8 +59,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; diff --git a/src/calculations/vector.ts b/src/calculations/vector.ts index 6a5217e..0f20025 100644 --- a/src/calculations/vector.ts +++ b/src/calculations/vector.ts @@ -1,3 +1,6 @@ +/** + * A Simple vector class to store the x and y coordinate of a vector in 2d space + */ export default class Vector2D { x: number; y: number; @@ -6,24 +9,45 @@ export default class Vector2D { this.y = y; } + /** + * Sums two vectors together + * @param vector + */ add(vector: Vector2D): void { this.x += vector.x; this.y += vector.y; } + /** + * Scales the vector ny some scalar value + * @param value + */ scale(value: number): void { this.y *= value; this.x *= value; } + /** + * Returns the euclidean norm of the vector + * @returns + */ length(): number { return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2)); } + /** + * Tests equality between two vectors + * @param other Another Vector2D object + * @returns boolean + */ equals(other: Vector2D): boolean { return this.x === other.x && this.y === other.y; } + /** + * Serialises a Vector2D object + * @returns + */ toString(): string { return `(x:${this.x}, y:${this.y})`; }