Class: GreinerHormann::Intersection
- Inherits:
-
Object
- Object
- GreinerHormann::Intersection
- Defined in:
- lib/greiner_hormann/intersection.rb
Instance Attribute Summary collapse
-
#to_clip ⇒ Object
Returns the value of attribute to_clip.
-
#to_source ⇒ Object
Returns the value of attribute to_source.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
-
#initialize(s1, s2, c1, c2) ⇒ Intersection
constructor
A new instance of Intersection.
- #valid ⇒ Object
Constructor Details
#initialize(s1, s2, c1, c2) ⇒ Intersection
Returns a new instance of Intersection.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/greiner_hormann/intersection.rb', line 5 def initialize(s1, s2, c1, c2) self.x = self.y = self.to_source = self.to_clip = 0.0 d = (c2.y - c1.y) * (s2.x - s1.x) - (c2.x - c1.x) * (s2.y - s1.y) return if d == 0 self.to_source = ((c2.x - c1.x) * (s1.y - c1.y) - (c2.y - c1.y) * (s1.x - c1.x)) / d self.to_clip = ((s2.x - s1.x) * (s1.y - c1.y) - (s2.y - s1.y) * (s1.x - c1.x)) / d if valid self.x = s1.x + self.to_source * (s2.x - s1.x) self.y = s1.y + self.to_source * (s2.y - s1.y) end end |
Instance Attribute Details
#to_clip ⇒ Object
Returns the value of attribute to_clip.
3 4 5 |
# File 'lib/greiner_hormann/intersection.rb', line 3 def to_clip @to_clip end |
#to_source ⇒ Object
Returns the value of attribute to_source.
3 4 5 |
# File 'lib/greiner_hormann/intersection.rb', line 3 def to_source @to_source end |
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/greiner_hormann/intersection.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/greiner_hormann/intersection.rb', line 3 def y @y end |
Instance Method Details
#valid ⇒ Object
19 20 21 |
# File 'lib/greiner_hormann/intersection.rb', line 19 def valid 0 < to_source && to_source < 1 && 0 < to_clip && to_clip < 1 end |