Skip to content

Commit 838fb59

Browse files
committed
Fixes overlap method - initial tests only
1 parent 9f41e35 commit 838fb59

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

src/osut/osut.py

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3978,7 +3978,7 @@ def fits(p1=None, p2=None, entirely=False) -> bool:
39783978
return True
39793979

39803980

3981-
def overlaps(p1=None, p2=None, flat=False) -> bool:
3981+
def overlap(p1=None, p2=None, flat=False) -> bool:
39823982
"""Returns intersection of overlapping polygons, empty if non intersecting.
39833983
If the optional 3rd argument is left as False, the 2nd polygon may only
39843984
overlap if it shares the 3D plane equation of the 1st one. If the 3rd
@@ -4011,19 +4011,17 @@ def overlaps(p1=None, p2=None, flat=False) -> bool:
40114011

40124012
if not isinstance(flat, bool): flat = False
40134013

4014+
cw1 = isClockwise(p01)
4015+
t = None
4016+
40144017
if shareXYZ(p01, "z"):
4015-
t = None
4016-
a1 = list(p01)
4017-
a2 = list(p02)
4018-
cw1 = isClockwise(p01)
4018+
a1 = list(p01)
4019+
a2 = list(p02)
40194020
if cw1: a1.reverse()
4020-
if flat: a2 = flatten(a2)
4021+
if flat: a2 = list(flatten(a2))
40214022

40224023
if not shareXYZ(a2, "z"):
40234024
return invalid("points 2", mth, 2, CN.DBG, face)
4024-
4025-
cw2 = isClockwise(a2)
4026-
if cw2: a2.reverse()
40274025
else:
40284026
t = openstudio.Transformation.alignFace(p01)
40294027
a1 = t.inverse() * p01
@@ -4033,8 +4031,8 @@ def overlaps(p1=None, p2=None, flat=False) -> bool:
40334031
if not shareXYZ(a2, "z"):
40344032
return invalid("points 2", mth, 2, CN.DBG, face)
40354033

4036-
cw2 = isClockwise(a2)
4037-
if cw2: a2.reverse()
4034+
cw2 = isClockwise(a2)
4035+
if cw2: a2.reverse()
40384036

40394037
# Return either (transformed) polygon if one fits into the other.
40404038
p1t = p01
@@ -4044,11 +4042,11 @@ def overlaps(p1=None, p2=None, flat=False) -> bool:
40444042
p2t = to_p3Dv(t * a2)
40454043
else:
40464044
if cw1:
4047-
if cw2: a2.reverse()
4048-
p2t = to_p3Dv(a2)
4049-
else:
40504045
if not cw2: a2.reverse()
4051-
p2t = to_p3Dv(a2)
4046+
else:
4047+
if cw2: a2.reverse()
4048+
4049+
p2t = to_p3Dv(a2)
40524050

40534051
if fits(a1, a2): return p1t
40544052
if fits(a2, a1): return p2t
@@ -4063,11 +4061,12 @@ def overlaps(p1=None, p2=None, flat=False) -> bool:
40634061
area2 = area2.get()
40644062
a1.reverse()
40654063
a2.reverse()
4064+
40664065
union = openstudio.join(a1, a2, CN.TOL2)
40674066
if not union: return face
40684067

40694068
union = union.get()
4070-
area = OpenStudio.getArea(union)
4069+
area = openstudio.getArea(union)
40714070
if not area: return face
40724071

40734072
area = area.get()
@@ -4085,12 +4084,33 @@ def overlaps(p1=None, p2=None, flat=False) -> bool:
40854084
res1 = res.polygon1()
40864085
if not res1: return face
40874086

4087+
res1 = list(res1)
40884088
res1.reverse()
40894089
if t: res1 = t * res1
40904090

40914091
return to_p3Dv(res1)
40924092

40934093

4094+
def doesOverlap(p1=None, p2=None, flat=False):
4095+
"""Determines whether OpenStudio polygons overlap.
4096+
4097+
Args:
4098+
p1 (openstudio.Point3d):
4099+
1st OpenStudio vector of 3D points.
4100+
p2 (openstudio.Point3d):
4101+
2nd OpenStudio vector of 3D points.
4102+
flat (bool):
4103+
Whether to first project the 2nd set onto the 1st set plane.
4104+
4105+
Returns:
4106+
bool: Whether polygons overlap (or fit).
4107+
False: If invalid input (see logs).
4108+
"""
4109+
if overlap(p1, p2, flat): return True
4110+
4111+
return False
4112+
4113+
40944114
def facets(spaces=[], boundary="all", type="all", sides=[]) -> list:
40954115
"""Returns an array of OpenStudio space surfaces or subsurfaces that match
40964116
criteria, e.g. exterior, north-east facing walls in hotel "lobby". Note

tests/test_osut.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,8 +2444,9 @@ def test23_fits_overlaps(self):
24442444
self.assertTrue(res1_m2)
24452445
res1_m2 = res1_m2.get()
24462446
self.assertAlmostEqual(res1_m2, delta, places=2)
2447-
# self.assertTrue(osut.overlaps(p1a, p2a))
2448-
# self.assertEqual(o.status(), 0)
2447+
# olap = osut.overlap(p1a, p2a)
2448+
self.assertTrue(osut.doesOverlap(p1a, p2a))
2449+
self.assertEqual(o.status(), 0)
24492450

24502451
def test24_triangulation(self):
24512452
o = osut.oslg

0 commit comments

Comments
 (0)