From 2c69ccbc2a2bd9a4bf590aa48e01e6d249323c21 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Tue, 24 Apr 2018 20:45:55 -0400 Subject: [PATCH] util functions --- curve/CurveUtils2.cs | 30 ++++++++++++++++++++++++++++++ curve/Polygon2d.cs | 11 +++++++++++ 2 files changed, 41 insertions(+) diff --git a/curve/CurveUtils2.cs b/curve/CurveUtils2.cs index a3abec8c..de6729c0 100644 --- a/curve/CurveUtils2.cs +++ b/curve/CurveUtils2.cs @@ -215,6 +215,36 @@ public static void LaplacianSmoothConstrained(GeneralPolygon2d solid, double alp + /// + /// return list of objects for which keepF(obj) returns true + /// + public static List Filter(List objects, Func keepF) + { + List result = new List(objects.Count); + foreach (var obj in objects) { + if (keepF(obj)) + result.Add(obj); + } + return result; + } + + + /// + /// Split the input list into two new lists, based on predicate (set1 == true) + /// + public static void Split(List objects, out List set1, out List set2, Func splitF) + { + set1 = new List(); + set2 = new List(); + foreach (var obj in objects) { + if (splitF(obj)) + set1.Add(obj); + else + set2.Add(obj); + } + } + + /// /// Remove polygons and polygon-holes smaller than minArea diff --git a/curve/Polygon2d.cs b/curve/Polygon2d.cs index f938c31b..7bf37970 100644 --- a/curve/Polygon2d.cs +++ b/curve/Polygon2d.cs @@ -709,6 +709,17 @@ public void Chamfer(double chamfer_dist, double minConvexAngleDeg = 30, double m + /// + /// Return minimal bounding box of vertices, computed to epsilon tolerance + /// + public Box2d MinimalBoundingBox(double epsilon) + { + ContMinBox2 box2 = new ContMinBox2(vertices, epsilon, QueryNumberType.QT_DOUBLE, false); + return box2.MinBox; + } + + + static public Polygon2d MakeRectangle(Vector2d center, double width, double height) { VectorArray2d vertices = new VectorArray2d(4);