Skip to content

Commit

Permalink
add some doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Aug 17, 2023
1 parent 1090350 commit 0cabba1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default function App(): JSX.Element {
<Box sx={{ width: 1, height: 1 }}>
<Stack direction={'row'}>
<DataSideBar />
<Stack direction={'column'} flexGrow={1}>
<Stack direction={'row'} flexGrow={1}>
<Stack direction={'column'} flexGrow={2}>
<Stack direction={'row'} flexGrow={2}>
<CentrePlot />
<LegendBar />
</Stack>
Expand Down
11 changes: 4 additions & 7 deletions src/calculations/circularDevice.ts
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 11 additions & 0 deletions src/calculations/ray.test.ts
Original file line number Diff line number Diff line change
@@ -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))
});

9 changes: 7 additions & 2 deletions src/calculations/ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions src/calculations/vector.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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})`;
}
Expand Down

0 comments on commit 0cabba1

Please sign in to comment.