func sumEqual(u, v, w float64) bool {
	return (u+v == w) && (u == w-v) && (v == w-u)
}
The three functions below (sumEqual, intersectsFace, intersectsOppositeEdges)
all compare a sum (u + v) to a third value w. They are implemented in such a
way that they produce an exact result even though all calculations are done
with ordinary floating-point operations. Here are the principles on which these
functions are based:

A. If u + v < w in floating-point, then u + v < w in exact arithmetic.

B. If u + v < w in exact arithmetic, then at least one of the following
expressions is true in floating-point:
u + v < w
u < w - v
v < w - u

Proof: By rearranging terms and substituting ">" for "<", we can assume
that all values are non-negative.  Now clearly "w" is not the smallest
value, so assume WLOG that "u" is the smallest.  We want to show that
u < w - v in floating-point.  If v >= w/2, the calculation of w - v is
exact since the result is smaller in magnitude than either input value,
so the result holds.  Otherwise we have u <= v < w/2 and w - v >= w/2
(even in floating point), so the result also holds.
sumEqual reports whether u + v == w exactly.
package s2
import (
	"math"
	"github.com/golang/geo/r1"
	"github.com/golang/geo/r2"
	"github.com/golang/geo/r3"
)
const (
	edgeClipErrorUVCoord = 2.25 * dblEpsilon
	edgeClipErrorUVDist = 2.25 * dblEpsilon
	faceClipErrorRadians = 3 * dblEpsilon
	faceClipErrorUVDist = 9 * dblEpsilon
	faceClipErrorUVCoord = 9.0 * (1.0 / math.Sqrt2) * dblEpsilon
	intersectsRectErrorUVDist = 3 * math.Sqrt2 * dblEpsilon
)
func ClipToFace(a, b Point, face int) (aUV, bUV r2.Point, intersects bool) {
	return ClipToPaddedFace(a, b, face, 0.0)
}
func ClipToPaddedFace(a, b Point, f int, padding float64) (aUV, bUV r2.Point, intersects bool) {
	if face(a.Vector) == f && face(b.Vector) == f {
		au, av := validFaceXYZToUV(f, a.Vector)
		bu, bv := validFaceXYZToUV(f, b.Vector)
		return r2.Point{au, av}, r2.Point{bu, bv}, true
	}
	normUVW := pointUVW(faceXYZtoUVW(f, a.PointCross(b)))
	aUVW := pointUVW(faceXYZtoUVW(f, a))
	bUVW := pointUVW(faceXYZtoUVW(f, b))
	scaleUV := 1 + padding
	scaledN := pointUVW{r3.Vector{X: scaleUV * normUVW.X, Y: scaleUV * normUVW.Y, Z: normUVW.Z}}
	if !scaledN.intersectsFace() {
		return aUV, bUV, false
	}
	if math.Max(math.Abs(normUVW.X), math.Max(math.Abs(normUVW.Y), math.Abs(normUVW.Z))) < math.Ldexp(1, -511) {
		normUVW = pointUVW{normUVW.Mul(math.Ldexp(1, 563))}
	}
	normUVW = pointUVW{normUVW.Normalize()}
	aTan := pointUVW{normUVW.Cross(aUVW.Vector)}
	bTan := pointUVW{bUVW.Cross(normUVW.Vector)}
	aUV, aScore := clipDestination(bUVW, aUVW, pointUVW{scaledN.Mul(-1)}, bTan, aTan, scaleUV)
	bUV, bScore := clipDestination(aUVW, bUVW, scaledN, aTan, bTan, scaleUV)
	return aUV, bUV, aScore+bScore < 3
}
func ClipEdge(a, b r2.Point, clip r2.Rect) (aClip, bClip r2.Point, intersects bool) {
	bound := r2.RectFromPoints(a, b)
	if bound, intersects = clipEdgeBound(a, b, clip, bound); !intersects {
		return aClip, bClip, false
	}
	ai := 0
	if a.X > b.X {
		ai = 1
	}
	aj := 0
	if a.Y > b.Y {
		aj = 1
	}
	return bound.VertexIJ(ai, aj), bound.VertexIJ(1-ai, 1-aj), true
}