// If the maximum distance from X to the edge AB is greater than "max_dist", // this method updates "max_dist" and returns true. Otherwise it returns false. // The case A == B is handled correctly. public static bool UpdateMaxDistance(S2Point x, S2Point a, S2Point b, ref S1ChordAngle max_dist) { var dist = S1ChordAngle.Max(new S1ChordAngle(x, a), new S1ChordAngle(x, b)); if (dist > S1ChordAngle.Right) { AlwaysUpdateMinDistance(-x, a, b, ref dist, true); dist = S1ChordAngle.Straight - dist; } if (max_dist < dist) { max_dist = dist; return(true); } return(false); }
private S1ChordAngle EstimateMaxError(R2Point pa, S2Point a, R2Point pb, S2Point b) { // See the algorithm description at the top of this file. // We always tessellate edges longer than 90 degrees on the sphere, since the // approximation below is not robust enough to handle such edges. if (a.DotProd(b) < -1e-14) { return(S1ChordAngle.Infinity); } const double t1 = kInterpolationFraction; const double t2 = 1 - kInterpolationFraction; S2Point mid1 = S2.Interpolate(a, b, t1); S2Point mid2 = S2.Interpolate(a, b, t2); S2Point pmid1 = proj_.Unproject(Projection.Interpolate(t1, pa, pb)); S2Point pmid2 = proj_.Unproject(Projection.Interpolate(t2, pa, pb)); return(S1ChordAngle.Max(new S1ChordAngle(mid1, pmid1), new S1ChordAngle(mid2, pmid2))); }