Class: Geometry::VertexRing
- Inherits:
-
Object
- Object
- Geometry::VertexRing
- Defined in:
- lib/geometry/polygon.rb
Instance Attribute Summary collapse
-
#vertices ⇒ Object
readonly
Returns the value of attribute vertices.
Instance Method Summary collapse
-
#edges ⇒ Object
Enumerate the pairs of vertices corresponding to each edge.
- #edges_with_index ⇒ Object
-
#initialize ⇒ VertexRing
constructor
A new instance of VertexRing.
- #insert(index, point, type) ⇒ Object
-
#insert_boundary(index, point) ⇒ Object
Insert a boundary vertex.
- #push(point, type) ⇒ Object
Constructor Details
#initialize ⇒ VertexRing
Returns a new instance of VertexRing.
328 329 330 |
# File 'lib/geometry/polygon.rb', line 328 def initialize @vertices = [] end |
Instance Attribute Details
#vertices ⇒ Object (readonly)
Returns the value of attribute vertices.
326 327 328 |
# File 'lib/geometry/polygon.rb', line 326 def vertices @vertices end |
Instance Method Details
#edges ⇒ Object
Enumerate the pairs of vertices corresponding to each edge
359 360 361 |
# File 'lib/geometry/polygon.rb', line 359 def edges (@vertices + [@vertices.first]).each_cons(2) {|v1,v2| yield v1, v2} end |
#edges_with_index ⇒ Object
363 364 365 366 |
# File 'lib/geometry/polygon.rb', line 363 def edges_with_index index = 0 (@vertices + [@vertices.first]).each_cons(2) {|v1,v2| yield(Edge.new(v1[:vertex], v2[:vertex]), index); index += 1} end |
#insert(index, point, type) ⇒ Object
335 336 337 338 339 340 341 342 343 |
# File 'lib/geometry/polygon.rb', line 335 def insert(index, point, type) if v = @vertices.find {|v| v[:vertex] == point } v[:type] = type false else @vertices.insert(index, {:vertex => point, :type => type}) true end end |
#insert_boundary(index, point) ⇒ Object
Insert a boundary vertex
348 349 350 |
# File 'lib/geometry/polygon.rb', line 348 def insert_boundary(index, point) self.insert(index, point, 0) end |
#push(point, type) ⇒ Object
354 355 356 |
# File 'lib/geometry/polygon.rb', line 354 def push(point, type) @vertices << {:vertex => point, :type => type} end |