func (p pointUVW) intersectsOppositeEdges() bool {
	u := math.Abs(p.X)
	v := math.Abs(p.Y)
	w := math.Abs(p.Z)
	if math.Abs(u-v) != w {
		return math.Abs(u-v) >= w
	}
	if u >= v {
		return u-w >= v
	}
	return v-w >= u
}
intersectsOppositeEdges reports whether a directed line L intersects two
opposite edges of a cube face F. This includs the case where L passes
exactly through a corner vertex of F. The directed line L is defined
by its normal N in the (u,v,w) coordinates of F.
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
}
func sumEqual(u, v, w float64) bool {
	return (u+v == w) && (u == w-v) && (v == w-u)
}
type pointUVW Point
func (p pointUVW) intersectsFace() bool {
	u := math.Abs(p.X)
	v := math.Abs(p.Y)
	w := math.Abs(p.Z)
	return (v >= w-u) && (u >= w-v)
}