middleInside function

bool middleInside(
  1. Node a,
  2. Node b
)

Implementation

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

  return inside;
}