コード例 #1
0
ファイル: Site.cs プロジェクト: QLwin/Polygon-Map-Generation
        public static void SortSites(List <Site> sites)
        {
            sites.Sort(delegate(Site s0, Site s1) {
                int returnValue = Voronoi.CompareByYThenX(s0, s1);

                int tempIndex;

                if (returnValue == -1)
                {
                    if (s0.siteIndex > s1.SiteIndex)
                    {
                        tempIndex    = s0.SiteIndex;
                        s0.SiteIndex = s1.SiteIndex;
                        s1.SiteIndex = tempIndex;
                    }
                }
                else if (returnValue == 1)
                {
                    if (s1.SiteIndex > s0.SiteIndex)
                    {
                        tempIndex    = s1.SiteIndex;
                        s1.SiteIndex = s0.SiteIndex;
                        s0.SiteIndex = tempIndex;
                    }
                }

                return(returnValue);
            });
        }
コード例 #2
0
ファイル: Site.cs プロジェクト: HelpOrMe/HereWeSettleDown
        public int CompareTo(Site s1)
        {
            int returnValue = Voronoi.CompareByYThenX(this, s1);

            int tempIndex;

            if (returnValue == -1)
            {
                if (this.SiteIndex > s1.SiteIndex)
                {
                    tempIndex      = this.SiteIndex;
                    this.SiteIndex = s1.SiteIndex;
                    s1.SiteIndex   = tempIndex;
                }
            }
            else if (returnValue == 1)
            {
                if (s1.SiteIndex > this.SiteIndex)
                {
                    tempIndex      = s1.SiteIndex;
                    s1.SiteIndex   = this.SiteIndex;
                    this.SiteIndex = tempIndex;
                }
            }

            return(returnValue);
        }
コード例 #3
0
ファイル: Vertex.cs プロジェクト: Deus0/Zeltex-v2
        /*
         * This is the only way to make a Vertex
         *
         * @param halfedge0
         * @param halfedge1
         * @return
         *
         */
        public static Vertex Intersect(Halfedge halfedge0, Halfedge halfedge1)
        {
            Edge     edge, edge0, edge1;
            Halfedge halfedge;
            float    determinant, intersectionX, intersectionY;
            bool     rightOfSite;

            edge0 = halfedge0.edge;
            edge1 = halfedge1.edge;
            if (edge0 == null || edge1 == null)
            {
                return(null);
            }
            if (edge0.RightSite == edge1.RightSite)
            {
                return(null);
            }

            determinant = edge0.a * edge1.b - edge0.b * edge1.a;
            if (Math.Pow(-1.0, 10) < determinant && determinant < Math.Pow(1.0, -10))
            {
                // The edges are parallel
                return(null);
            }

            intersectionX = (edge0.c * edge1.b - edge1.c * edge0.b) / determinant;
            intersectionY = (edge1.c * edge0.a - edge0.c * edge1.a) / determinant;

            if (Voronoi.CompareByYThenX(edge0.RightSite, edge1.RightSite) < 0)
            {
                halfedge = halfedge0;
                edge     = edge0;
            }
            else
            {
                halfedge = halfedge1;
                edge     = edge1;
            }
            rightOfSite = intersectionX >= edge.RightSite.x;
            if ((rightOfSite && halfedge.leftRight == LR.LEFT) ||
                (!rightOfSite && halfedge.leftRight == LR.RIGHT))
            {
                return(null);
            }

            return(Vertex.Create(intersectionX, intersectionY));
        }