Skip to content

Commit c88bea5

Browse files
committed
Completes model transformation tests
1 parent 9a4c20e commit c88bea5

File tree

2 files changed

+280
-23
lines changed

2 files changed

+280
-23
lines changed

src/osut/osut.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ def isFenestrated(s=None) -> bool:
12981298

12991299
return True
13001300

1301-
13021301
# ---- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---- #
13031302
# ---- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---- #
13041303
# This next set of utilities (~850 lines) help distinguish spaces that are
@@ -4606,9 +4605,9 @@ def outline(a=[], bfr=0, flat=True) -> openstudio.Point3dVector:
46064605
return oslg.negative("outline width", mth, CN.DBG, out)
46074606
if yMAX < yMIN:
46084607
return oslg.negative("outline height", mth, Cn.DBG, out)
4609-
if abs(xMIN - xMAX) < TOL:
4608+
if abs(xMIN - xMAX) < CN.TOL:
46104609
return oslg.zero("outline width", mth, CN.DBG, out)
4611-
if abs(yMIN - yMAX) < TOL:
4610+
if abs(yMIN - yMAX) < CN.TOL:
46124611
return oslg.zero("outline height", mth, CN.DBG, out)
46134612

46144613
# Generate ULC point 3D vector.
@@ -5003,45 +5002,45 @@ def realignedFace(pts=None, force=False) -> dict:
50035002
return oslg.invalid("clockwise pts", mth, 1, CN.DBG, out)
50045003

50055004
# Optionally force rotation so bounded box ends up wider than taller.
5006-
# Strongly suggested for flat surfaces like roofs (see 'sloped?').
5005+
# Strongly suggested for flat surfaces like roofs (see 'isSloped').
50075006
try:
50085007
force = bool(force)
50095008
except:
50105009
oslg.log(CN.DBG, "Ignoring force input (%s)" % mth)
50115010
force = False
50125011

5013-
o = openstudio.Point3d(0, 0, 0)
5014-
w = width(pts)
5015-
h = height(pts)
5016-
d = h if h > w else w
5017-
5018-
sgs = {}
5012+
o = openstudio.Point3d(0, 0, 0)
5013+
w = width(pts)
5014+
h = height(pts)
5015+
d = h if h > w else w
50195016
box = boundedBox(pts)
50205017

50215018
if not box:
50225019
return oslg.invalid("bounded box", mth, 0, CN.DBG, out)
50235020

5021+
sgs = []
50245022
segs = segments(box)
50255023

50265024
if not segs:
50275025
return oslg.invalid("bounded box segments", mth, 0, CN.DBG, out)
50285026

5029-
# Deterministic ID of box rotation/translation 'origin'.
5030-
for idx, sg in enumerate(segs):
5031-
sgs[sg] = {}
5032-
sgs[sg]["idx"] = idx
5033-
sgs[sg]["mid"] = midpoint(sg[0], sg[1])
5034-
sgs[sg]["l" ] = (sg[1] - sg[0]).length()
5035-
sgs[sg]["mo" ] = (sgs[sg]["mid"] - o).length()
5027+
# Deterministic identification of box rotation/translation 'origin'.
5028+
for idx, segment in enumerate(segs):
5029+
sg = {}
5030+
sg["idx"] = idx
5031+
sg["mid"] = midpoint(segment[0], segment[1])
5032+
sg["l" ] = (segment[1] - segment[0]).length()
5033+
sg["mo" ] = (sg["mid"] - o).length()
5034+
sgs.append(sg)
50365035

50375036
if isSquare(box):
5038-
sgs = dict(sorted(sgs.items(), key=lambda item: item[1]["mo"])[:2])
5037+
sgs = sorted(sgs, key=lambda x: x["mo"])[:2]
50395038
else:
5040-
sgs = dict(sorted(sgs.items(), key=lambda item: item[1]["l" ])[:2])
5041-
sgs = dict(sorted(sgs.items(), key=lambda item: item[1]["mo"])[:2])
5039+
sgs = sorted(sgs, key=lambda x: x["l" ])[:2]
5040+
sgs = sorted(sgs, key=lambda x: x["mo"])[:2]
50425041

5043-
sg0 = sgs.values[0]
5044-
sg1 = sgs.values[1]
5042+
sg0 = sgs[0]
5043+
sg1 = sgs[1]
50455044

50465045
i = sg0["idx"]
50475046

tests/test_osut.py

Lines changed: 259 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,265 @@ def test22_model_transformation(self):
23832383
pts = r * a
23842384
self.assertTrue(osut.areSame(pts, vtx))
23852385

