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


C# IEnvelope.Center方法代码示例

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


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

示例1: HandleBoundaries

        /// <summary>
        /// The original algorithm simply allows edges that have one defined point and 
        /// another "NAN" point.  Simply excluding the not a number coordinates fails
        /// to preserve the known direction of the ray.  We only need to extend this
        /// long enough to encounter the bounding box, not infinity.
        /// </summary>
        /// <param name="graph">The VoronoiGraph with the edge list</param>
        /// <param name="bounds">The polygon bounding the datapoints</param>
        private static void HandleBoundaries(VoronoiGraph graph, IEnvelope bounds)
        {
            
            List<ILineString> boundSegments = new List<ILineString>();
            List<VoronoiEdge> unboundEdges = new List<VoronoiEdge>();
            // Identify bound edges for intersection testing
            foreach (VoronoiEdge edge in graph.Edges)
            {
                if(edge.VVertexA.ContainsNan() || edge.VVertexB.ContainsNan())
                {
                    unboundEdges.Add(edge);
                    continue;
                }
                boundSegments.Add(new LineString(new List<Coordinate>{edge.VVertexA.ToCoordinate(), edge.VVertexB.ToCoordinate()}));
            }

            // calculate a length to extend a ray to look for intersections
            IEnvelope env = bounds;
            double h = env.Height;
            double w = env.Width;
            double len = Math.Sqrt(w * w + h * h);  // len is now long enough to pass entirely through the dataset no matter where it starts

            foreach (VoronoiEdge edge in unboundEdges)
            {
                // the unbound line passes thorugh start
                Coordinate start = (edge.VVertexB.ContainsNan())
                                        ? edge.VVertexA.ToCoordinate()
                                        : edge.VVertexB.ToCoordinate();

                // the unbound line should have a direction normal to the line joining the left and right source points
                double dx = edge.LeftData.X - edge.RightData.X;
                double dy = edge.LeftData.Y - edge.RightData.Y;
                double l = Math.Sqrt(dx*dx + dy*dy);

                

                // the slope of the bisector between left and right
                double sx = -dy/l;
                double sy = dx/l;

                Coordinate center = bounds.Center();
                if((start.X > center.X && start.Y > center.Y) || (start.X < center.X && start.Y < center.Y))
                {
                    sx = dy/l;
                    sy = -dx/l;
                }

                Coordinate end1 = new Coordinate(start.X + len*sx, start.Y + len * sy);
                Coordinate end2 = new Coordinate(start.X - sx * len, start.Y - sy * len);
                
                Coordinate end = (end1.Distance(center) < end2.Distance(center)) ? end2 : end1;
                if(bounds.Contains(end))
                {
                    end = new Coordinate(start.X - sx * len, start.Y - sy * len);
                }
                if (edge.VVertexA.ContainsNan())
                {
                    edge.VVertexA = new Vector2(end.ToArray());
                }
                else
                {
                    edge.VVertexB = new Vector2(end.ToArray());
                }
                
                
                
                
            }
            
        }
开发者ID:zhongshuiyuan,项目名称:mapwindowsix,代码行数:78,代码来源:Voronoi.cs


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