resolveOutline method

ResolvedOutline resolveOutline(
  1. DiagramRect target,
  2. DiagramPortShapeRegistry shapes, {
  3. double inset = 0,
})

The marker contour placed on target, oriented by the outward normal. A positive inset shrinks it toward its centre for the connected fill.

Implementation

ResolvedOutline resolveOutline(
  DiagramRect target,
  DiagramPortShapeRegistry shapes, {
  double inset = 0,
}) {
  final definition = shapes.require(style.shape);
  final declared = outwardNormal;
  final length = declared.magnitude;
  final normal = length <= 1e-9
      ? const DiagramPoint(0, -1)
      : declared * (1 / length);
  final tangent = DiagramPoint(-normal.y, normal.x);
  final anchor = resolveCenter(target);
  var points = [
    for (final p in definition.contour)
      anchor +
          tangent * ((p.x - .5) * style.width) +
          normal * ((p.y - definition.anchorDepth) * style.height),
  ];
  if (inset > 0) {
    final extent = DiagramRect.fromPoints(points);
    final center = extent.center;
    final scale = math.max(
      .05,
      1 - 2 * inset / math.min(style.width, style.height),
    );
    points = [for (final p in points) center + (p - center) * scale];
  }
  return PolygonOutline(DiagramRect.fromPoints(points), points);
}