middleInside function

dynamic middleInside(
  1. dynamic a,
  2. dynamic b
)

Implementation

middleInside(a, b) {
  var p = a;
  bool inside = false;
  var px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;
  do {
    if (((p.y > py) != (p.next.y > py)) &&
        p.next.y != p.y &&
        (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x)) {
      inside = !inside;
    }
    p = p.next;
  } while (p != a);

  return inside;
}