/** * sort sites on y, then x, coord * also change each site's _siteIndex to match its new position in the list * so the _siteIndex can be used to identify the site for nearest-neighbor queries * * haha "also" - means more than one responsibility... * */ public int CompareTo(System.Object obj) // XXX: Really, really worried about this because it depends on how sorting works in AS3 impl - Julian { Site s2 = (Site)obj; int returnValue = Voronoi.CompareByYThenX(this, s2); // swap _siteIndex values if necessary to match new ordering: uint tempIndex; if (returnValue == -1) { if (this._siteIndex > s2._siteIndex) { tempIndex = this._siteIndex; this._siteIndex = s2._siteIndex; s2._siteIndex = tempIndex; } } else if (returnValue == 1) { if (s2._siteIndex > this._siteIndex) { tempIndex = s2._siteIndex; s2._siteIndex = this._siteIndex; this._siteIndex = tempIndex; } } return(returnValue); }
public int CompareTo(object obj) { Site site = (Site)obj; int num = Voronoi.CompareByYThenX(this, site); switch (num) { case -1: if (_siteIndex > site._siteIndex) { uint siteIndex = _siteIndex; _siteIndex = site._siteIndex; site._siteIndex = siteIndex; } break; case 1: if (site._siteIndex > _siteIndex) { uint siteIndex = site._siteIndex; site._siteIndex = _siteIndex; _siteIndex = siteIndex; } break; } return(num); }
public static Vertex Intersect(Halfedge halfedge0, Halfedge halfedge1) { Edge edge = halfedge0.edge; Edge edge2 = halfedge1.edge; if (edge == null || edge2 == null) { return(null); } if (edge.rightSite == edge2.rightSite) { return(null); } float num = edge.a * edge2.b - edge.b * edge2.a; if (-1E-10 < (double)num && (double)num < 1E-10) { return(null); } float num2 = (edge.c * edge2.b - edge2.c * edge.b) / num; float y = (edge2.c * edge.a - edge.c * edge2.a) / num; Halfedge halfedge2; Edge edge3; if (Voronoi.CompareByYThenX(edge.rightSite, edge2.rightSite) < 0) { halfedge2 = halfedge0; edge3 = edge; } else { halfedge2 = halfedge1; edge3 = edge2; } bool flag = num2 >= edge3.rightSite.x; if (flag) { Side?leftRight = halfedge2.leftRight; if (leftRight.GetValueOrDefault() == Side.LEFT && leftRight.HasValue) { goto IL_0138; } } if (flag || halfedge2.leftRight != Side.RIGHT) { return(Create(num2, y)); } goto IL_0138; IL_0138: return(null); }
/** * This is the only way to make a Vertex * * @param halfedge0 * @param halfedge1 * @return * */ public static Vertex Intersect(Halfedge halfedge0, Halfedge halfedge1) { Edge edge0, edge1, edge; 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 (-1.0e-10 < determinant && determinant < 1.0e-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 == Side.LEFT) || (!rightOfSite && halfedge.leftRight == Side.RIGHT)) { return(null); } return(Vertex.Create(intersectionX, intersectionY)); }