Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
import type { JestConfigWithTsJest } from 'ts-jest';

const config: JestConfigWithTsJest = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: [
"**/test/**/*.test.ts"
]
};

export default config;
23 changes: 11 additions & 12 deletions modules/ecs6-class/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@ export default class Line {
}


getPointByX(x: number) {
if (this.slope && this.n) {
let y = this.slope * x + this.n
return new Point({ x, y })
}

getPointByX(x: number) {
if (this.slope !== undefined && this.n !== undefined) {
let y = this.slope * x + this.n;
return new Point({ x, y });
}
}

getPointByY(y: number) {
if (this.slope && this.n) {
let x = (y - this.n) / this.slope;
return new Point({ x, y })
}
getPointByY(y: number) {
if (this.slope !== undefined && this.n !== undefined) {
let x = (y - this.n) / this.slope;
return new Point({ x, y });
}


}
}
55 changes: 28 additions & 27 deletions modules/geometry-calculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,40 @@ import Point from './ecs6-class/point';

export const calculateDistance = (point1: Point, point2: Point): number => {
let distanceX = (point2.x - point1.x) ** 2;
let distanceY = (point2.y - point2.y) ** 2;
let distanceY = (point2.y - point1.y) ** 2;
const distance = Math.sqrt(distanceX + distanceY);
return distance;
}

export const calculateJunctionPoint = (line1: Line, line2: Line): Boolean | Point | undefined => {
if (line1.slope === line2.slope) {
if (line1.n === line2.n) {
return true
}
else {
return false
}
}
else {
if (line1.n !== undefined && line1.slope !== undefined && line2.n !== undefined && line2.slope !== undefined) {
const x = (line1.n - line2.n) / (line2.slope - line1.slope)
const junctionPoint = line1.getPointByX(x);
return junctionPoint
}


export const calculateJunctionPoint = (line1: Line, line2: Line): boolean | Point | undefined => {
if (line1.slope === undefined || line2.slope === undefined || line1.n === undefined || line2.n === undefined) {
return undefined;
}
}

export const isPointOnLine = (line: Line, point: Point): Boolean => {
const proxyLine = new Line({ point1: line.point1, point2: point })
proxyLine.calculateSlope()
if (line.slope === proxyLine.slope) {
proxyLine.calculateNOfLineFunction()
if (line.n === proxyLine.n) {
return true
}

if (line1.slope === line2.slope && line1.n === line2.n) {
return true;
}
return false
}


if (line1.slope === line2.slope) {
return false;
}


const x = (line1.n - line2.n) / (line2.slope - line1.slope);
const y = line1.slope * x + line1.n;
const junctionPoint = new Point({x, y});
return junctionPoint;
};
export const isPointOnLine = (line: Line, point: Point): boolean => {
const proxyLine = new Line({ point1: line.point1, point2: point });
proxyLine.calculateSlope();
if (line.slope === proxyLine.slope) {
proxyLine.calculateNOfLineFunction();
return line.n === proxyLine.n;
}
return false;
};
189 changes: 189 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
"test": "jest",
"coverage": "jest --coverage"

},
"repository": {
"type": "git",
Expand All @@ -22,6 +24,7 @@
"devDependencies": {
"@types/jest": "^30.0.0",
"jest": "^30.0.4",
"ts-jest": "^29.4.0",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
}
Expand Down
Loading