Edge.sameRadiusDirectTangent constructor

Edge.sameRadiusDirectTangent(
  1. Corner prev,
  2. Corner current
)

Implementation

factory Edge.sameRadiusDirectTangent(Corner prev, Corner current) {
  assert(prev.circle.radius == current.circle.radius,
      'This constructor is for corner with same border radius, use [Edge.fromTangent] constructor instead.');
  final clockwise = current.clockwise;

  final centerLine =
      Line.fromTwoPoints((prev.circle.center, current.circle.center));

  final perpLineFirst = centerLine.perpendicular(prev.circle.center);
  final perpLineSecond = centerLine.perpendicular(current.circle.center);

  final firstCoords = perpLineFirst.pointsOnLineFromPoint(
      prev.circle.center, prev.circle.radius);
  final secondCoords = perpLineSecond.pointsOnLineFromPoint(
      current.circle.center, current.circle.radius);

  for (final (first, second) in [
    (firstCoords.$1, secondCoords.$1),
    (firstCoords.$2, secondCoords.$2)
  ]) {
    //Checking if according to the direction tangent is correct.
    if (areCorrectPoints(first, second, current.circle.center, clockwise)) {
      return Edge(first, second);
    }
  }

  throw PlatformException(
    code: 'NO_CORRECT_TANGENTS',
    details: 'No correct tangent found between the given two corners.',
  );
}