public static bool AreDuplicateEntities(List <Point3d> source, List <Point3d> target) { if (source == null || source.Count == 0 || target == null || target.Count == 0) { return(false); } // 如果他们坐标完全一样,那么认为他们是相同的,无需再用clipperlib if (AreIdenticalCoordinates(source, target.ToList())) { return(true); } // 有时候坐标太大,导致计算结果不正确,所以移到原点去计算 var vector = Point3d.Origin - source[0]; source = source.Select(it => it + vector).ToList(); target = target.Select(it => it + vector).ToList(); // Use clipper to calculate the intersection var precision = 0.0001; // 精度不能太大,否则结果出错 var subject = new List <List <IntPoint> >(1); var clipper = new List <List <IntPoint> >(1); var result = new List <List <IntPoint> >(); // 用Math.Rount解决精度带来的影响。 var subjectPath = source.Select(it => new IntPoint(Math.Round(it.X / precision), Math.Round(it.Y / precision))).ToList(); subject.Add(subjectPath); var clipperPath = target.Select(it => new IntPoint(Math.Round(it.X / precision), Math.Round(it.Y / precision))).ToList(); clipper.Add(clipperPath); var cpr = new Clipper(); cpr.AddPaths(subject, PolyType.ptSubject, true); cpr.AddPaths(clipper, PolyType.ptClip, true); // 相同为0,相异为1 cpr.Execute(ClipType.ctXor, result, PolyFillType.pftNonZero, PolyFillType.pftNonZero); if (result.Count == 0) { return(true); } foreach (var path in result) { var points = path.Select(it => new Point3d(it.X * precision, it.Y * precision, 0.0)).ToArray(); var polyline = CurveUtils.CreatePolygon(points); // If the polygon's area is very small, just ignore, or it will bother user. if (polyline.Area.Larger(0.001)) { polyline.Dispose(); return(false); } polyline.Dispose(); } return(true); }