/// <summary> /// TODO summary. /// </summary> public static __tpolygon__ ConvexClipped( this __tpolygon__ polygon, __tbox__ box, double eps = 1e-8) { var __plane__s = new[] { //# Meta.VecFields.Take(d).ForEach(axis => { new __tplane__(__tvec__.__axis__Axis, box.Min), new __tplane__(-__tvec__.__axis__Axis, box.Max), //# }); }; return(polygon.ConvexClipped(__plane__s)); }
/// <summary> /// Returns the convex polygon clipped by the set of __plane__s (defined /// as __tplane__s), i.e. all parts of the polygon that are at the positive /// side of the __plane__s. /// </summary> public static __tpolygon__ ConvexClipped( this __tpolygon__ polygon, __tplane__[] __plane__s, double eps = 1e-8) { foreach (var c in __plane__s) { polygon = polygon.ConvexClipped(c, eps); if (polygon.PointCount == 0) { break; } } return(polygon); }
public static bool ApproximateEquals(this __tpolygon__ a, __tpolygon__ b, double tolerance) { if (a.m_pointCount != b.m_pointCount) { return(false); } for (int pi = 0; pi < a.m_pointCount; pi++) { if (!ApproximateEquals(a.m_pointArray[pi], b.m_pointArray[pi], tolerance)) { return(false); } } return(true); }
public bool Equals(__tpolygon__ other) { if (m_pointCount != other.m_pointCount) { return(false); } for (int pi = 0; pi < m_pointCount; pi++) { if (!m_pointArray[pi].Equals(other.m_pointArray[pi])) { return(false); } } return(true); }
public static __tpolygon__ WithoutMultiplePoints( this __tpolygon__ polygon, double eps = 1e-8) { eps *= eps; var opc = polygon.PointCount; var pa = new __tvec__[opc]; var pc = 0; pa[0] = polygon[0]; for (int pi = 1; pi < opc; pi++) { if (__tvec__.DistanceSquared(pa[pc], polygon[pi]) > eps) { pa[++pc] = polygon[pi]; } } if (__tvec__.DistanceSquared(pa[pc], polygon[0]) > eps) { ++pc; } return(new __tpolygon__(pa, pc)); }
/// <summary> /// Clip the supplied polygon at the supplied __plane__. The method should /// work with all non-selfintersecting polygons. Returns all parts of /// the polygon that are at the positive side of the __plane__. /// </summary> public static __tpolygon__ ConvexClipped( this __tpolygon__ polygon, __tplane__ __plane__, double eps = 1e-8) { var opc = polygon.PointCount; __tvec__[] pa = new __tvec__[opc + 1]; var pc = 0; var pf = polygon[0]; var hf = __plane__.Height(pf); bool hfp = hf > eps, hfn = hf < -eps; if (hf >= -eps) { pa[pc++] = pf; } var p0 = pf; var h0 = hf; var h0p = hfp; var h0n = hfn; for (int vi = 1; vi < opc; vi++) { var p1 = polygon[vi]; var h1 = __plane__.Height(p1); bool h1p = h1 > eps, h1n = h1 < -eps; if (h0p && h1n || h0n && h1p) { pa[pc++] = p0 + (p1 - p0) * (h0 / (h0 - h1)); } if (h1 >= -eps) { pa[pc++] = p1; } p0 = p1; h0 = h1; h0p = h1p; h0n = h1n; } if (h0p && hfn || h0n && hfp) { pa[pc++] = p0 + (pf - p0) * (h0 / (h0 - hf)); } return(new __tpolygon__(pa, pc)); }
/// <summary> /// Returns the polygon clipped by the hull, i.e. all parts of the /// polygon that are at the positive side of the hull __plane__s. /// </summary> public static __tpolygon__ ConvexClipped( this __tpolygon__ polygon, __thull__ hull, double eps = 1e-8) { return(polygon.ConvexClipped(hull.PlaneArray, eps)); }
public static __tpolygon__ Transformed( this __tpolygon__ polygon, __tmat1__ m) { return(polygon.Map(p => m.TransformPos(p))); }
public static __tpolygon__ ScaledAboutVertexCentroid( this __tpolygon__ polygon, __tvec__ scale) { return(polygon.Scaled(polygon.ComputeVertexCentroid(), scale)); }
public static __tpolygon__ Scaled( this __tpolygon__ polygon, __tvec__ center, __tvec__ scale) { return(polygon.Map(p => center + (p - center) * scale)); }
public static __tpolygon__ Scaled( this __tpolygon__ polygon, __tvec__ scale) { return(polygon.Map(p => p * scale)); }
/// <summary> /// Copy constructor. /// Performs deep copy of original. /// </summary> public __tpolygon__(__tpolygon__ original) : this(original.GetPointArray()) { }
public static bool ApproximateEquals(this __tpolygon__ a, __tpolygon__ b) => ApproximateEquals(a, b, Constant <double> .PositiveTinyValue);