Class: Floorplanner::WallBuilder
Instance Attribute Summary
#data, #meshes, #tess, #texcoord
Instance Method Summary
collapse
#<<, #bounding_box, #merge, #reverse, #transform_vertices
Constructor Details
Returns a new instance of WallBuilder.
4
5
6
7
8
9
10
|
# File 'lib/floorplanner/wall_builder.rb', line 4
def initialize(&block)
super()
@connections = Hash.new
@base_vertices = Array.new
@walls = Array.new
block.call(self)
end
|
Instance Method Details
#collect(&block) ⇒ Object
16
17
18
|
# File 'lib/floorplanner/wall_builder.rb', line 16
def collect(&block)
@walls.collect{|w| block.call(w)}
end
|
#each(&block) ⇒ Object
12
13
14
|
# File 'lib/floorplanner/wall_builder.rb', line 12
def each(&block)
@walls.each{|w| block.call(w)}
end
|
#faces ⇒ Object
133
134
135
|
# File 'lib/floorplanner/wall_builder.rb', line 133
def faces
@faces
end
|
#opening(position, size, type) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/floorplanner/wall_builder.rb', line 40
def opening(position, size, type)
@walls.each do |wall|
if wall.outline.point_inside(position)
wall.opening(position,size,type)
break
end
end
end
|
#prepare ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/floorplanner/wall_builder.rb', line 49
def prepare
@base_vertices.each do |v|
connections = @connections[v]
next if connections.length.zero?
connections.each do |c|
begin
c.angle = Math.atan2(c.point.x - v.x, c.point.y - v.y)
rescue; end
end
connections.sort! {|a,b| a.angle <=> b.angle}
connections.each_index do |i|
j = (i+1) % connections.length
w0 , w1 = find_wall(v,connections[i].point),
find_wall(v,connections[j].point)
flipped0 , flipped1 = (w0.baseline.end_point == v),
(w1.baseline.end_point == v)
e0 , e1 = flipped0 ? w0.outer : w0.inner,
flipped1 ? w1.inner : w1.outer
isect = Geom::Intersection.line_line(e0.start_point.position,e0.end_point.position,e1.start_point.position,e1.end_point.position,true)
if isect.status == Geom::Intersection::INTERSECTION
if isect.alpha[0].abs < 2
if flipped0
e0.end_point.x = isect.points[0].x
e0.end_point.y = isect.points[0].y
else
e0.start_point.x = isect.points[0].x
e0.start_point.y = isect.points[0].y
end
if flipped1
e1.end_point.x = isect.points[0].x
e1.end_point.y = isect.points[0].y
else
e1.start_point.x = isect.points[0].x
e1.start_point.y = isect.points[0].y
end
else
end
end
end
end
@walls.each do |wall|
num_start = @connections[wall.baseline.start_point].length
num_end = @connections[wall.baseline.end_point].length
wall.prepare(num_start,num_end)
end
end
|
#update ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/floorplanner/wall_builder.rb', line 107
def update
@walls.each do |wall|
wall.update
@vertices.concat(wall.vertices)
@faces.concat(wall.faces)
end
$stderr.puts "Walls Vertices before: #{@vertices.length.to_s}"
@vertices.uniq!
old = @vertices.dup
@vertices = Array.new
old.each do |v|
@vertices.push(v) unless @vertices.include?(v) end
$stderr.puts "Walls Vertices: #{@vertices.length.to_s}"
$stderr.puts "Walls Faces : #{@faces.length.to_s}"
end
|
#vertex(vertex) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/floorplanner/wall_builder.rb', line 20
def vertex(vertex)
if existing = find_vertex(@base_vertices,vertex,Floorplanner.config['geom_snap'])
existing
else
@base_vertices << vertex
vertex
end
end
|
#vertices ⇒ Object
129
130
131
|
# File 'lib/floorplanner/wall_builder.rb', line 129
def vertices
@vertices
end
|
#wall(sp, ep, thickness, height) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/floorplanner/wall_builder.rb', line 29
def wall(sp, ep, thickness, height)
@connections[sp] = Array.new unless @connections.include?(sp)
@connections[ep] = Array.new unless @connections.include?(ep)
cs = Geom::Connection.new(ep, 0.0)
ce = Geom::Connection.new(sp, 0.0)
@connections[sp] << cs unless @connections[sp].include?(cs)
@connections[ep] << ce unless @connections[ep].include?(ce)
@walls << Wall3D.new(Geom::Edge.new(sp,ep), thickness, height, "wall_#{@walls.length}")
end
|
#windows ⇒ Object
137
138
139
|
# File 'lib/floorplanner/wall_builder.rb', line 137
def windows
@walls.collect{|w| w.windows}.flatten
end
|