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) ⇒ Bool
True if the Point was inserted, false otherwise.
-
#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
360 361 362 |
# File 'lib/geometry/polygon.rb', line 360 def edges (@vertices + [@vertices.first]).each_cons(2) {|v1,v2| yield v1, v2} end |
#edges_with_index ⇒ Object
364 365 366 367 |
# File 'lib/geometry/polygon.rb', line 364 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) ⇒ Bool
Returns true if the Point was inserted, false otherwise.
336 337 338 339 340 341 342 343 344 |
# File 'lib/geometry/polygon.rb', line 336 def insert(index, point, type) if vertex = @vertices.find {|v| v[:vertex] == point } vertex[:type] = type false else @vertices.insert(index, {:vertex => point, :type => type}) true end end |
#insert_boundary(index, point) ⇒ Object
Insert a boundary vertex
349 350 351 |
# File 'lib/geometry/polygon.rb', line 349 def insert_boundary(index, point) self.insert(index, point, 0) end |
#push(point, type) ⇒ Object
355 356 357 |
# File 'lib/geometry/polygon.rb', line 355 def push(point, type) @vertices << {:vertex => point, :type => type} end |