public static __tvec__[] GetPointArray(this __type__ __name__) { var pa = new __tvec__[__pc__]; //# pc.ForEach(i => { pa[__i__] = __name__.P__i__; //# }); return(pa); }
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)); }
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)); }