Fix arrow inside shape

feat/remove-ga
Mark Tolmacs 5 days ago
parent 7ceede4238
commit 4928742aca
No known key found for this signature in database

@ -1221,16 +1221,36 @@ const updateBoundPoint = (
elementsMap, elementsMap,
); );
newEdgePoint = const intersections = intersectElementWithLineSegment(
intersectElementWithLineSegment( bindableElement,
bindableElement, lineSegment<GlobalPoint>(
lineSegment<GlobalPoint>(adjacentPoint, focusPointAbsolute), adjacentPoint,
binding.gap, pointFromVector(
).sort( vectorScale(
(g, h) => vectorNormalize(vectorFromPoint(focusPointAbsolute, adjacentPoint)),
pointDistanceSq(g, edgePointAbsolute) - Math.max(bindableElement.width, bindableElement.height) * 2,
pointDistanceSq(h, edgePointAbsolute), ),
)[0] ?? edgePointAbsolute; adjacentPoint,
),
),
binding.gap,
).sort(
(g, h) =>
// pointDistanceSq(g, edgePointAbsolute) -
// pointDistanceSq(h, edgePointAbsolute),
pointDistanceSq(g, adjacentPoint) - pointDistanceSq(h, adjacentPoint),
);
if (intersections.length > 1) {
// The adjacent point is outside the shape (+ gap)
newEdgePoint = intersections[0];
} else if (intersections.length === 1) {
// The adjacent point is inside the shape (+ gap)
newEdgePoint = focusPointAbsolute;
} else {
// Shouldn't happend, but just in case
newEdgePoint = edgePointAbsolute;
}
} }
return LinearElementEditor.pointFromAbsoluteCoords( return LinearElementEditor.pointFromAbsoluteCoords(
@ -1574,17 +1594,22 @@ const determineFocusDistance = (
.filter((p) => !pointOnLineSegment(p, lineSegment(a, b))) .filter((p) => !pointOnLineSegment(p, lineSegment(a, b)))
.map((p, idx): [GlobalPoint, number] => [p, idx]) .map((p, idx): [GlobalPoint, number] => [p, idx])
.sort((g, h) => pointDistanceSq(g[0], b) - pointDistanceSq(h[0], b))[0] ?? .sort((g, h) => pointDistanceSq(g[0], b) - pointDistanceSq(h[0], b))[0] ??
center; [];
// console.log(ordered[0]);
// debugClear();
// debugDrawPoint(ordered[0], { color: "red", permanent: true });
const sign = const sign =
Math.sign(vectorCross(vectorFromPoint(b, a), vectorFromPoint(b, center))) * Math.sign(vectorCross(vectorFromPoint(b, a), vectorFromPoint(b, center))) *
-1; -1;
const signedDist = sign * pointDistance(center, ordered[0]); const signedDist = sign * pointDistance(center, ordered[0]);
const signedDistanceRatio = const signedDistanceRatio = ordered[1]
signedDist / ? signedDist /
(element.type === "diamond" (element.type === "diamond"
? pointDistance(axes[ordered[1]][0], axes[ordered[1]][1]) / 2 ? pointDistance(axes[ordered[1]][0], axes[ordered[1]][1]) / 2
: Math.sqrt(element.width ** 2 + element.height ** 2) / 2); : Math.sqrt(element.width ** 2 + element.height ** 2) / 2)
: 0;
return signedDistanceRatio; return signedDistanceRatio;
}; };

Loading…
Cancel
Save