feat: implement type-safe isomorphic coords helpers#1233
feat: implement type-safe isomorphic coords helpers#1233shadowusr wants to merge 1 commit intotestplane@9from
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97b73c48d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| scaled[key] = v[key] * pixelRatio; | ||
| } | ||
|
|
||
| return (pixelRatio % 1 === 0 ? scaled : roundCoords(scaled as Rect<Space, Unit>)) as unknown as CssToDevice<T>; |
There was a problem hiding this comment.
Handle Size inputs in fractional css→device conversion
fromCssToDevice explicitly accepts Size<"css">, but in the fractional-pixelRatio branch it routes through roundCoords, which only fills fields when top/left exist. For a size object ({ width, height }), this returns an empty object at runtime, so downstream code gets undefined dimensions on non-integer DPR values (for example 1.25/1.5), breaking size-based geometry.
Useful? React with 👍 / 👎.
| coordRelativeToViewport: Coord<"viewport", U, "y">, | ||
| captureAreaTopRelativeToViewport: Coord<"viewport", U, "y">, | ||
| ): Coord<"capture", U, "y"> => { | ||
| return getHeight(coordRelativeToViewport, captureAreaTopRelativeToViewport) as number as Coord<"capture", U, "y">; |
There was a problem hiding this comment.
Preserve sign when converting viewport to capture coords
fromViewportToCaptureArea uses getHeight, which applies Math.abs, so it always returns a non-negative offset. Coordinate conversion should preserve direction (it should be the inverse of fromCaptureAreaToViewport), and inputs above the capture-area top should produce negative values; with the current code those values are mirrored to positive and can place/crop geometry on the wrong side.
Useful? React with 👍 / 👎.
What's done?
Implemented a type system for type-safe coords operations.
With these, it becomes much harder to confuse numbers from different spaces or units.
These helpers are broadly used in the upcoming PRs.
For example:
leftandtopvalues without explicit type casting