slope property

double? get slope

Returns the slope of the line, using only the first and last coordinate. If the line is vertical, null is returned If the line is horizontal, 0 is returned

Example:

LineString([Coordinate(1, 2), Coordinate(3, 4)]).slope; // 1
LineString([Coordinate(1, 2), Coordinate(3, 2)]).slope; // 0
LineString([Coordinate(1, 2), Coordinate(1, 4)]).slope; // null

Implementation

double? get slope {
  if (coordinates.first.x == coordinates.last.x) {
    return null;
  }
  return (coordinates.last.y - coordinates.first.y) /
      (coordinates.last.x - coordinates.first.x);
}