isParallelTo method

bool isParallelTo(
  1. LineString other
)

Returns whether or not the LineString is parallel to the LineString other. If the LineStrings have different lengths, they are not considered parallel.

Example:

LineString([Coordinate(1, 2), Coordinate(3, 4)]).isParallelTo(LineString([Coordinate(2, 3), Coordinate(4, 5)])); // true
LineString([Coordinate(1, 2), Coordinate(3, 4)]).isParallelTo(LineString([Coordinate(4, 5), Coordinate(2, 3)])); // true
LineString([Coordinate(1, 2), Coordinate(3, 4)]).isParallelTo(LineString([Coordinate(4, 5), Coordinate(2, 6)])); // false

Implementation

bool isParallelTo(LineString other) {
  if (coordinates.length != other.coordinates.length) {
    return false;
  } else if (coordinates.length == 2) {
    return bearing == other.bearing;
  } else {
    return segments.every((LineString element) {
      int index = segments.indexOf(element);

      return element.bearing == other.segments[index].bearing ||
          element.bearing == other.reverse().segments[index].bearing;
    });
  }
}