MCPcopy
hub / github.com/fogleman/ln / Intersect

Method Intersect

ln/cube.go:36–49  ·  view source on GitHub ↗
(r Ray)

Source from the content-addressed store, hash-verified

34}
35
36func (c *Cube) Intersect(r Ray) Hit {
37 n := c.Min.Sub(r.Origin).Div(r.Direction)
38 f := c.Max.Sub(r.Origin).Div(r.Direction)
39 n, f = n.Min(f), n.Max(f)
40 t0 := math.Max(math.Max(n.X, n.Y), n.Z)
41 t1 := math.Min(math.Min(f.X, f.Y), f.Z)
42 if t0 < 1e-3 && t1 > 1e-3 {
43 return Hit{c, t1}
44 }
45 if t0 >= 1e-3 && t0 < t1 {
46 return Hit{c, t0}
47 }
48 return NoHit
49}
50
51func (c *Cube) Paths() Paths {
52 x1, y1, z1 := c.Min.X, c.Min.Y, c.Min.Z

Callers

nothing calls this directly

Calls 4

DivMethod · 0.80
SubMethod · 0.80
MinMethod · 0.45
MaxMethod · 0.45

Tested by

no test coverage detected