Class: Geometry::VertexRing

Inherits:
Object
  • Object
show all
Defined in:
lib/geometry/polygon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVertexRing

Returns a new instance of VertexRing.



328
329
330
# File 'lib/geometry/polygon.rb', line 328

def initialize
    @vertices = []
end

Instance Attribute Details

#verticesObject (readonly)

Returns the value of attribute vertices.



326
327
328
# File 'lib/geometry/polygon.rb', line 326

def vertices
  @vertices
end

Instance Method Details

#edgesObject

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_indexObject



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

Parameters:

  • index (Integer)

    The index to insert the new Point before

  • point (Point)

    The Point to insert

  • type (Integer)

    The vertex type: 1 is inside, 0 is boundary, -1 is outside



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

Parameters:

  • index (Integer)

    The index to insert the new Point before

  • point (Point)

    The Point to insert



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

Parameters:

  • point (Point)

    The Point to push

  • type (Integer)

    The vertex type: 1 is inside, 0 is boundary, -1 is outside



354
355
356
# File 'lib/geometry/polygon.rb', line 354

def push(point, type)
    @vertices << {:vertex => point, :type => type}
end