Class: Wicket::Subpoint
- Inherits:
-
Struct
- Object
- Struct
- Wicket::Subpoint
- Includes:
- Cartesian
- Defined in:
- lib/wicket/subpoint.rb
Instance Attribute Summary collapse
-
#siblings ⇒ Object
Returns the value of attribute siblings.
-
#t ⇒ Object
Returns the value of attribute t.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #angle ⇒ Object
- #endpoint? ⇒ Boolean
-
#evaluate_angle(p1, p2, p3) ⇒ Object
This method evaluates the angle at p2 in radians (180 deg = pi).
-
#initialize(x, y, t, siblings) ⇒ Subpoint
constructor
A new instance of Subpoint.
- #next_neighbor ⇒ Object
- #previous_neighbor ⇒ Object
Methods included from Cartesian
#distance_to, #to_svg, #to_wkt
Constructor Details
#initialize(x, y, t, siblings) ⇒ Subpoint
Returns a new instance of Subpoint.
9 10 11 12 |
# File 'lib/wicket/subpoint.rb', line 9 def initialize(x,y,t,siblings) super(x,y,t,siblings) siblings << self end |
Instance Attribute Details
#siblings ⇒ Object
Returns the value of attribute siblings
2 3 4 |
# File 'lib/wicket/subpoint.rb', line 2 def siblings @siblings end |
#t ⇒ Object
Returns the value of attribute t
2 3 4 |
# File 'lib/wicket/subpoint.rb', line 2 def t @t end |
#x ⇒ Object
Returns the value of attribute x
2 3 4 |
# File 'lib/wicket/subpoint.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y
2 3 4 |
# File 'lib/wicket/subpoint.rb', line 2 def y @y end |
Class Method Details
.from_coordinate(coordinate, t, siblings) ⇒ Object
5 6 7 |
# File 'lib/wicket/subpoint.rb', line 5 def self.from_coordinate(coordinate,t,siblings) new(coordinate.x,coordinate.y,t,siblings) end |
Instance Method Details
#angle ⇒ Object
22 23 24 |
# File 'lib/wicket/subpoint.rb', line 22 def angle evaluate_angle(previous_neighbor,self,next_neighbor) unless endpoint? end |
#endpoint? ⇒ Boolean
26 27 28 |
# File 'lib/wicket/subpoint.rb', line 26 def endpoint? t == 0 || t == 1 end |
#evaluate_angle(p1, p2, p3) ⇒ Object
This method evaluates the angle at p2 in radians (180 deg = pi)
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wicket/subpoint.rb', line 31 def evaluate_angle(p1,p2,p3) if straight_line?(p1,p2,p3) Math::PI else a = p2.distance_to(p1) b = p2.distance_to(p3) c = p1.distance_to(p3) Math.acos((a**2 + b**2 - c**2)/(2 * a * b)) end end |
#next_neighbor ⇒ Object
18 19 20 |
# File 'lib/wicket/subpoint.rb', line 18 def next_neighbor siblings.select{|s| s.t > t }.min_by(&:t) end |
#previous_neighbor ⇒ Object
14 15 16 |
# File 'lib/wicket/subpoint.rb', line 14 def previous_neighbor siblings.select{|s| s.t < t }.max_by(&:t) end |