Class: StraightSkeleton::Split
- Inherits:
-
Object
- Object
- StraightSkeleton::Split
- Includes:
- InteriorNode
- Defined in:
- lib/nswtopo/geometry/straight_skeleton/split.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Attributes included from Node
#neighbours, #normals, #original, #point, #travel
Instance Method Summary collapse
-
#initialize(nodes, point, travel, source, node) ⇒ Split
constructor
A new instance of Split.
- #replace!(&block) ⇒ Object
- #split!(index, &block) ⇒ Object
- #viable? ⇒ Boolean
Methods included from InteriorNode
Methods included from Node
#active?, #index, #next, #prev, #project, #reflex?, #splits?, #terminal?
Constructor Details
#initialize(nodes, point, travel, source, node) ⇒ Split
Returns a new instance of Split.
5 6 7 |
# File 'lib/nswtopo/geometry/straight_skeleton/split.rb', line 5 def initialize(nodes, point, travel, source, node) @original, @nodes, @point, @travel, @source, @normal = self, nodes, point, travel, source, node.normals[1] end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
9 10 11 |
# File 'lib/nswtopo/geometry/straight_skeleton/split.rb', line 9 def source @source end |
Instance Method Details
#replace!(&block) ⇒ Object
27 28 29 30 31 |
# File 'lib/nswtopo/geometry/straight_skeleton/split.rb', line 27 def replace!(&block) dup.split!(0, &block) dup.split!(1, &block) block.call @source end |
#split!(index, &block) ⇒ Object
22 23 24 25 |
# File 'lib/nswtopo/geometry/straight_skeleton/split.rb', line 22 def split!(index, &block) @neighbours = [@source.neighbours[index], @edge[1-index]].rotate index @neighbours.inject(&:equal?) ? block.call(prev, prev.is_a?(Collapse) ? 1 : 0) : insert! if @neighbours.any? end |
#viable? ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nswtopo/geometry/straight_skeleton/split.rb', line 11 def viable? return false unless @source.active? @edge = @nodes.track(@normal).find do |edge| (n00, n01), (n10, n11) = edge.map(&:normals) p0, p1 = edge.map(&:point) next if (point - p0).cross(n00 ? n00 + n01 : n01) < 0 next if (point - p1).cross(n11 ? n11 + n10 : n10) > 0 true end end |