-
- Notifications
You must be signed in to change notification settings - Fork 17
refactor: rewrite of geometryutil as typescript #132
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
base: main
Are you sure you want to change the base?
Conversation
938990c to aa18cbe Compare
willmurnane left a comment
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.
Most of these comments can be resolved later, but just commenting while I'm looking at this.
| | ||
| // Build the UMD modules using Rollup | ||
| console.log('Building UMD modules with Rollup...'); | ||
| execSync('npx rollup -c rollup.config.mjs', { stdio: 'inherit' }); |
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.
I'm not familiar with UMD modules, what benefit do they give?
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.
| | ||
| import { NfpCache } from '../build/nfpDb.js'; | ||
| import { HullPolygon } from '../build/util/HullPolygon.js'; | ||
| import * as GeometryUtil from '../build/util/geometryutil.js'; |
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.
Are both built versions necessary, or should this import the UMD as well?
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.
both are needed the UMD is for the worker, and the non UMD is used in non worker context.
main/util/geometryutil.ts Outdated
| x?: number; | ||
| y?: number; | ||
| width?: number; | ||
| height?: number; |
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.
What about making a bounds?: Bounds to make it clearer what the meaning of these values are?
| height: number; | ||
| } | ||
| | ||
| export interface QuadraticBezierSegmentDef { |
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.
Should these be exported? They're not apparently used outside of this file. We should define constructors for the QuadraticBezier class for example, and use those.
| export function almostEqual(a: number, b: number, tolerance?: number): boolean { | ||
| return _internalAlmostEqual(a, b, tolerance); | ||
| } |
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.
I don't know of a reason to define a private function with a body in it, and then make the public method call that. Why not just put the body here, and get rid of the private function?
main/util/geometryutil.ts Outdated
| ): boolean { | ||
| const dx = p1.x - p2.x; | ||
| const dy = p1.y - p2.y; | ||
| return dx * dx + dy * dy < distance * distance; |
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.
| return dx * dx + dy * dy < distance * distance; | |
| return Math.hypot(dx, dy) < distance; |
main/util/geometryutil.ts Outdated
| return _internalLineIntersect(A, B, E, F, infinite); | ||
| } | ||
| | ||
| export const QuadraticBezier = { |
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.
Should this be a class?
main/util/geometryutil.ts Outdated
| const p1c1: Point = new Point( | ||
| t_p1.x + (t_c1.x - t_p1.x) * t, | ||
| t_p1.y + (t_c1.y - t_p1.y) * t, | ||
| ); |
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.
Should define and use a lerp function that encapsulates the "partway from one point to another" behavior.
| }, | ||
| }; | ||
| | ||
| export function getPolygonBounds(polygon: Polygon): Bounds | null { |
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.
This should be a member function of the Polygon class.
- Added unit tests for all functions in geometryutil.ts - Refactored code for better readability and maintainability - Removed unused imports and variables - Improved type definitions and interfaces polygon needs to updated where it called getPolygonBounds
| ATTENTION: getPolygonBounds calls against GeometryUtil needs to updated the polygon calls for x,y, width and height |
This refactoring needs #131 merged before