parser and editor use same code for figuring out what is connected to what
This commit is contained in:
parent
6dc7a2e9a7
commit
b55cba198e
6 changed files with 228 additions and 149 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { Rect2D, Vec2D, Line2D, euclideanDistance, intersectLines, isWithin, lineBBox } from "../VisualEditor/geometry";
|
||||
import { ARROW_SNAP_THRESHOLD, TEXT_SNAP_THRESHOLD } from "../VisualEditor/parameters";
|
||||
import { Rect2D, Vec2D, Line2D, euclideanDistance, intersectLines, isWithin, lineBBox, subtractV2D } from "../VisualEditor/geometry";
|
||||
import { ARROW_SNAP_THRESHOLD, HISTORY_RADIUS, TEXT_SNAP_THRESHOLD } from "../VisualEditor/parameters";
|
||||
import { sides } from "../VisualEditor/VisualEditor";
|
||||
|
||||
export type Rountangle = {
|
||||
|
|
@ -115,3 +115,19 @@ export function findRountangle(point: Vec2D, candidates: Rountangle[]): Rountang
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function findNearestHistory(point: Vec2D, candidates: History[]): History | undefined {
|
||||
let best;
|
||||
let bestDistance = Infinity;
|
||||
for (const h of candidates) {
|
||||
const diff = subtractV2D(point, {x: h.topLeft.x+HISTORY_RADIUS, y: h.topLeft.y+HISTORY_RADIUS});
|
||||
const euclideanDistance = Math.hypot(diff.x, diff.y) - HISTORY_RADIUS;
|
||||
if (euclideanDistance < ARROW_SNAP_THRESHOLD) {
|
||||
if (euclideanDistance < bestDistance) {
|
||||
best = h;
|
||||
bestDistance = euclideanDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue