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


C# Polygon.Simplify方法代码示例

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


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

示例1: AddLineSegment

    public void AddLineSegment(List<PolygonPoint> segment)
    {
        if (segment.Count < 2)
            return; //can't add a single point.

        //if both the start and end match, then we're bridging two together.
        if (PolygonSegmentsByEnd.ContainsKey(segment[0]) && PolygonSegmentsByStart.ContainsKey(segment[segment.Count - 1]))
        {
            //get the segment that this one completes.
            var startSegment = PolygonSegmentsByEnd[segment[0]];
            var endSegment = PolygonSegmentsByStart[segment[segment.Count - 1]];
            //remove both from both collections.
            PolygonSegmentsByEnd.Remove(segment[0]);
            PolygonSegmentsByStart.Remove(segment[segment.Count - 1]);

            if (startSegment == endSegment) // We're completing a closed polygon.
            {
                //remove the shared point between both
                startSegment.RemoveAt(startSegment.Count - 1);
                //join them together
                startSegment.AddRange(segment);
                //remove one of the now same two points that are at either ends.
                startSegment.RemoveAt(startSegment.Count - 1);
                Polygon newPoly = new Polygon(startSegment);
                newPoly.Simplify();
                InsertIntoSet(CompletedPolygons, newPoly);
            }
            else
            {
                //remove the shared point between both
                startSegment.RemoveAt(startSegment.Count - 1);
                //join them together
                startSegment.AddRange(segment);
                //remove one of the now same two points that are at either ends.
                startSegment.RemoveAt(startSegment.Count - 1);
                //join them together
                startSegment.AddRange(endSegment);

                PolygonSegmentsByEnd[startSegment[startSegment.Count - 1]] = startSegment;
                PolygonSegmentsByStart[startSegment[0]] = startSegment;
            }
        }
        //If we have a segment who's end matches our beginning, we join them.
        else if (PolygonSegmentsByEnd.ContainsKey(segment[0]))
        {
            //get the segment we need to join to
            var oldSegment = PolygonSegmentsByEnd[segment[0]];

            //Remove the old segment from that list.
            //It will need a new address.
            PolygonSegmentsByEnd.Remove(segment[0]);

            //remove the last point from the old segment,
            //because it's the same as the first point from the new one.
            oldSegment.RemoveAt(oldSegment.Count - 1);

            //now join them together.
            oldSegment.AddRange(segment);

            //finally add the newly joined segment to the list of ends.
            PolygonSegmentsByEnd[oldSegment[oldSegment.Count - 1]] = oldSegment;

            //The other list doesn't need changeing because we keep the start point.
        }
        //likewise, if we have a segment who's beginning matches our end.
        else if (PolygonSegmentsByStart.ContainsKey(segment[segment.Count - 1]))
        {
            var oldSegment = PolygonSegmentsByStart[segment[segment.Count - 1]];
            PolygonSegmentsByStart.Remove(segment[segment.Count - 1]);
            segment.RemoveAt(segment.Count - 1);
            oldSegment.InsertRange(0, segment);
            PolygonSegmentsByStart[oldSegment[0]] = oldSegment;
        }
        //finally, if there's no existing connection, just add it to both lists.
        else
        {
            PolygonSegmentsByStart[segment[0]] = segment;
            PolygonSegmentsByEnd[segment[segment.Count - 1]] = segment;
        }
    }
开发者ID:JapaMala,项目名称:armok-vision,代码行数:80,代码来源:ComplexPoly.cs

示例2: getPolygonBuffer

        private static Polygon getPolygonBuffer(Polygon polygon, double distance, int pointsPerCircle, bool allowParallels)
        {
            polygon = (Polygon)polygon.Clone();
            polygon.Weed(distance - distance * Math.Cos(Math.PI / pointsPerCircle));
            polygon.Simplify();

            Polygon boundaryBuffer = getBoundsBuffer(polygon, distance, pointsPerCircle, allowParallels);

            ICollection<IGeometry> result;
            if (distance > 0)
                result = polygon.Union(boundaryBuffer);
            else
                result = polygon.Difference(boundaryBuffer);

            foreach (IGeometry g in result)
                if (g is Polygon)
                    return (Polygon)g;

            return new Polygon();
        }
开发者ID:gkrsu,项目名称:maparound.core,代码行数:20,代码来源:Buffer.cs


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