OSDN Git Service

data write directory change. shapely library include.
[openembroidery/EmbroideryOutputExtensionForInkscape.git] / embroider / shapely / algorithms / cga.py
diff --git a/embroider/shapely/algorithms/cga.py b/embroider/shapely/algorithms/cga.py
new file mode 100644 (file)
index 0000000..3b8d925
--- /dev/null
@@ -0,0 +1,16 @@
+
+def signed_area(ring):
+    """Return the signed area enclosed by a ring in linear time using the 
+    algorithm at: http://www.cgafaq.info/wiki/Polygon_Area.
+    """
+    xs, ys = ring.coords.xy
+    xs.append(xs[1])
+    ys.append(ys[1])
+    return sum(xs[i]*(ys[i+1]-ys[i-1]) for i in range(1, len(ring.coords)))/2.0
+
+def is_ccw_impl(name):
+    """Predicate implementation"""
+    def is_ccw_op(ring):
+        return signed_area(ring) >= 0.0
+    return is_ccw_op
+