public int FindIntersection(LineSegment line2, ref Vector3 intersection) { if (Start.x == End.x) { if (line2.Start.x == line2.End.x) { return(-1); } intersection.x = Start.x; intersection.y = line2.CalcY(intersection.x); if ((intersection.y >= Start.y) && (intersection.y <= End.y)) { return(1); } return(-1); } return(mLine.FindIntersection(line2, ref intersection)); }
public int FindIntersection(Edge e2, ref Vector3 intersection) { LineSegment line2 = e2.Line; if (Line.Start.x == Line.End.x) { if (line2.Start.x == line2.End.x) { return(-1); } intersection.x = Line.Start.x; intersection.y = line2.CalcY(intersection.x); if ((intersection.y < Line.Start.y) || (intersection.y > Line.End.y)) { return(-1); } if ((intersection.y == Line.Start.y) || (intersection.y == Line.End.y)) { return(0); } return(1); } return(Line.FindIntersection(line2, ref intersection)); }
public override int Compare(Edge e1, Edge e2) { if (e1 == e2) { return(0); } LineSegment s1 = e1.Line; LineSegment s2 = e2.Line; Vector3 v1 = s1.End - s1.Start; Vector3 v2 = s2.End - s2.Start; float y1 = s1.CalcY(CurrentX); float y2 = s2.CalcY(CurrentX); Vector3 sweep = new Vector3(0, -1, 0); float dx; v1.Normalize(); v2.Normalize(); // // Check for vertical lines // if (y1 == float.MaxValue) { if (y2 == float.MaxValue) { dx = s1.Start.x - s2.Start.x; // both vertical, sort on X if (Math.Abs(dx) > LineSegment.EPSILON) { return((dx > 0) ? 1 : -1); } return(e1.Tri.ID - e2.Tri.ID); } // // first edge is vertical, not the second // choose vertical direction based on // the slope of the other line // if Y increases with X, treat the vertical // line as being above. Otherwise point it // down and treat as below. // dx = s1.Start.x - CurrentX; if (Math.Abs(dx) < LineSegment.EPSILON) { y1 = y2; // they intersect at CurrentX } } // // second edge is vertical, not the first // choose vertical direction based on // the slope of the other line // if Y increases with X, treat the vertical // line as being above. Otherwise point it // down and treat as below. // else if (y2 == float.MaxValue) { dx = s2.Start.x - CurrentX; if (Math.Abs(dx) < LineSegment.EPSILON) { y2 = y1; // they intersect at CurrentX } } // // Compare Y values at the current X // float dy = y1 - y2; if (Math.Abs(dy) > LineSegment.EPSILON) { return((dy > 0) ? 1 : -1); } // // sort based on angle around common point // float a1 = Vector3.Dot(sweep, v1); float a2 = Vector3.Dot(sweep, v2); float t = a2 - a1; if (Math.Abs(t) > LineSegment.EPSILON) { return((t > 0) ? 1 : -1); } return(e1.Tri.ID - e2.Tri.ID); }