(r Ray, tmin, tmax float64)
| 38 | } |
| 39 | |
| 40 | func (node *Node) Intersect(r Ray, tmin, tmax float64) Hit { |
| 41 | var tsplit float64 |
| 42 | var leftFirst bool |
| 43 | switch node.Axis { |
| 44 | case AxisNone: |
| 45 | return node.IntersectShapes(r) |
| 46 | case AxisX: |
| 47 | tsplit = (node.Point - r.Origin.X) / r.Direction.X |
| 48 | leftFirst = (r.Origin.X < node.Point) || (r.Origin.X == node.Point && r.Direction.X <= 0) |
| 49 | case AxisY: |
| 50 | tsplit = (node.Point - r.Origin.Y) / r.Direction.Y |
| 51 | leftFirst = (r.Origin.Y < node.Point) || (r.Origin.Y == node.Point && r.Direction.Y <= 0) |
| 52 | case AxisZ: |
| 53 | tsplit = (node.Point - r.Origin.Z) / r.Direction.Z |
| 54 | leftFirst = (r.Origin.Z < node.Point) || (r.Origin.Z == node.Point && r.Direction.Z <= 0) |
| 55 | } |
| 56 | var first, second *Node |
| 57 | if leftFirst { |
| 58 | first = node.Left |
| 59 | second = node.Right |
| 60 | } else { |
| 61 | first = node.Right |
| 62 | second = node.Left |
| 63 | } |
| 64 | if tsplit > tmax || tsplit <= 0 { |
| 65 | return first.Intersect(r, tmin, tmax) |
| 66 | } else if tsplit < tmin { |
| 67 | return second.Intersect(r, tmin, tmax) |
| 68 | } else { |
| 69 | h1 := first.Intersect(r, tmin, tsplit) |
| 70 | if h1.T <= tsplit { |
| 71 | return h1 |
| 72 | } |
| 73 | h2 := second.Intersect(r, tsplit, math.Min(tmax, h1.T)) |
| 74 | if h1.T <= h2.T { |
| 75 | return h1 |
| 76 | } else { |
| 77 | return h2 |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func (node *Node) IntersectShapes(r Ray) Hit { |
| 83 | hit := NoHit |
nothing calls this directly
no test coverage detected