kopia lustrzana https://github.com/Tldraw/Tldraw
Arrows followup (#1972)
This PR includes a few followup small fixes for arrows. ### Change Type - [x] `patch` — Bug fixpull/1973/head^2
rodzic
73e61727cc
commit
9dac6862bf
|
@ -235,9 +235,7 @@ export function getCurvedArrowInfo(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const dist = Vec2d.Dist(tA, tB)
|
if (Vec2d.Dist(tA, tB) < MIN_ARROW_LENGTH) {
|
||||||
|
|
||||||
if (dist < MIN_ARROW_LENGTH) {
|
|
||||||
if (offsetA !== 0 && offsetB !== 0) {
|
if (offsetA !== 0 && offsetB !== 0) {
|
||||||
offsetA *= -1.5
|
offsetA *= -1.5
|
||||||
offsetB *= -1.5
|
offsetB *= -1.5
|
||||||
|
@ -266,29 +264,31 @@ export function getCurvedArrowInfo(
|
||||||
)
|
)
|
||||||
|
|
||||||
// Did we miss intersections? This happens when we have overlapping shapes.
|
// Did we miss intersections? This happens when we have overlapping shapes.
|
||||||
if (
|
if (startShapeInfo && endShapeInfo && !startShapeInfo.isExact && !endShapeInfo.isExact) {
|
||||||
startShapeInfo &&
|
|
||||||
endShapeInfo &&
|
|
||||||
startShapeInfo.shape !== endShapeInfo.shape &&
|
|
||||||
!startShapeInfo.isExact &&
|
|
||||||
!endShapeInfo.isExact
|
|
||||||
) {
|
|
||||||
const startAngle = Vec2d.Angle(handleArc.center, tempA)
|
const startAngle = Vec2d.Angle(handleArc.center, tempA)
|
||||||
const endAngle = Vec2d.Angle(handleArc.center, tempB)
|
const endAngle = Vec2d.Angle(handleArc.center, tempB)
|
||||||
const length = getArcLength(handleArc.center, handleArc.radius, tempA, tempB)
|
const length = getArcLength(handleArc.center, handleArc.radius, tempA, tempB)
|
||||||
|
|
||||||
if (startShapeInfo && !startShapeInfo.didIntersect) {
|
if (startShapeInfo.shape === endShapeInfo.shape) {
|
||||||
tempA.setTo(a)
|
if (Math.abs(length) < 100) {
|
||||||
}
|
tempA.setTo(a)
|
||||||
|
tempB.setTo(b)
|
||||||
if (endShapeInfo && !endShapeInfo.didIntersect) {
|
tempC.setTo(c)
|
||||||
const size = angleDelta(startAngle, endAngle)
|
}
|
||||||
let mid = lerpAngles(startAngle, endAngle, Math.abs(MIN_ARROW_LENGTH / length))
|
} else {
|
||||||
if (+(size > 0) !== handleArc.sweepFlag) {
|
if (startShapeInfo && !startShapeInfo.didIntersect) {
|
||||||
mid = PI2 - mid
|
tempA.setTo(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
tempB.setTo(getPointOnCircle(handleArc.center.x, handleArc.center.y, handleArc.radius, mid))
|
if (endShapeInfo && !endShapeInfo.didIntersect) {
|
||||||
|
const size = angleDelta(startAngle, endAngle)
|
||||||
|
let mid = lerpAngles(startAngle, endAngle, Math.abs(MIN_ARROW_LENGTH / length))
|
||||||
|
if (+(size > 0) !== handleArc.sweepFlag) {
|
||||||
|
mid = PI2 - mid
|
||||||
|
}
|
||||||
|
|
||||||
|
tempB.setTo(getPointOnCircle(handleArc.center.x, handleArc.center.y, handleArc.radius, mid))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,8 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr
|
||||||
startShapeInfo
|
startShapeInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
let minDist = MIN_ARROW_LENGTH
|
let offsetA = 0
|
||||||
|
let offsetB = 0
|
||||||
|
|
||||||
const isSelfIntersection =
|
const isSelfIntersection =
|
||||||
startShapeInfo && endShapeInfo && startShapeInfo.shape === endShapeInfo.shape
|
startShapeInfo && endShapeInfo && startShapeInfo.shape === endShapeInfo.shape
|
||||||
|
@ -66,14 +67,14 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr
|
||||||
// ...and if only the end shape intersected, then make it
|
// ...and if only the end shape intersected, then make it
|
||||||
// a short arrow ending at the end shape intersection.
|
// a short arrow ending at the end shape intersection.
|
||||||
if (startShapeInfo.isClosed) {
|
if (startShapeInfo.isClosed) {
|
||||||
a.setTo(Vec2d.Nudge(b, a, minDist))
|
a.setTo(b.clone().add(uAB.clone().mul(MIN_ARROW_LENGTH)))
|
||||||
}
|
}
|
||||||
} else if (!endShapeInfo.didIntersect) {
|
} else if (!endShapeInfo.didIntersect) {
|
||||||
// ...and if only the end shape intersected, or if neither
|
// ...and if only the end shape intersected, or if neither
|
||||||
// shape intersected, then make it a short arrow starting
|
// shape intersected, then make it a short arrow starting
|
||||||
// at the start shape intersection.
|
// at the start shape intersection.
|
||||||
if (endShapeInfo.isClosed) {
|
if (endShapeInfo.isClosed) {
|
||||||
b.setTo(Vec2d.Nudge(a, b, minDist))
|
b.setTo(a.clone().sub(uAB.clone().mul(MIN_ARROW_LENGTH)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,48 +86,49 @@ export function getStraightArrowInfo(editor: Editor, shape: TLArrowShape): TLArr
|
||||||
// start point has an arrowhead offset the start point
|
// start point has an arrowhead offset the start point
|
||||||
if (!isSelfIntersection) {
|
if (!isSelfIntersection) {
|
||||||
if (startShapeInfo && arrowheadStart !== 'none' && !startShapeInfo.isExact) {
|
if (startShapeInfo && arrowheadStart !== 'none' && !startShapeInfo.isExact) {
|
||||||
const offset =
|
offsetA =
|
||||||
BOUND_ARROW_OFFSET +
|
BOUND_ARROW_OFFSET +
|
||||||
STROKE_SIZES[shape.props.size] / 2 +
|
STROKE_SIZES[shape.props.size] / 2 +
|
||||||
('size' in startShapeInfo.shape.props
|
('size' in startShapeInfo.shape.props
|
||||||
? STROKE_SIZES[startShapeInfo.shape.props.size] / 2
|
? STROKE_SIZES[startShapeInfo.shape.props.size] / 2
|
||||||
: 0)
|
: 0)
|
||||||
|
|
||||||
minDist -= offset
|
|
||||||
a.nudge(b, offset * (didFlip ? -1 : 1))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the arrow is bound non-exact to an end shape and the
|
// If the arrow is bound non-exact to an end shape and the
|
||||||
// end point has an arrowhead offset the end point
|
// end point has an arrowhead offset the end point
|
||||||
if (endShapeInfo && arrowheadEnd !== 'none' && !endShapeInfo.isExact) {
|
if (endShapeInfo && arrowheadEnd !== 'none' && !endShapeInfo.isExact) {
|
||||||
const offset =
|
offsetB =
|
||||||
BOUND_ARROW_OFFSET +
|
BOUND_ARROW_OFFSET +
|
||||||
STROKE_SIZES[shape.props.size] / 2 +
|
STROKE_SIZES[shape.props.size] / 2 +
|
||||||
('size' in endShapeInfo.shape.props ? STROKE_SIZES[endShapeInfo.shape.props.size] / 2 : 0)
|
('size' in endShapeInfo.shape.props ? STROKE_SIZES[endShapeInfo.shape.props.size] / 2 : 0)
|
||||||
|
|
||||||
minDist -= offset
|
|
||||||
b.nudge(a, offset * (didFlip ? -1 : 1))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startShapeInfo && endShapeInfo) {
|
const tA = a.clone().add(u.clone().mul(offsetA * (didFlip ? -1 : 1)))
|
||||||
// If we have two bound shapes...
|
const tB = b.clone().sub(u.clone().mul(offsetB * (didFlip ? -1 : 1)))
|
||||||
if (didFlip) {
|
if (Vec2d.Dist(tA, tB) < MIN_ARROW_LENGTH) {
|
||||||
// If we flipped, then make the arrow a short arrow from
|
if (offsetA !== 0 && offsetB !== 0) {
|
||||||
// the start point towards where the end point should be.
|
offsetA *= -1.5
|
||||||
b.setTo(Vec2d.Add(a, u.mul(-minDist)))
|
offsetB *= -1.5
|
||||||
} else if (Vec2d.Dist(a, b) < MIN_ARROW_LENGTH / 2) {
|
} else if (offsetA !== 0) {
|
||||||
// Otherwise, if the arrow is too short, make it a short
|
offsetA *= -2
|
||||||
// arrow from the start point towards where the end point
|
} else if (offsetB !== 0) {
|
||||||
// should be.
|
offsetB *= -2
|
||||||
b.setTo(Vec2d.Add(a, u.mul(MIN_ARROW_LENGTH / 2)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.add(u.clone().mul(offsetA * (didFlip ? -1 : 1)))
|
||||||
|
b.sub(u.clone().mul(offsetB * (didFlip ? -1 : 1)))
|
||||||
|
|
||||||
// If the handles flipped their order, then set the center handle
|
// If the handles flipped their order, then set the center handle
|
||||||
// to the midpoint of the terminals (rather than the midpoint of the
|
// to the midpoint of the terminals (rather than the midpoint of the
|
||||||
// arrow body); otherwise, it may not be "between" the other terminals.
|
// arrow body); otherwise, it may not be "between" the other terminals.
|
||||||
if (didFlip) {
|
if (didFlip) {
|
||||||
|
if (startShapeInfo && endShapeInfo) {
|
||||||
|
// If we have two bound shapes...then make the arrow a short arrow from
|
||||||
|
// the start point towards where the end point should be.
|
||||||
|
b.setTo(Vec2d.Add(a, u.clone().mul(-MIN_ARROW_LENGTH)))
|
||||||
|
}
|
||||||
c.setTo(Vec2d.Med(terminalsInArrowSpace.start, terminalsInArrowSpace.end))
|
c.setTo(Vec2d.Med(terminalsInArrowSpace.start, terminalsInArrowSpace.end))
|
||||||
} else {
|
} else {
|
||||||
c.setTo(Vec2d.Med(a, b))
|
c.setTo(Vec2d.Med(a, b))
|
||||||
|
|
Ładowanie…
Reference in New Issue