Class: Wicket::Subpoint

Inherits:
Struct
  • Object
show all
Includes:
Cartesian
Defined in:
lib/wicket/subpoint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#siblingsObject

Returns the value of attribute siblings

Returns:

  • (Object)

    the current value of siblings



2
3
4
# File 'lib/wicket/subpoint.rb', line 2

def siblings
  @siblings
end

#tObject

Returns the value of attribute t

Returns:

  • (Object)

    the current value of t



2
3
4
# File 'lib/wicket/subpoint.rb', line 2

def t
  @t
end

#xObject

Returns the value of attribute x

Returns:

  • (Object)

    the current value of x



2
3
4
# File 'lib/wicket/subpoint.rb', line 2

def x
  @x
end

#yObject

Returns the value of attribute y

Returns:

  • (Object)

    the current value of 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

#angleObject



22
23
24
# File 'lib/wicket/subpoint.rb', line 22

def angle
  evaluate_angle(previous_neighbor,self,next_neighbor) unless endpoint?
end

#endpoint?Boolean

Returns:

  • (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_neighborObject



18
19
20
# File 'lib/wicket/subpoint.rb', line 18

def next_neighbor
  siblings.select{|s| s.t > t }.min_by(&:t)
end

#previous_neighborObject



14
15
16
# File 'lib/wicket/subpoint.rb', line 14

def previous_neighbor
  siblings.select{|s| s.t < t }.max_by(&:t)
end