isPointOnLineSegmentCrossesVariant function

bool isPointOnLineSegmentCrossesVariant(
  1. Position start,
  2. Position end,
  3. Position pt,
  4. bool incEnd,
)

Only takes into account outer rings See http://stackoverflow.com/a/4833823/1979085 lineSegmentStart Position of start of line lineSegmentEnd Position of end of line pt Position of point to check incEnd controls whether the Point is allowed to fall on the line ends

Implementation

bool isPointOnLineSegmentCrossesVariant(
  Position start,
  Position end,
  Position pt,
  bool incEnd,
) {
  var dxc = pt[0]! - start[0]!;
  var dyc = pt[1]! - start[1]!;
  var dxl = end[0]! - start[0]!;
  var dyl = end[1]! - start[1]!;
  var cross = dxc * dyl - dyc * dxl;
  if (cross != 0) {
    return false;
  }
  if (incEnd) {
    if ((dxl).abs() >= (dyl).abs()) {
      return dxl > 0
          ? start[0]! <= pt[0]! && pt[0]! <= end[0]!
          : end[0]! <= pt[0]! && pt[0]! <= start[0]!;
    }
    return dyl > 0
        ? start[1]! <= pt[1]! && pt[1]! <= end[1]!
        : end[1]! <= pt[1]! && pt[1]! <= start[1]!;
  } else {
    if ((dxl).abs() >= (dyl).abs()) {
      return dxl > 0
          ? start[0]! < pt[0]! && pt[0]! < end[0]!
          : end[0]! < pt[0]! && pt[0]! < start[0]!;
    }
    return dyl > 0
        ? start[1]! < pt[1]! && pt[1]! < end[1]!
        : end[1]! < pt[1]! && pt[1]! < start[1]!;
  }
}