Skip to content

Commit d36561c

Browse files
committed
Tweaks 'overlap' (more testing needed)
1 parent 82028fb commit d36561c

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

src/osut/osut.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,8 +4049,6 @@ def overlap(p1=None, p2=None, flat=False) -> bool:
40494049
delta = area1 + area2 - area
40504050

40514051
if area > CN.TOL:
4052-
if round(area, 2) == round(area1, 2): return face
4053-
if round(area, 2) == round(area2, 2): return face
40544052
if round(delta, 2) == 0: return face
40554053

40564054
res = openstudio.intersect(a1, a2, CN.TOL)
@@ -4582,6 +4580,7 @@ def medialBox(pts=None) -> openstudio.Point3dVector:
45824580
if not pts: return bkp
45834581

45844582
if isClockwise(pts):
4583+
pts = list(pts)
45854584
pts.reverse()
45864585
pts = p3Dv(pts)
45874586

@@ -4614,8 +4613,9 @@ def medialBox(pts=None) -> openstudio.Point3dVector:
46144613
box.append(mpoints[0])
46154614
box.append(mpoints[1])
46164615
box.append(plane.project(mpoints[1]))
4616+
46174617
box = list(nonCollinears(box))
4618-
if box.size != 4: return bkp
4618+
if len(box) != 4: return bkp
46194619

46204620
if isClockwise(box): box.reverse()
46214621

@@ -4677,7 +4677,7 @@ def boundedBox(pts=None) -> openstudio.Point3dVector:
46774677
for sg in segments(pts):
46784678
m0 = midpoint(sg[0], sg[1])
46794679

4680-
for seg in getSegments(pts):
4680+
for seg in segments(pts):
46814681
p1 = seg[0]
46824682
p2 = seg[1]
46834683
if areSame(p1, sg[0]): continue
@@ -4781,9 +4781,9 @@ def boundedBox(pts=None) -> openstudio.Point3dVector:
47814781
aire = area
47824782
box = out
47834783

4784-
if aire > CN.TOL:
4785-
if t: box = p3Dv(t * box)
4786-
return box
4784+
if aire > CN.TOL:
4785+
if t: box = p3Dv(t * box)
4786+
return box
47874787

47884788
# PATH G : Medial box, triangulated approach.
47894789
aire = 0

tests/test_osut.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2624,10 +2624,86 @@ def test23_fits_overlaps(self):
26242624
pts = osut.nonCollinears(ceiling.vertices(), 3)
26252625
box01 = osut.triadBox(pts)
26262626
box11 = osut.boundedBox(ceiling)
2627-
print(o.logs())
26282627
self.assertTrue(osut.areSame(box01, box11))
26292628
self.assertTrue(osut.fits(box01, ceiling))
26302629

2630+
pts = osut.nonCollinears(roof.vertices(), 3)
2631+
box02 = osut.medialBox(pts)
2632+
box12 = osut.boundedBox(roof)
2633+
self.assertTrue(osut.areSame(box02, box12))
2634+
self.assertTrue(osut.fits(box02, roof))
2635+
2636+
box03 = osut.triadBox(pts)
2637+
self.assertFalse(osut.areSame(box03, box12))
2638+
self.assertEqual(o.status(), 0)
2639+
2640+
# For parallel surfaces, OSut's 'overlap' output is consistent
2641+
# regardless of the sequence of arguments. Here, floor and ceiling are
2642+
# mirrored - the former counterclockwise, the latter clockwise. The
2643+
# returned overlap conserves the vertex winding of the first surface.
2644+
self.assertTrue(osut.areParallel(floor, ceiling))
2645+
olap1 = osut.overlap(floor, ceiling)
2646+
olap2 = osut.overlap(ceiling, floor)
2647+
self.assertTrue(osut.areSame(floor.vertices(), olap1))
2648+
self.assertTrue(osut.areSame(ceiling.vertices(), olap2))
2649+
2650+
# When surfaces aren't parallel, 'overlap' remains somewhat consistent
2651+
# if both share a common edge. Here, the flat soffit shares an edge
2652+
# with the sloped roof. The projection of the soffit neatly fits onto
2653+
# the roof, yet the generated overlap will obviously be distorted with
2654+
# respect to the original soffit vertices. Nonetheless, the shared
2655+
# vertices/edge(s) would be preserved.
2656+
olap1 = osut.overlap(soffit, roof, True)
2657+
olap2 = osut.overlap(roof, soffit, True)
2658+
self.assertTrue(osut.areParallel(olap1, soffit))
2659+
self.assertFalse(osut.areParallel(olap1, roof))
2660+
self.assertTrue(osut.areParallel(olap2, roof))
2661+
self.assertFalse(osut.areParallel(olap2, soffit))
2662+
self.assertEqual(len(olap1), 4)
2663+
self.assertEqual(len(olap2), 4)
2664+
area1 = openstudio.getArea(olap1)
2665+
area2 = openstudio.getArea(olap2)
2666+
self.assertTrue(area1)
2667+
self.assertTrue(area2)
2668+
area1 = area1.get()
2669+
area2 = area2.get()
2670+
self.assertGreater(abs(area1 - area2), TOL)
2671+
pl1 = openstudio.Plane(olap1)
2672+
pl2 = openstudio.Plane(olap2)
2673+
n1 = pl1.outwardNormal()
2674+
n2 = pl2.outwardNormal()
2675+
dt1 = soffit.plane().outwardNormal().dot(n1)
2676+
dt2 = roof.plane().outwardNormal().dot(n2)
2677+
self.assertAlmostEqual(dt1, 1, places=2)
2678+
self.assertAlmostEqual(dt2, 1, places=2)
2679+
2680+
# When surfaces are neither parallel nor share any edges (e.g. sloped roof
2681+
# vs horizontal floor), the generated overlap is more likely to hold extra
2682+
# vertices, depending on which surface it is cast onto.
2683+
olap1 = osut.overlap(floor, roof, True)
2684+
olap2 = osut.overlap(roof, floor, True)
2685+
self.assertTrue(osut.areParallel(olap1, floor))
2686+
self.assertFalse(osut.areParallel(olap1, roof))
2687+
self.assertTrue(osut.areParallel(olap2, roof))
2688+
self.assertFalse(osut.areParallel(olap2, floor))
2689+
self.assertEqual(len(olap1), 3)
2690+
self.assertEqual(len(olap2), 5)
2691+
area1 = openstudio.getArea(olap1)
2692+
area2 = openstudio.getArea(olap2)
2693+
self.assertTrue(area1)
2694+
self.assertTrue(area2)
2695+
area1 = area1.get()
2696+
area2 = area2.get()
2697+
self.assertGreater(area2 - area1, TOL)
2698+
pl1 = openstudio.Plane(olap1)
2699+
pl2 = openstudio.Plane(olap2)
2700+
n1 = pl1.outwardNormal()
2701+
n2 = pl2.outwardNormal()
2702+
dt1 = floor.plane().outwardNormal().dot(n1)
2703+
dt2 = roof.plane().outwardNormal().dot(n2)
2704+
self.assertAlmostEqual(dt1, 1, places=2)
2705+
self.assertAlmostEqual(dt2, 1, places=2)
2706+
26312707
del(model)
26322708
self.assertEqual(o.clean(), DBG)
26332709

0 commit comments

Comments
 (0)