-
Notifications
You must be signed in to change notification settings - Fork 0
feat: allow boundary strategy to be passed when updating rois programmatically #177
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
Merged
stropitek
merged 11 commits into
main
from
175-allow-boundary-strategy-to-be-passed-when-updating-rois-programmatically
Nov 20, 2025
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e42def7
feat: add option when commiting ROI through updateRoi actions API to …
stropitek e1acee1
docs: re-organize stories
stropitek 80adbe8
Merge remote-tracking branch 'origin/main' into 175-allow-boundary-st…
stropitek 60efc18
fix: correct implementation of rectangle intersection detection
stropitek 626ca72
chore: remove unused function
stropitek 56a4106
refactor: return tuple from getRectanglePoints
stropitek 7ab7b49
fixup: prefer unnamed tuple
stropitek 1e4bb4f
fix: make return type of getRectanglePoints on CommittedRoi class imp…
stropitek 296cd87
docs: add jsdoc in api facing method to describe the order of returne…
stropitek 5cd1586
chore: apply review recommendation
stropitek b2083f4
docs: add some explanations to the update position with commit strate…
stropitek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { BoundaryStrategy } from './utils.ts'; | ||
|
|
||
| export type UpdateRoiOptions = | ||
| | UpdateRoiOptionsNoCommit | ||
| | UpdateRoiOptionsWithCommit; | ||
|
|
||
| export interface UpdateRoiOptionsNoCommit { | ||
| /** | ||
| * Whether the update should be committed immediately. | ||
| * In both cases, the ROI will move immediately on screen. | ||
| * If set to false, the ROI will enter a mode where it can't be modified through user interactions until committed. | ||
| * Setting it to false also prevents having frequent updates to committed ROIs when those can trigger expensive operations. | ||
| */ | ||
| commit: false; | ||
| } | ||
|
|
||
| // The inside_auto strategy is excluded because it requires to know about the nature of the action (move, resize, etc.). | ||
| export type UpdateRoiOptionsBoundaryStrategy = Exclude< | ||
| BoundaryStrategy, | ||
| 'inside_auto' | ||
| >; | ||
|
|
||
| export interface UpdateRoiOptionsWithCommit { | ||
| commit: true; | ||
| boundaryStrategy?: UpdateRoiOptionsBoundaryStrategy; | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import type { CommittedBox } from '../types/box.ts'; | ||
|
|
||
| import { getRectanglePoints } from './box.ts'; | ||
| import type { Point } from './point.ts'; | ||
| import { dotProduct, subtract } from './point.ts'; | ||
|
|
||
| // Check if 2 rectangles intersect based on the separating Axis Theorem (SAT) | ||
| export function rectanglesIntersect( | ||
| rect1: CommittedBox, | ||
| rect2: CommittedBox, | ||
| ): boolean { | ||
| const corners1 = getRectanglePoints(rect1); | ||
| const corners2 = getRectanglePoints(rect2); | ||
|
|
||
| const axes = [...getAxes(corners1), ...getAxes(corners2)]; | ||
|
|
||
| for (const axis of axes) { | ||
| const proj1 = projectOntoAxis(corners1, axis); | ||
| const proj2 = projectOntoAxis(corners2, axis); | ||
|
|
||
| if (proj1.max < proj2.min || proj2.max < proj1.min) { | ||
| return false; // Gap found, no intersection | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| function getAxes(corners: Point[]): Point[] { | ||
| const axes: Point[] = []; | ||
| for (let i = 0; i < corners.length; i++) { | ||
| const p1 = corners[i]; | ||
| const p2 = corners[(i + 1) % corners.length]; | ||
| const edge = subtract(p2, p1); | ||
| // Perpendicular axis | ||
| axes.push({ x: -edge.y, y: edge.x }); | ||
| } | ||
| return axes; | ||
| } | ||
|
|
||
| function projectOntoAxis( | ||
| corners: Point[], | ||
| axis: Point, | ||
| ): { min: number; max: number } { | ||
| const projections = corners.map((c) => dotProduct(c, axis)); | ||
| return { | ||
| min: Math.min(...projections), | ||
| max: Math.max(...projections), | ||
| }; | ||
| } |
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
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
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
10 changes: 5 additions & 5 deletions
10
stories/hooks/useActions/mode.stories.tsx → stories/1-actions/mode.stories.tsx
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.