Class: Topolys::Face
Overview
Instance Attribute Summary collapse
Attributes inherited from Object
#attributes, #children, #id, #parents
Instance Method Summary
collapse
Methods inherited from Object
#debug, #hash, link, #link_child, #link_parent, #short_id, #short_name, #to_s, unlink, #unlink_child, #unlink_parent
Constructor Details
#initialize(outer, holes) ⇒ Face
Initializes a Face object
Throws if outer or holes are incorrect type or if holes have incorrect winding
1216
1217
1218
1219
1220
1221
1222
|
# File 'lib/topolys/model.rb', line 1216
def initialize(outer, holes)
super()
@outer = outer
@holes = holes
recalculate
end
|
Instance Attribute Details
#holes ⇒ Array
1207
1208
1209
|
# File 'lib/topolys/model.rb', line 1207
def holes
@holes
end
|
#outer ⇒ Wire
1204
1205
1206
|
# File 'lib/topolys/model.rb', line 1204
def outer
@outer
end
|
Instance Method Details
#child_class ⇒ Object
1265
1266
1267
|
# File 'lib/topolys/model.rb', line 1265
def child_class
Wire
end
|
#parent_class ⇒ Object
1261
1262
1263
|
# File 'lib/topolys/model.rb', line 1261
def parent_class
Shell
end
|
#recalculate ⇒ Object
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
|
# File 'lib/topolys/model.rb', line 1231
def recalculate
super()
@children.reverse_each {|child| Object.unlink(self, child)}
Object.link(self, outer)
@holes.each {|hole| Object.link(self, hole)}
normal = @outer.normal
@holes.each do |hole|
raise "Hole does not have correct winding, #{hole.normal.dot(normal)}" if hole.normal.dot(normal) < 1 - Topolys.normal_tol
end
plane = @outer.plane
@holes.each do |hole|
hole.points.each do |point|
raise "Point not on plane" if (point - plane.project(point)).magnitude > Topolys.planar_tol
end
end
end
|
#shared_outer_edges(other) ⇒ Object
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
|
# File 'lib/topolys/model.rb', line 1277
def shared_outer_edges(other)
return nil unless other.is_a?(Face)
result = []
@outer.directed_edges.each do |de|
other.outer.directed_edges.each do |other_de|
result << de.edge if de.edge.id == other_de.edge.id
end
end
return result
end
|
1269
1270
1271
|
# File 'lib/topolys/model.rb', line 1269
def shells
@parents
end
|
1224
1225
1226
1227
1228
1229
|
# File 'lib/topolys/model.rb', line 1224
def to_json
result = super
result[:outer] = @outer.id
result[:holes] = @holes.map { |h| h.id }
return result
end
|
1273
1274
1275
|
# File 'lib/topolys/model.rb', line 1273
def wires
@children
end
|