Skip to content

Conert to TS - #33

Draft
ItsNickBarry wants to merge 44 commits into
masterfrom
ts-module
Draft

Conert to TS#33
ItsNickBarry wants to merge 44 commits into
masterfrom
ts-module

Conversation

@ItsNickBarry

Copy link
Copy Markdown
Owner

This PR is primarily focused on converting the code from JS to TS, but also includes a significant number of breaking API changes meant to simplify the type system.

- Add "type": "module" to package.json
- Convert all CommonJS require/module.exports to ESM import/export
- Restructure to avoid circular dependencies:
  - hyperbolic_canvas.js exports the namespace object only
  - index.js imports namespace first, then other modules
  - Other modules import namespace and attach classes to it
- Convert all test files to ESM
This is a permissive/minimal TypeScript conversion to enable the build
system. The tsconfig is intentionally relaxed with strict: false and
noImplicitAny: false to minimize changes to the original JS code.

Changes:
- Renamed all src/*.js files to src/*.ts
- Added minimal type annotations for:
  - Math.TAU global declaration
  - HyperbolicCanvas typed as 'any'
  - Static properties: Circle.UNIT, Line.X_AXIS/Y_AXIS, Point.ORIGIN/CENTER
- Added TypeScript dependencies and build scripts
- Created tsconfig.json with Node 22 base config

Type safety improvements to follow in subsequent commits.
- Add tsx as devDependency for TypeScript test execution
- Update test script to use tsx instead of node
- Update test helper to import from src/index.js (tsx resolves to .ts)

This allows tests to run directly against TypeScript source without
requiring a build step, and coverage reports show .ts files instead
of compiled .js output.
- Convert test files (.js → .ts) with type annotations
- Add typecheck script and tsconfig.test.json
Add method to check if a circle lies entirely within the hyperbolic
plane (unit disk). Returns true if the circle's Euclidean center
distance from origin plus its Euclidean radius is less than 1.

Includes tests for both on-plane and off-plane cases.
Change Point.hyperbolicBetween to throw an error instead of
returning false when either point is not on the hyperbolic plane.
This simplifies the return type from Point | false to just Point.

Update tests to verify the error is thrown in all invalid cases.
Change Line.getHyperbolicMidpoint to throw an error instead of
returning false when the line is not on the hyperbolic plane.
This simplifies the return type from Point | false to just Point.

Update test to verify the error is thrown for lines not on plane.
Remove the options.infinite branch from #pathForHyperbolicPolygon.
This eliminates the only internal usage of Line.getIdealLine and
Line.getIdealPoints, simplifying the codebase.
Remove the getIdealLine method and its associated private field
#idealLine. This method was no longer needed after removing the
infinite option from pathForHyperbolicPolygon. Update tests to
remove assertions for getIdealLine.
Remove the global Math.TAU augmentation and instead export TAU
as a regular constant from constants.ts. This is cleaner and
avoids modifying built-in objects.

Update all imports and usages across src/ and test/ files.
Also update API.md documentation to reflect the new usage.
Replace the overloaded at() method with two explicit methods:
- getCoordinates(point): Converts Point to canvas coordinates [x, y]
- getPoint(coordinates): Converts canvas coordinates [x, y] to Point

Update all internal usages, scripts, tests, and API documentation.
- Change getHyperbolicCenter() return type from Point | false to Point
- Remove false branch by throwing error when circle is not on plane
- Update tests to expect thrown errors instead of false/NaN returns
The geodesic calculation now throws instead of returning false when the line is not on the hyperbolic plane. This simplifies the return type from Circle | Line | false to Circle | Line.
…est for getEuclideanUnitCircleIntersects empty case

- Line.hyperbolicIntersect now throws descriptive errors when either line is not on the hyperbolic plane instead of returning false

- Added test for getEuclideanUnitCircleIntersects returning empty array when line doesn't intersect unit circle
Replace the method with direct calls to Circle.intersects(circle, Circle.UNIT)
to reduce API surface and simplify the codebase.
- Circle.intersects now returns true when circles are equal (concentric,
  same radius) instead of false
- Line.euclideanIntersect now returns true when lines are equal instead
  of false
- Line.hyperbolicIntersect now returns true when lines have the same
  hyperbolic geodesic
- Add invariant checks that throw errors for geometrically impossible cases
- Add tests for lines being parallel with themselves
- Consistently use typeof x === 'boolean' for boolean checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant