Skip to content

Commit

Permalink
util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rms80 committed Apr 25, 2018
1 parent bd31d7d commit 2c69ccb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions curve/CurveUtils2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,36 @@ public static void LaplacianSmoothConstrained(GeneralPolygon2d solid, double alp



/// <summary>
/// return list of objects for which keepF(obj) returns true
/// </summary>
public static List<T> Filter<T>(List<T> objects, Func<T, bool> keepF)
{
List<T> result = new List<T>(objects.Count);
foreach (var obj in objects) {
if (keepF(obj))
result.Add(obj);
}
return result;
}


/// <summary>
/// Split the input list into two new lists, based on predicate (set1 == true)
/// </summary>
public static void Split<T>(List<T> objects, out List<T> set1, out List<T> set2, Func<T, bool> splitF)
{
set1 = new List<T>();
set2 = new List<T>();
foreach (var obj in objects) {
if (splitF(obj))
set1.Add(obj);
else
set2.Add(obj);
}
}



/// <summary>
/// Remove polygons and polygon-holes smaller than minArea
Expand Down
11 changes: 11 additions & 0 deletions curve/Polygon2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,17 @@ public void Chamfer(double chamfer_dist, double minConvexAngleDeg = 30, double m



/// <summary>
/// Return minimal bounding box of vertices, computed to epsilon tolerance
/// </summary>
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);
Expand Down

0 comments on commit 2c69ccb

Please sign in to comment.