@@ -3368,7 +3368,222 @@ def test26_ulc_blc(self):
33683368 # [70, 45, 0]
33693369 # [ 0, 45, 0]
33703370
3371- # def test27_polygon_attributes(self):
3371+ def test27_polygon_attributes (self ):
3372+ o = osut .oslg
3373+ self .assertEqual (o .status (), 0 )
3374+ self .assertEqual (o .reset (INF ), INF )
3375+ self .assertEqual (o .level (), INF )
3376+ self .assertEqual (o .status (), 0 )
3377+
3378+ # 2x points (not a polygon).
3379+ vtx = openstudio .Point3dVector ()
3380+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3381+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3382+
3383+ v = osut .poly (vtx )
3384+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3385+ self .assertFalse (v )
3386+ self .assertTrue (o .is_error ())
3387+ self .assertEqual (len (o .logs ()), 1 )
3388+ self .assertTrue ("non-collinears < 3" in o .logs ()[0 ]["message" ])
3389+ self .assertEqual (o .clean (), INF )
3390+
3391+ # 3x non-unique points (not a polygon).
3392+ vtx = openstudio .Point3dVector ()
3393+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3394+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3395+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3396+
3397+ v = osut .poly (vtx )
3398+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3399+ self .assertFalse (v )
3400+ self .assertTrue (o .is_error ())
3401+ self .assertEqual (len (o .logs ()), 1 )
3402+ self .assertTrue ("non-collinears < 3" in o .logs ()[0 ]["message" ])
3403+ self .assertEqual (o .clean (), INF )
3404+
3405+ # 4th non-planar point (not a polygon).
3406+ vtx = openstudio .Point3dVector ()
3407+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3408+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3409+ vtx .append (openstudio .Point3d (10 , 0 ,10 ))
3410+ vtx .append (openstudio .Point3d ( 0 ,10 ,10 ))
3411+
3412+ v = osut .poly (vtx )
3413+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3414+ self .assertFalse (v )
3415+ self .assertTrue (o .is_error ())
3416+ self .assertEqual (len (o .logs ()), 1 )
3417+ self .assertTrue ("plane" in o .logs ()[0 ]["message" ])
3418+ self .assertEqual (o .clean (), INF )
3419+
3420+ # 3x unique points (a valid polygon).
3421+ vtx = openstudio .Point3dVector ()
3422+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3423+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3424+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3425+
3426+ v = osut .poly (vtx )
3427+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3428+ self .assertEqual (len (v ), 3 )
3429+ self .assertEqual (o .status (), 0 )
3430+
3431+ # 4th collinear point (collinear permissive).
3432+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3433+ v = osut .poly (vtx )
3434+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3435+ self .assertEqual (len (v ), 4 )
3436+ self .assertEqual (o .status (), 0 )
3437+
3438+ # Intersecting points, e.g. a 'bowtie' (not a valid Openstudio polygon).
3439+ vtx = openstudio .Point3dVector ()
3440+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3441+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3442+ vtx .append (openstudio .Point3d (10 , 0 ,10 ))
3443+ vtx .append (openstudio .Point3d ( 0 ,10 , 0 ))
3444+
3445+ v = osut .poly (vtx )
3446+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3447+ self .assertFalse (v )
3448+ self .assertTrue (o .is_error ())
3449+ self .assertEqual (len (o .logs ()), 1 )
3450+ self .assertTrue ("Empty 'plane' (osut.poly)" in o .logs ()[0 ]["message" ])
3451+ self .assertEqual (o .clean (), INF )
3452+
3453+ # Ensure uniqueness & OpenStudio's counterclockwise ULC sequence.
3454+ vtx = openstudio .Point3dVector ()
3455+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3456+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3457+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3458+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3459+
3460+ v = osut .poly (vtx , False , True , False , False , "ulc" )
3461+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3462+ self .assertEqual (len (v ), 3 )
3463+ self .assertTrue (osut .areSame (vtx [0 ], v [0 ]))
3464+ self .assertTrue (osut .areSame (vtx [1 ], v [1 ]))
3465+ self .assertTrue (osut .areSame (vtx [2 ], v [2 ]))
3466+ self .assertEqual (o .status (), 0 )
3467+
3468+ # Ensure strict non-collinearity (ULC).
3469+ vtx = openstudio .Point3dVector ()
3470+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3471+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3472+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3473+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3474+
3475+ v = osut .poly (vtx , False , False , True , False , "ulc" )
3476+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3477+ self .assertEqual (len (v ), 3 )
3478+ self .assertTrue (osut .areSame (vtx [0 ], v [0 ]))
3479+ self .assertTrue (osut .areSame (vtx [1 ], v [1 ]))
3480+ self .assertTrue (osut .areSame (vtx [3 ], v [2 ]))
3481+ self .assertEqual (o .status (), 0 )
3482+
3483+ # Ensuring strict non-collinearity also ensures uniqueness (ULC).
3484+ vtx = openstudio .Point3dVector ()
3485+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3486+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3487+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3488+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3489+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3490+
3491+ v = osut .poly (vtx , False , False , True , False , "ulc" )
3492+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3493+ self .assertEqual (len (v ), 3 )
3494+ self .assertTrue (osut .areSame (vtx [0 ], v [0 ]))
3495+ self .assertTrue (osut .areSame (vtx [1 ], v [1 ]))
3496+ self .assertTrue (osut .areSame (vtx [4 ], v [2 ]))
3497+ self .assertEqual (o .status (), 0 )
3498+
3499+ # Check for (valid) convexity.
3500+ vtx = openstudio .Point3dVector ()
3501+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3502+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3503+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3504+
3505+ v = osut .poly (vtx , True )
3506+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3507+ self .assertEqual (len (v ), 3 )
3508+ self .assertEqual (o .status (), 0 )
3509+
3510+ # Check for (invalid) convexity.
3511+ vtx .append (openstudio .Point3d (1 , 0 , 1 ))
3512+ v = osut .poly (vtx , True )
3513+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3514+ self .assertFalse (v )
3515+ self .assertEqual (o .status (), 0 )
3516+
3517+ # 2nd check for (valid) convexity (with collinear points).
3518+ vtx = openstudio .Point3dVector ()
3519+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3520+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3521+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3522+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3523+
3524+ v = osut .poly (vtx , True , False , False , False , "ulc" )
3525+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3526+ self .assertEqual (len (v ), 4 )
3527+ self .assertTrue (osut .areSame (vtx [0 ], v [0 ]))
3528+ self .assertTrue (osut .areSame (vtx [1 ], v [1 ]))
3529+ self .assertTrue (osut .areSame (vtx [2 ], v [2 ]))
3530+ self .assertTrue (osut .areSame (vtx [3 ], v [3 ]))
3531+ self .assertEqual (o .status (), 0 )
3532+
3533+ # 2nd check for (invalid) convexity (with collinear points).
3534+ vtx .append (openstudio .Point3d ( 1 , 0 , 1 ))
3535+ v = osut .poly (vtx , True , False , False , False , "ulc" )
3536+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3537+ self .assertFalse (v )
3538+ self .assertEqual (o .status (), 0 )
3539+
3540+ # 3rd check for (valid) convexity (with collinear points), yet returned
3541+ # 3D points vector become 'aligned' & clockwise.
3542+ vtx = openstudio .Point3dVector ()
3543+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3544+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3545+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3546+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3547+
3548+ v = osut .poly (vtx , True , False , False , True , "cw" )
3549+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3550+ self .assertEqual (len (v ), 4 )
3551+ self .assertTrue (osut .shareXYZ (v , "z" , 0 ))
3552+ self .assertTrue (osut .isClockwise (v ))
3553+ self .assertEqual (o .status (), 0 )
3554+
3555+ # Ensure returned vector remains in original sequence (if unaltered).
3556+ vtx = openstudio .Point3dVector ()
3557+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3558+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3559+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3560+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3561+
3562+ v = osut .poly (vtx , True , False , False , False , "no" )
3563+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3564+ self .assertEqual (len (v ), 4 )
3565+ self .assertTrue (osut .areSame (vtx [0 ], v [0 ]))
3566+ self .assertTrue (osut .areSame (vtx [1 ], v [1 ]))
3567+ self .assertTrue (osut .areSame (vtx [2 ], v [2 ]))
3568+ self .assertTrue (osut .areSame (vtx [3 ], v [3 ]))
3569+ self .assertFalse (osut .isClockwise (v ))
3570+ self .assertEqual (o .status (), 0 )
3571+
3572+ # Sequence of returned vector if altered (avoid collinearity).
3573+ vtx = openstudio .Point3dVector ()
3574+ vtx .append (openstudio .Point3d ( 0 , 0 ,10 ))
3575+ vtx .append (openstudio .Point3d ( 0 , 0 , 0 ))
3576+ vtx .append (openstudio .Point3d (10 , 0 , 0 ))
3577+ vtx .append (openstudio .Point3d (20 , 0 , 0 ))
3578+
3579+ v = osut .poly (vtx , True , False , True , False , "no" )
3580+ self .assertTrue (isinstance (v , openstudio .Point3dVector ))
3581+ self .assertEqual (len (v ), 3 )
3582+ self .assertTrue (osut .areSame (vtx [0 ], v [0 ]))
3583+ self .assertTrue (osut .areSame (vtx [1 ], v [1 ]))
3584+ self .assertTrue (osut .areSame (vtx [3 ], v [2 ]))
3585+ self .assertFalse (osut .isClockwise (v ))
3586+ self .assertEqual (o .status (), 0 )
33723587
33733588 # def test28_subsurface_insertions(self):
33743589
0 commit comments