feat(g.Point): add chooseClosestIndex() and string support in update() - #3502
Open
kumilingus wants to merge 5 commits into
Open
kumilingus wants to merge 5 commits into
kumilingus wants to merge 5 commits into
Conversation
`chooseClosestIndex(points)` returns the index of the closest point (`-1` for an empty array), so callers can keep a reference to their own anchor object instead of receiving a copy. `chooseClosest()` is now a thin wrapper over it. The search reuses a single scratch `Point` via `update()` rather than allocating one per candidate. For that to cover every `PointInit`, `update()` now parses `'10 20'` / `'10@20'` strings the same way the constructor does; previously it silently stored the string as `x`. The fixed-connection-points story replaces its hand-rolled closest-anchor loop with the new method. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The public typing gains a `PointInit` overload, which is new API surface rather than a fix of a documented behavior. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… story The story only reads x/y from the found anchor, so the `g.Point` copy from `chooseClosest()` is enough; its `| null` return also makes the empty-anchors case explicit (falls back to the drop point) instead of indexing past the array. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ring parsing code Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ests Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
g.Point#chooseClosestIndex(points)— returns the index of the closest point inpoints,-1for an empty array. Useful when the caller needs its own anchor object back rather than ag.Pointcopy (thechooseClosest()contract).chooseClosest()is now a thin wrapper over it.Pointviaupdate()instead ofnew Point(points[i])for every item.g.Point#update()accepts strings —'10 20'/'10@20'are parsed the same way the constructor does (sharedparsePointString()). Previouslyupdate('10 20')silently stored the string asxand0asy. Typing widened fromPlainPointtoPointInitto match the constructor and runtime.fixed-connection-pointsstory — hand-rolled closest-anchor loop replaced withchooseClosest()(the story only readsx/y, so the copy is fine); the| nullreturn makes the empty-anchors case explicit and falls back to the drop point instead of indexing past the array.Changesets: two
minorentries, one for the new method and one for theupdate()string support (newPointInitoverload in the public typings).The same hand-rolled loop lives in
joint-demos/fixed-connection-points. Like the story, it only readsx/yfrom the result, so it can switch to the already-releasedchooseClosest()independently of this PR.chooseClosestIndex()is for callers that need their original anchor object back (identity, or anchors carrying extra data such as anidor side).Test plan
karma:geometry— 353/353 (new tests:chooseClosestIndexincl. empty / single /g.Point/ string / partial{ x }inputs and tie → first index;update()with string arg). Each new test was watched failing first.grunt test:ts(core typings)joint-react: eslint on the story;tsc --noEmitreports no errors in touched files🤖 Generated with Claude Code