class Geom2D::PolygonSet

Represents a set of polygons.

Attributes

polygons[R]

The array of polygons.

Public Class Methods

new(polygons = []) click to toggle source

Creates a new PolygonSet with the given polygons.

# File lib/geom2d/polygon_set.rb, line 21
def initialize(polygons = [])
  @polygons = polygons
end

Public Instance Methods

+(other)
Alias for: join
<<(polygon)
Alias for: add
add(polygon) click to toggle source

Adds a polygon to this set.

# File lib/geom2d/polygon_set.rb, line 26
def add(polygon)
  @polygons << polygon
  self
end
Also aliased as: <<
bbox() click to toggle source

Returns the BoundingBox of all polygons in the set, or nil if it contains no polygon.

# File lib/geom2d/polygon_set.rb, line 52
def bbox
  return BoundingBox.new if @polygons.empty?
  result = @polygons.first.bbox
  @polygons[1..-1].each {|v| result.add!(v.bbox) }
  result
end
each_segment(&block) click to toggle source

Calls the given block once for each segment of each polygon in the set.

If no block is given, an Enumerator is returned.

# File lib/geom2d/polygon_set.rb, line 41
def each_segment(&block)
  return to_enum(__method__) unless block_given?
  @polygons.each {|polygon| polygon.each_segment(&block) }
end
join(other) click to toggle source

Creates a new polygon set by combining the polygons from this set and the other one.

# File lib/geom2d/polygon_set.rb, line 33
def join(other)
  PolygonSet.new(@polygons + other.polygons)
end
Also aliased as: +
nr_of_contours() click to toggle source

Returns the number of polygons in this set.

# File lib/geom2d/polygon_set.rb, line 47
def nr_of_contours
  @polygons.size
end