discontinuedPackage jet_cad_floor_plan has been discontinued and replaced by jet_cad_2d_plan.

isSimpleCcw function

bool isSimpleCcw(
  1. List<Vector2> ring
)

Exact, like the triangulator: the signed area is positive and no two non-adjacent edges properly cross (spec 07 D6's invariant).

Implementation

bool isSimpleCcw(List<Vector2> ring) {
  final n = ring.length;
  if (!(signedArea(ring) > 0)) return false;
  double cross(Vector2 a, Vector2 b, Vector2 d) =>
      (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
  bool crosses(Vector2 a, Vector2 b, Vector2 d, Vector2 e) {
    final d1 = cross(d, e, a), d2 = cross(d, e, b);
    final d3 = cross(a, b, d), d4 = cross(a, b, e);
    return ((d1 > 0 && d2 < 0) || (d1 < 0 && d2 > 0)) &&
        ((d3 > 0 && d4 < 0) || (d3 < 0 && d4 > 0));
  }

  for (var i = 0; i < n; i++) {
    for (var j = i + 2; j < n; j++) {
      if (i == 0 && j == n - 1) continue;
      if (crosses(ring[i], ring[(i + 1) % n], ring[j], ring[(j + 1) % n])) {
        return false;
      }
    }
  }
  return true;
}