Class: Topolys::Face
Overview
Wire
Instance Attribute Summary collapse
-
#holes ⇒ Array
readonly
Array of Wire.
-
#outer ⇒ Wire
readonly
Outer polygon.
Attributes inherited from Object
#attributes, #children, #id, #parents
Instance Method Summary collapse
- #child_class ⇒ Object
-
#initialize(outer, holes) ⇒ Face
constructor
Initializes a Face object.
- #parent_class ⇒ Object
- #recalculate ⇒ Object
- #shared_outer_edges(other) ⇒ Object
- #shells ⇒ Object
- #to_json ⇒ Object
- #wires ⇒ Object
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 (readonly)
Returns Array of Wire.
1207 1208 1209 |
# File 'lib/topolys/model.rb', line 1207 def holes @holes end |
#outer ⇒ Wire (readonly)
Returns outer polygon.
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() # unlink from any previous wires @children.reverse_each {|child| Object.unlink(self, child)} # link with current wires Object.link(self, outer) @holes.each {|hole| Object.link(self, hole)} # recompute cached properties and check invariants # check that holes have same normal as outer 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 # check that holes are on same plane as outer 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 # TODO: check that holes are contained within outer 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| # next if de.id == other.de result << de.edge if de.edge.id == other_de.edge.id end end return result end |
#shells ⇒ Object
1269 1270 1271 |
# File 'lib/topolys/model.rb', line 1269 def shells @parents end |
#to_json ⇒ Object
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 |
#wires ⇒ Object
1273 1274 1275 |
# File 'lib/topolys/model.rb', line 1273 def wires @children end |