Skip to content

Conversation

@Dexus
Copy link
Member

@Dexus Dexus commented May 20, 2025

This refactoring needs #131 merged before

@Dexus Dexus requested a review from willmurnane May 20, 2025 09:57
@Dexus Dexus force-pushed the refactor-rewrite-geometryutil.js-as-typescript branch from 938990c to aa18cbe Compare May 20, 2025 10:39
@Dexus Dexus marked this pull request as draft May 20, 2025 12:35
@Dexus Dexus marked this pull request as ready for review May 20, 2025 13:14
Copy link
Collaborator

@willmurnane willmurnane left a 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' });
Copy link
Collaborator

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?

Copy link
Member Author

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';
Copy link
Collaborator

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?

Copy link
Member Author

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.

Comment on lines 9 to 12
x?: number;
y?: number;
width?: number;
height?: number;
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Comment on lines 235 to 237
export function almostEqual(a: number, b: number, tolerance?: number): boolean {
return _internalAlmostEqual(a, b, tolerance);
}
Copy link
Collaborator

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?

): boolean {
const dx = p1.x - p2.x;
const dy = p1.y - p2.y;
return dx * dx + dy * dy < distance * distance;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return dx * dx + dy * dy < distance * distance;
return Math.hypot(dx, dy) < distance;
return _internalLineIntersect(A, B, E, F, infinite);
}

export const QuadraticBezier = {
Copy link
Collaborator

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?

Comment on lines 377 to 380
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,
);
Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Dexus added 2 commits May 22, 2025 09:03
- 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
@Dexus
Copy link
Member Author

Dexus commented May 22, 2025

ATTENTION: getPolygonBounds calls against GeometryUtil needs to updated the polygon calls for x,y, width and height

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants