Class: Floorplanner::AreaBuilder

Inherits:
Geom::TriangleMesh show all
Defined in:
lib/floorplanner/area_builder.rb

Instance Attribute Summary collapse

Attributes inherited from Geom::TriangleMesh

#data, #faces, #meshes, #tess, #texcoord, #vertices

Instance Method Summary collapse

Methods inherited from Geom::TriangleMesh

#<<, #bounding_box, #merge, #reverse, #transform_vertices

Constructor Details

#initialize(&block) ⇒ AreaBuilder

Returns a new instance of AreaBuilder.



6
7
8
9
10
# File 'lib/floorplanner/area_builder.rb', line 6

def initialize(&block)
  super()
  @meshes = {}
  block.call(self)
end

Instance Attribute Details

#ceiling_zObject (readonly)

Returns the value of attribute ceiling_z.



4
5
6
# File 'lib/floorplanner/area_builder.rb', line 4

def ceiling_z
  @ceiling_z
end

Instance Method Details

#area(vertices, params = nil) ⇒ Object



24
25
26
27
28
# File 'lib/floorplanner/area_builder.rb', line 24

def area(vertices, params=nil)
  a_id = vertices.hash.abs.to_s + "_" + params[:type].to_s
  params[:color] = Floorplanner.read_color params[:color]
  @meshes[a_id] = Geom::Polygon.new(vertices, nil, params.merge({:id => a_id}))
end

#each(&block) ⇒ Object



12
13
14
# File 'lib/floorplanner/area_builder.rb', line 12

def each(&block)
  @meshes.each_value{|a| block.call(a)}
end

#update(ceiling_z) ⇒ Object



30
31
32
33
34
35
# File 'lib/floorplanner/area_builder.rb', line 30

def update(ceiling_z)
  @ceiling_z = ceiling_z
  @meshes.each do |id,mesh|
    mesh.update
  end
end

#vertex(p) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/floorplanner/area_builder.rb', line 16

def vertex(p)
  if existing = @vertices.index(p)
    @vertices[existing]
  else
    @vertices << p; p
  end
end