Class: Geom2D::PolygonSet
- Inherits:
 - 
      Object
      
        
- Object
 - Geom2D::PolygonSet
 
 
- Defined in:
 - lib/geom2d/polygon_set.rb
 
Overview
Represents a set of polygons.
Instance Attribute Summary collapse
- 
  
    
      #polygons  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The array of polygons.
 
Instance Method Summary collapse
- 
  
    
      #add(polygon)  ⇒ Object 
    
    
      (also: #<<)
    
  
  
  
  
  
  
  
  
  
    
Adds a polygon to this set.
 - 
  
    
      #bbox  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the BoundingBox of all polygons in the set, or
nilif it contains no polygon. - 
  
    
      #each_segment(&block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Calls the given block once for each segment of each polygon in the set.
 - 
  
    
      #initialize(polygons = [])  ⇒ PolygonSet 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Creates a new PolygonSet with the given polygons.
 - 
  
    
      #inspect  ⇒ Object 
    
    
      (also: #to_s)
    
  
  
  
  
  
  
  
  
  
    
:nodoc:.
 - 
  
    
      #join(other)  ⇒ Object 
    
    
      (also: #+)
    
  
  
  
  
  
  
  
  
  
    
Creates a new polygon set by combining the polygons from this set and the other one.
 - 
  
    
      #nr_of_contours  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the number of polygons in this set.
 
Constructor Details
#initialize(polygons = []) ⇒ PolygonSet
Creates a new PolygonSet with the given polygons.
      22 23 24  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 22 def initialize(polygons = []) @polygons = polygons end  | 
  
Instance Attribute Details
#polygons ⇒ Object (readonly)
The array of polygons.
      19 20 21  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 19 def polygons @polygons end  | 
  
Instance Method Details
#add(polygon) ⇒ Object Also known as: <<
Adds a polygon to this set.
      27 28 29 30  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 27 def add(polygon) @polygons << polygon self end  | 
  
#bbox ⇒ Object
Returns the BoundingBox of all polygons in the set, or nil if it contains no polygon.
      53 54 55 56 57 58  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 53 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) ⇒ Object
Calls the given block once for each segment of each polygon in the set.
If no block is given, an Enumerator is returned.
      42 43 44 45  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 42 def each_segment(&block) return to_enum(__method__) unless block_given? @polygons.each {|polygon| polygon.each_segment(&block) } end  | 
  
#inspect ⇒ Object Also known as: to_s
:nodoc:
      60 61 62  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 60 def inspect # :nodoc: "PolygonSet#{@polygons}" end  | 
  
#join(other) ⇒ Object Also known as: +
Creates a new polygon set by combining the polygons from this set and the other one.
      34 35 36  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 34 def join(other) PolygonSet.new(@polygons + other.polygons) end  | 
  
#nr_of_contours ⇒ Object
Returns the number of polygons in this set.
      48 49 50  | 
    
      # File 'lib/geom2d/polygon_set.rb', line 48 def nr_of_contours @polygons.size end  |