Module: StraightSkeleton::Node

Included in:
InteriorNode, Vertex
Defined in:
lib/nswtopo/geometry/straight_skeleton/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#neighboursObject (readonly)

Returns the value of attribute neighbours.



3
4
5
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 3

def neighbours
  @neighbours
end

#normalsObject (readonly)

Returns the value of attribute normals.



3
4
5
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 3

def normals
  @normals
end

#originalObject (readonly)

Returns the value of attribute original.



3
4
5
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 3

def original
  @original
end

#pointObject (readonly)

Returns the value of attribute point.



3
4
5
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 3

def point
  @point
end

#travelObject (readonly)

Returns the value of attribute travel.



3
4
5
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 3

def travel
  @travel
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 5

def active?
  @nodes.include? self
end

#indexObject



29
30
31
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 29

def index
  @index ||= @nodes.index self
end

#nextObject



25
26
27
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 25

def next
  @neighbours[1]
end

#prevObject



21
22
23
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 21

def prev
  @neighbours[0]
end

#project(travel) ⇒ Object

########################################### solve for vector p:

n0.(p - @point) = travel - @travel
n1.(p - @point) = travel - @travel

###########################################



39
40
41
42
43
44
45
46
47
48
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 39

def project(travel)
  det = normals.inject(&:cross) if normals.all?
  case
  when det&.nonzero?
    x = normals.map { |normal| travel - @travel + normal.dot(point) }
    (normals[0].perp * x[1] - normals[1].perp * x[0]) / det
  when normals[0] then normals[0] * (travel - @travel) + point
  when normals[1] then normals[1] * (travel - @travel) + point
  end
end

#reflex?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 13

def reflex?
  normals.inject(&:cross) * @nodes.direction <= 0
end

#splits?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 17

def splits?
  terminal? || reflex?
end

#terminal?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/nswtopo/geometry/straight_skeleton/node.rb', line 9

def terminal?
  @neighbours.one?
end