当前位置: 首页>>代码示例>>C#>>正文


C# Polygon.RemoveRange方法代码示例

本文整理汇总了C#中Polygon.RemoveRange方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.RemoveRange方法的具体用法?C# Polygon.RemoveRange怎么用?C# Polygon.RemoveRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon的用法示例。


在下文中一共展示了Polygon.RemoveRange方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CleanPolygon

        //------------------------------------------------------------------------------

        public static Polygon CleanPolygon(Polygon poly,
            double delta = 1.415)
        {
            //delta = proximity in units/pixels below which vertices
            //will be stripped. Default ~= sqrt(2) so when adjacent 
            //vertices have both x & y coords within 1 unit, then 
            //the second vertex will be stripped. 
            int len = poly.Count;
            if (len < 3) return null;
            Polygon result = new Polygon(poly);
            int d = (int)(delta * delta);
            IntPoint p = poly[0];
            int j = 1;
            for (int i = 1; i < len; i++)
            {
                if ((poly[i].X - p.X) * (poly[i].X - p.X) +
                    (poly[i].Y - p.Y) * (poly[i].Y - p.Y) <= d)
                    continue;
                result[j] = poly[i];
                p = poly[i];
                j++;
            }
            p = poly[j - 1];
            if ((poly[0].X - p.X) * (poly[0].X - p.X) +
                (poly[0].Y - p.Y) * (poly[0].Y - p.Y) <= d)
                j--;
            if (j < len)
                result.RemoveRange(j, len - j);
            return result;
        }
开发者ID:caomw,项目名称:elementdiscovery,代码行数:32,代码来源:clipper.cs

示例2: GetPathsWithOverlapsRemoved

		public Polygons GetPathsWithOverlapsRemoved(Polygon perimeter, int overlapMergeAmount_um)
		{
			// make a copy that has every point duplicatiod (so that we have them as segments).
			Polygon polySegments = new Polygon(perimeter.Count * 2);
			for (int i = 0; i < perimeter.Count - 1; i++)
			{
				IntPoint point = perimeter[i];
				IntPoint nextPoint = perimeter[i + 1];

				polySegments.Add(point);
				polySegments.Add(nextPoint);
			}

			Altered[] markedAltered = new Altered[polySegments.Count/2];

			int segmentCount = polySegments.Count / 2;
			// now walk every segment and check if there is another segment that is similar enough to merge them together
			for (int firstSegmentIndex = 0; firstSegmentIndex < segmentCount; firstSegmentIndex++)
			{
				int firstPointIndex = firstSegmentIndex * 2;
				for (int checkSegmentIndex = firstSegmentIndex + 1; checkSegmentIndex < segmentCount; checkSegmentIndex++)
				{
					int checkPointIndex = checkSegmentIndex * 2;
					// The first point of start and the last point of check (the path will be coming back on itself).
					long startDelta = (polySegments[firstPointIndex] - polySegments[checkPointIndex + 1]).Length();
					// if the segmets are similar enough
					if (startDelta < overlapMergeAmount_um)
					{
						// The last point of start and the first point of check (the path will be coming back on itself).
						long endDelta = (polySegments[firstPointIndex + 1] - polySegments[checkPointIndex]).Length();
						if (endDelta < overlapMergeAmount_um)
						{
							// move the first segments points to the average of the merge positions
							polySegments[firstPointIndex] = (polySegments[firstPointIndex] + polySegments[checkPointIndex + 1]) / 2; // the start
							polySegments[firstPointIndex + 1] = (polySegments[firstPointIndex + 1] + polySegments[checkPointIndex]) / 2; // the end

							markedAltered[firstSegmentIndex] = Altered.merged;
							// mark this segment for removal
							markedAltered[checkSegmentIndex] = Altered.remove;
							// We only expect to find one match for each segment, so move on to the next segment
							break;
						}
					}
				}
			}

			// Check for perimeter edeges that need to be removed that are the u turns of sectons that go back on themselves.
			//  __________
			// |__________|	->  |--------|  the 2 vertical sections should be removed
			for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
			{
				int prevSegmentIndex = (int)((uint)(segmentIndex - 1) % (uint)segmentCount);
				int nextSegmentIndex = (segmentIndex + 1) % segmentCount;
				if ((markedAltered[nextSegmentIndex] == Altered.merged && markedAltered[prevSegmentIndex] == Altered.remove)
					|| (markedAltered[nextSegmentIndex] == Altered.remove && markedAltered[prevSegmentIndex] == Altered.merged))
				{
					markedAltered[segmentIndex] = Altered.remove;
				}
			}

			// remove the marked segments
			for (int segmentIndex = segmentCount - 1; segmentIndex >= 0; segmentIndex--)
			{
				int pointIndex = segmentIndex * 2;
				if (markedAltered[segmentIndex] == Altered.remove)
				{
					polySegments.RemoveRange(pointIndex, 2);
				}
			}

			// go through the polySegmets and create a new polygon for every connected set of segmets
			Polygons separatedPolygons = new Polygons();
			Polygon currentPolygon = new Polygon();
			separatedPolygons.Add(currentPolygon);
			// put in the first point
			for (int segmentIndex = 0; segmentIndex < polySegments.Count; segmentIndex += 2)
			{
				// add the start point
				currentPolygon.Add(polySegments[segmentIndex]);

				// if the next segment is not connected to this one
				if (segmentIndex < polySegments.Count - 2
					&& polySegments[segmentIndex + 1] != polySegments[segmentIndex + 2])
				{
					// add the end point
					currentPolygon.Add(polySegments[segmentIndex + 1]);

					// create a new polygon
					currentPolygon = new Polygon();
					separatedPolygons.Add(currentPolygon);
				}
			}

			// add the end point
			currentPolygon.Add(polySegments[polySegments.Count - 1]);

			return separatedPolygons;
		}
开发者ID:broettge,项目名称:MatterSlice,代码行数:98,代码来源:GCodePlanner.cs


注:本文中的Polygon.RemoveRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。