boundaryToward method
Implementation
@override
DiagramPoint boundaryToward(DiagramPoint target) {
final center = bounds.center;
final delta = target - center;
if (delta.x == 0 && delta.y == 0) return center;
final xScale = delta.x == 0
? double.infinity
: bounds.width / 2 / delta.x.abs();
final yScale = delta.y == 0
? double.infinity
: bounds.height / 2 / delta.y.abs();
final rectangularHit = center + delta * math.min(xScale, yScale);
final radius = effectiveCornerRadius;
if (radius == 0 ||
(rectangularHit.x >= bounds.left + radius &&
rectangularHit.x <= bounds.right - radius) ||
(rectangularHit.y >= bounds.top + radius &&
rectangularHit.y <= bounds.bottom - radius)) {
return rectangularHit;
}
// Only a corner arc can exclude a point on the rectangular perimeter.
// Intersect the center ray with that corner's circle, taking the far root:
// the near root belongs to the interior, outside the corner's quadrant.
final corner = DiagramPoint(
rectangularHit.x < center.x
? bounds.left + radius
: bounds.right - radius,
rectangularHit.y < center.y
? bounds.top + radius
: bounds.bottom - radius,
);
final ray = rectangularHit - center;
final direction = ray * (1 / ray.magnitude);
final offset = corner - center;
final along = offset.x * direction.x + offset.y * direction.y;
final across = offset.x * direction.y - offset.y * direction.x;
final distance =
along + math.sqrt(math.max(0, radius * radius - across * across));
return center + direction * distance;
}