2386-
# ... to be completed later.
2386+
output1 = osut.realignedFace(vtx)
2387+
self.assertEqual(o.status(), 0)
2388+
self.assertTrue(isinstance(output1, dict))
2389+
self.assertTrue("set" in output1)
2390+
self.assertTrue("box" in output1)
2391+
self.assertTrue("bbox" in output1)
2392+
self.assertTrue("t" in output1)
2393+
self.assertTrue("r" in output1)
2394+
self.assertTrue("o" in output1)
2395+
2396+
ubox1 = output1[ "box"]
2397+
ubbox1 = output1["bbox"]
2398+
2399+
# Realign a previously realigned surface?
2400+
output2 = osut.realignedFace(ubox1)
2401+
ubox2 = output1[ "box"]
2402+
ubbox2 = output1["bbox"]
2403+
2404+
# Realigning a previously realigned polygon has no effect (== safe).
2405+
self.assertTrue(osut.areSame(ubox1, ubox2, False))
2406+
self.assertTrue(osut.areSame(ubbox1, ubbox2, False))
2407+
2408+
bounded_area = openstudio.getArea(ubox1)
2409+
bounding_area = openstudio.getArea(ubbox1)
2410+
self.assertTrue(bounded_area)
2411+
self.assertTrue(bounding_area)
2412+
bounded_area = bounded_area.get()
2413+
bounding_area = bounding_area.get()
2414+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2415+
2416+
bounded_area = openstudio.getArea(ubox2)
2417+
bounding_area = openstudio.getArea(ubbox2)
2418+
self.assertTrue(bounded_area)
2419+
self.assertTrue(bounding_area)
2420+
bounded_area = bounded_area.get()
2421+
bounding_area = bounding_area.get()
2422+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2423+
self.assertEqual(o.status(), 0)
2424+
2425+
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
2426+
# Repeat with slight change in orientation.
2427+
vtx = openstudio.Point3dVector()
2428+
vtx.append(openstudio.Point3d( 2, 6, 0))
2429+
vtx.append(openstudio.Point3d( 1, 4, 0))
2430+
vtx.append(openstudio.Point3d( 5, 2, 0))
2431+
vtx.append(openstudio.Point3d( 6, 4, 0))
2432+
2433+
output3 = osut.realignedFace(vtx)
2434+
ubox3 = output3[ "box"]
2435+
ubbox3 = output3["bbox"]
2436+
2437+
# Realign a previously realigned surface?
2438+
output4 = osut.realignedFace(ubox3)
2439+
ubox4 = output4[ "box"]
2440+
ubbox4 = output4["bbox"]
2441+
2442+
# Realigning a previously realigned polygon has no effect (== safe).
2443+
self.assertTrue(osut.areSame(ubox1, ubox3, False))
2444+
self.assertTrue(osut.areSame(ubbox1, ubbox3, False))
2445+
self.assertTrue(osut.areSame(ubox1, ubox4, False))
2446+
self.assertTrue(osut.areSame(ubbox1, ubbox4, False))
2447+
2448+
bounded_area = openstudio.getArea(ubox3)
2449+
bounding_area = openstudio.getArea(ubbox3)
2450+
self.assertTrue(bounded_area)
2451+
self.assertTrue(bounding_area)
2452+
bounded_area = bounded_area.get()
2453+
bounding_area = bounding_area.get()
2454+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2455+
2456+
bounded_area = openstudio.getArea(ubox4)
2457+
bounding_area = openstudio.getArea(ubbox4)
2458+
self.assertTrue(bounded_area)
2459+
self.assertTrue(bounding_area)
2460+
bounded_area = bounded_area.get()
2461+
bounding_area = bounding_area.get()
2462+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2463+
self.assertEqual(o.status(), 0)
2464+
2465+
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
2466+
# Repeat with changes in vertex sequence.
2467+
# Repeat with slight change in orientation.
2468+
vtx = openstudio.Point3dVector()
2469+
vtx.append(openstudio.Point3d( 6, 4, 0))
2470+
vtx.append(openstudio.Point3d( 5, 6, 0))
2471+
vtx.append(openstudio.Point3d( 1, 4, 0))
2472+
vtx.append(openstudio.Point3d( 2, 2, 0))
2473+
2474+
output5 = osut.realignedFace(vtx)
2475+
ubox5 = output5[ "box"]
2476+
ubbox5 = output5["bbox"]
2477+
2478+
# Realign a previously realigned surface?
2479+
output6 = osut.realignedFace(ubox5)
2480+
ubox6 = output6[ "box"]
2481+
ubbox6 = output6["bbox"]
2482+
2483+
# Realigning a previously realigned polygon has no effect (== safe).
2484+
self.assertTrue(osut.areSame(ubox1, ubox5))
2485+
self.assertTrue(osut.areSame(ubox1, ubox6))
2486+
self.assertTrue(osut.areSame(ubbox1, ubbox5))
2487+
self.assertTrue(osut.areSame(ubbox1, ubbox6))
2488+
self.assertTrue(osut.areSame(ubox5, ubox6, False))
2489+
self.assertTrue(osut.areSame(ubox5, ubbox5, False))
2490+
self.assertTrue(osut.areSame(ubbox5, ubox6, False))
2491+
self.assertTrue(osut.areSame(ubox6, ubbox6, False))
2492+
2493+
bounded_area = openstudio.getArea(ubox5)
2494+
bounding_area = openstudio.getArea(ubbox5)
2495+
self.assertTrue(bounded_area)
2496+
self.assertTrue(bounding_area)
2497+
bounded_area = bounded_area.get()
2498+
bounding_area = bounding_area.get()
2499+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2500+
2501+
bounded_area = openstudio.getArea(ubox6)
2502+
bounding_area = openstudio.getArea(ubbox6)
2503+
self.assertTrue(bounded_area)
2504+
self.assertTrue(bounding_area)
2505+
bounded_area = bounded_area.get()
2506+
bounding_area = bounding_area.get()
2507+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2508+
self.assertEqual(o.status(), 0)
2509+
2510+
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
2511+
# Repeat with slight change in orientation (vertices resequenced).
2512+
vtx = openstudio.Point3dVector()
2513+
vtx.append(openstudio.Point3d( 5, 2, 0))
2514+
vtx.append(openstudio.Point3d( 6, 4, 0))
2515+
vtx.append(openstudio.Point3d( 2, 6, 0))
2516+
vtx.append(openstudio.Point3d( 1, 4, 0))
2517+
2518+
output7 = osut.realignedFace(vtx)
2519+
ubox7 = output7[ "box"]
2520+
ubbox7 = output7["bbox"]
2521+
2522+
# Realign a previously realigned surface?
2523+
output8 = osut.realignedFace(ubox7)
2524+
ubox8 = output8[ "box"]
2525+
ubbox8 = output8["bbox"]
2526+
2527+
# Realigning a previously realigned polygon has no effect (== safe).
2528+
self.assertTrue(osut.areSame(ubox1, ubox7))
2529+
self.assertTrue(osut.areSame(ubox1, ubox8))
2530+
self.assertTrue(osut.areSame(ubbox1, ubbox7))
2531+
self.assertTrue(osut.areSame(ubbox1, ubbox8))
2532+
self.assertTrue(osut.areSame(ubox5, ubox7, False))
2533+
self.assertTrue(osut.areSame(ubbox5, ubbox7, False))
2534+
self.assertTrue(osut.areSame(ubox5, ubox5, False))
2535+
self.assertTrue(osut.areSame(ubbox5, ubbox8, False))
2536+
2537+
bounded_area = openstudio.getArea(ubox7)
2538+
bounding_area = openstudio.getArea(ubbox7)
2539+
self.assertTrue(bounded_area)
2540+
self.assertTrue(bounding_area)
2541+
bounded_area = bounded_area.get()
2542+
bounding_area = bounding_area.get()
2543+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2544+
2545+
bounded_area = openstudio.getArea(ubox8)
2546+
bounding_area = openstudio.getArea(ubbox8)
2547+
self.assertTrue(bounded_area)
2548+
self.assertTrue(bounding_area)
2549+
bounded_area = bounded_area.get()
2550+
bounding_area = bounding_area.get()
2551+
self.assertAlmostEqual(bounded_area, bounding_area, places=2)
2552+
self.assertEqual(o.status(), 0)
2553+
2554+
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
2555+
# Aligned box (wide).
2556+
vtx = openstudio.Point3dVector()
2557+
vtx.append(openstudio.Point3d( 2, 4, 0))
2558+
vtx.append(openstudio.Point3d( 2, 2, 0))
2559+
vtx.append(openstudio.Point3d( 6, 2, 0))
2560+
vtx.append(openstudio.Point3d( 6, 4, 0))
2561+
2562+
output9 = osut.realignedFace(vtx)
2563+
ubox9 = output9[ "box"]
2564+
ubbox9 = output9["bbox"]
2565+
2566+
output10 = osut.realignedFace(vtx, True) # no impact
2567+
ubox10 = output10[ "box"]
2568+
ubbox10 = output10["bbox"]
2569+
self.assertTrue(osut.areSame(ubox9, ubox10))
2570+
self.assertTrue(osut.areSame(ubbox9, ubbox10))
2571+
2572+
# ... vs aligned box (narrow).
2573+
vtx = openstudio.Point3dVector()
2574+
vtx.append(openstudio.Point3d( 2, 6, 0))
2575+
vtx.append(openstudio.Point3d( 2, 2, 0))
2576+
vtx.append(openstudio.Point3d( 4, 2, 0))
2577+
vtx.append(openstudio.Point3d( 4, 6, 0))
2578+
2579+
output11 = osut.realignedFace(vtx)
2580+
ubox11 = output11[ "box"]
2581+
ubbox11 = output11["bbox"]
2582+
2583+
output12 = osut.realignedFace(vtx, True) # narrow, now wide
2584+
ubox12 = output12[ "box"]
2585+
ubbox12 = output12["bbox"]
2586+
self.assertFalse(osut.areSame(ubox11, ubox12))
2587+
self.assertFalse(osut.areSame(ubbox11, ubbox12))
2588+
self.assertTrue(osut.areSame(ubox12, ubox10))
2589+
self.assertTrue(osut.areSame(ubbox12, ubbox10))
2590+
2591+
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
2592+
# Irregular surface (parallelogram).
2593+
vtx = openstudio.Point3dVector()
2594+
vtx.append(openstudio.Point3d( 4, 0, 0))
2595+
vtx.append(openstudio.Point3d( 6, 4, 0))
2596+
vtx.append(openstudio.Point3d( 3, 8, 0))
2597+
vtx.append(openstudio.Point3d( 1, 4, 0))
2598+
2599+
output13 = osut.realignedFace(vtx)
2600+
uset13 = output13[ "set"]
2601+
ubox13 = output13[ "box"]
2602+
ubbox13 = output13["bbox"]
2603+
2604+
# Pre-isolate bounded box (preferable with irregular surfaces).
2605+
box = osut.boundedBox(vtx)
2606+
output14 = osut.realignedFace(box)
2607+
uset14 = output14[ "set"]
2608+
ubox14 = output14[ "box"]
2609+
ubbox14 = output14["bbox"]
2610+
self.assertTrue(osut.areSame(uset14, ubox14))
2611+
self.assertTrue(osut.areSame(uset14, ubbox14))
2612+
self.assertFalse(osut.areSame(uset13, uset14))
2613+
self.assertFalse(osut.areSame(ubox13, ubox14))
2614+
self.assertFalse(osut.areSame(ubbox13, ubbox14))
2615+
2616+
rset14 = output14["r"] * (output14["t"] * uset14)
2617+
self.assertTrue(osut.areSame(box, rset14))
2618+
2619+
# --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- #
2620+
# Bounded box from an irregular, non-convex, "J"-shaped corridor roof.
2621+
# This is a VERY EXPENSIVE method when dealing with such HIGHLY
2622+
# CONVOLUTED polygons !
2623+
# vtx = openstudio.Point3dVector()
2624+
# vtx.append(openstudio.Point3d( 0.0000000, 0.0000, 3.658))
2625+
# vtx.append(openstudio.Point3d( 0.0000000, 35.3922, 3.658))
2626+
# vtx.append(openstudio.Point3d( 7.4183600, 35.3922, 3.658))
2627+
# vtx.append(openstudio.Point3d( 7.8150800, 35.2682, 3.658))
2628+
# vtx.append(openstudio.Point3d( 13.8611000, 35.2682, 3.658))
2629+
# vtx.append(openstudio.Point3d( 13.8611000, 38.9498, 3.658))
2630+
# vtx.append(openstudio.Point3d( 7.8150800, 38.9498, 3.658))
2631+
# vtx.append(openstudio.Point3d( 7.8150800, 38.6275, 3.658))
2632+
# vtx.append(openstudio.Point3d( -0.0674713, 38.6275, 3.658))
2633+
# vtx.append(openstudio.Point3d( -0.0674713, 48.6247, 3.658))
2634+
# vtx.append(openstudio.Point3d( -2.5471900, 48.6247, 3.658))
2635+
# vtx.append(openstudio.Point3d( -2.5471900, 38.5779, 3.658))
2636+
# vtx.append(openstudio.Point3d( -6.7255500, 38.5779, 3.658))
2637+
# vtx.append(openstudio.Point3d( -2.5471900, 2.7700, 3.658))
2638+
# vtx.append(openstudio.Point3d(-14.9024000, 2.7700, 3.658))
2639+
# vtx.append(openstudio.Point3d(-14.9024000, 0.0000, 3.658))
2640+
#
2641+
# bbx = osut.boundedBox(vtx)
2642+
# self.assertTrue(osut.fits(bbx, vtx))
2643+
# if o.logs(): print(mod1.logs())
2644+
self.assertEqual(o.status(), 0)
23872645

23882646
def test23_fits_overlaps(self):
23892647
o = osut.oslg

0 commit comments

Comments
 (0)