Class: Ra::Intersection
- Inherits:
-
Object
- Object
- Ra::Intersection
- Defined in:
- lib/ra/intersection.rb
Overview
An intersection tracks the time t at which a shape is intersected by a ray.
Instance Attribute Summary collapse
-
#ray ⇒ Object
Returns the value of attribute ray.
-
#shape ⇒ Object
Returns the value of attribute shape.
-
#t ⇒ Object
Returns the value of attribute t.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(t:, ray:, shape:) ⇒ Intersection
constructor
A new instance of Intersection.
- #surface ⇒ Ra::Surface
Constructor Details
#initialize(t:, ray:, shape:) ⇒ Intersection
Returns a new instance of Intersection.
25 26 27 28 29 |
# File 'lib/ra/intersection.rb', line 25 def initialize(t:, ray:, shape:) @t = t @ray = ray @shape = shape end |
Instance Attribute Details
#ray ⇒ Object
Returns the value of attribute ray.
6 7 8 |
# File 'lib/ra/intersection.rb', line 6 def ray @ray end |
#shape ⇒ Object
Returns the value of attribute shape.
6 7 8 |
# File 'lib/ra/intersection.rb', line 6 def shape @shape end |
#t ⇒ Object
Returns the value of attribute t.
6 7 8 |
# File 'lib/ra/intersection.rb', line 6 def t @t end |
Class Method Details
.hit(intersections:) ⇒ Ra::Intersection?
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ra/intersection.rb', line 10 def self.hit(intersections:) hit = nil intersections.each do |interaction| next if interaction.t.negative? hit = interaction if hit.nil? || interaction.t < hit.t end hit end |
Instance Method Details
#==(other) ⇒ Boolean
32 33 34 |
# File 'lib/ra/intersection.rb', line 32 def ==(other) t == other.t && ray == other.ray && shape == other.shape end |
#surface ⇒ Ra::Surface
37 38 39 40 41 42 43 |
# File 'lib/ra/intersection.rb', line 37 def surface point = ray.position(t:) eyev = -ray.direction normalv = shape.normal(point:) Surface.new(shape:, eyev:, normalv:, point:) end |