-
Notifications
You must be signed in to change notification settings - Fork 9
Testing #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LEVPROGRAMMER
wants to merge
3
commits into
gemtechd:main
Choose a base branch
from
LEVPROGRAMMER:testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Testing #6
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| testEnvironment: 'node', | ||
| transform: { | ||
| '^.+\\.ts$': 'ts-jest', // אם אתה משתמש ב-TypeScript | ||
| }, | ||
| moduleFileExtensions: ['js', 'ts'], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,50 +1,34 @@ | ||
| import Point from "./point"; | ||
|
|
||
| export default class Line { | ||
| point1: Point | ||
| point2: Point | ||
| n: number | undefined | ||
| slope: number | undefined | ||
| constructor({ point1 = new Point(), point2 = new Point(), n = undefined, slope = undefined }: { point1?: Point, point2?: Point, n?: number, slope?: number } = {}) { | ||
| class Line { | ||
| point1: Point; | ||
| point2: Point; | ||
| n: number; | ||
| slope: number; | ||
| constructor({ point1, point2 }: { point1: Point, point2: Point }) { | ||
| this.point1 = point1; | ||
| this.point2 = point2; | ||
| this.slope = slope; | ||
| this.n = n; | ||
| this.calculateSlope(); | ||
| this.calculateNOfLineFunction(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| calculateSlope() { | ||
| this.slope = (this.point1.y - this.point2.y) / (this.point1.x - this.point2.x) | ||
| this.slope = (this.point2.y - this.point1.y) / (this.point2.x - this.point1.x); | ||
| } | ||
|
|
||
| calculateNOfLineFunction() { | ||
| if (this.slope) | ||
| this.n = this.point1.y - this.slope * this.point1.x | ||
| this.n = this.point1.y - this.slope * this.point1.x; | ||
| } | ||
|
|
||
| getPointOnXAsis() { | ||
| return this.getPointByY(0) | ||
| return this.getPointByY(0); | ||
| } | ||
|
|
||
| getPointOnYAsis() { | ||
| return this.getPointByX(0) | ||
| return this.getPointByX(0); | ||
| } | ||
|
|
||
|
|
||
| getPointByX(x: number) { | ||
| if (this.slope && this.n) { | ||
| let y = this.slope * x + this.n | ||
| return new Point({ x, y }) | ||
| } | ||
| 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 }) | ||
| } | ||
| let x = (y - this.n) / this.slope; | ||
| return new Point({ x, y }); | ||
| } | ||
|
|
||
|
|
||
| } | ||
| export default Line; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| export default class Point { | ||
| class Point { | ||
| x: number | ||
| y: number | ||
| constructor({ x = 0, y = 0 }:{x?:number, y?:number} = {}) { | ||
| constructor({ x = 0, y = 0 }: { x?: number, y?: number } = {}) { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| moveVertical(value:number) { | ||
| moveVertical(value: number) { | ||
| this.y += value; | ||
| } | ||
| moveHorizontal(value:number) { | ||
| moveHorizontal(value: number) { | ||
| this.x += value; | ||
| } | ||
| } | ||
|
|
||
| export default Point; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,27 @@ | ||
| import Line from './ecs6-class/line'; | ||
| 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 distanceX = Math.abs(point2.x - point1.x) ** 2; | ||
| let distanceY = Math.abs(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 isPointOnLine = (line: Line, point: Point): Boolean => { | ||
| if (typeof line.slope !== 'number' || typeof line.n !== 'number' || typeof point.x !== 'number' || typeof point.y !== 'number') { | ||
| throw new Error('Invalid input types'); | ||
| } | ||
| const expectedY = line.slope * point.x + line.n; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't remove the functions |
||
| const tolerance = 0.0001; | ||
| return Math.abs(point.y - expectedY) < tolerance; | ||
| } | ||
|
|
||
| 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 | ||
| export const calculateJunctionPoint = (line1: Line, line2: Line): Point | false | true => { | ||
| if (line1.slope === line2.slope) { | ||
| if (line1.n === line2.n) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| return false | ||
| } | ||
|
|
||
|
|
||
| const x = (line2.n - line1.n) / (line1.slope - line2.slope); | ||
| const y = line1.slope * x + line1.n; | ||
| return new Point({ x, y }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be more specific, the line can be updated by the points (each point can be moved) so you'll have to calculate this functions again