def test_rotate_xy(): """Test the Shade rotate_xy method.""" pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2)) plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2)) shade = Shade('RectangleShade', Face3D(pts, plane)) origin_1 = Point3D(1, 1, 0) test_1 = shade.duplicate() test_1.rotate_xy(180, origin_1) assert test_1.geometry[0].x == pytest.approx(1, rel=1e-3) assert test_1.geometry[0].y == pytest.approx(1, rel=1e-3) assert test_1.geometry[0].z == pytest.approx(2, rel=1e-3) assert test_1.geometry[2].x == pytest.approx(0, rel=1e-3) assert test_1.geometry[2].y == pytest.approx(0, rel=1e-3) assert test_1.geometry[2].z == pytest.approx(2, rel=1e-3) test_2 = shade.duplicate() test_2.rotate_xy(90, origin_1) assert test_2.geometry[0].x == pytest.approx(1, rel=1e-3) assert test_2.geometry[0].y == pytest.approx(1, rel=1e-3) assert test_1.geometry[0].z == pytest.approx(2, rel=1e-3) assert test_2.geometry[2].x == pytest.approx(0, rel=1e-3) assert test_2.geometry[2].y == pytest.approx(2, rel=1e-3) assert test_1.geometry[2].z == pytest.approx(2, rel=1e-3)
def test_rotate(): """Test the shade rotate method.""" pts = (Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(2, 2, 2), Point3D(0, 2, 2)) plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2)) shade = Shade('RectangleShade', Face3D(pts, plane)) origin = Point3D(0, 0, 0) axis = Vector3D(1, 0, 0) test_1 = shade.duplicate() test_1.rotate(axis, 180, origin) assert test_1.geometry[0].x == pytest.approx(0, rel=1e-3) assert test_1.geometry[0].y == pytest.approx(0, rel=1e-3) assert test_1.geometry[0].z == pytest.approx(-2, rel=1e-3) assert test_1.geometry[2].x == pytest.approx(2, rel=1e-3) assert test_1.geometry[2].y == pytest.approx(-2, rel=1e-3) assert test_1.geometry[2].z == pytest.approx(-2, rel=1e-3) assert shade.area == test_1.area assert len(shade.vertices) == len(test_1.vertices) test_2 = shade.duplicate() test_2.rotate(axis, 90, origin) assert test_2.geometry[0].x == pytest.approx(0, rel=1e-3) assert test_2.geometry[0].y == pytest.approx(-2, rel=1e-3) assert test_2.geometry[0].z == pytest.approx(0, rel=1e-3) assert test_2.geometry[2].x == pytest.approx(2, rel=1e-3) assert test_2.geometry[2].y == pytest.approx(-2, rel=1e-3) assert test_2.geometry[2].z == pytest.approx(2, rel=1e-3) assert shade.area == test_2.area assert len(shade.vertices) == len(test_2.vertices)
def test_duplicate(): """Test what happens to radiance properties when duplicating a Shade.""" verts = [ Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 1, 3), Point3D(0, 1, 3) ] foliage = Glass.from_single_transmittance('Foliage', 0.2) shade_original = Shade('tree', Face3D(verts)) shade_dup_1 = shade_original.duplicate() assert shade_original.properties.radiance.host is shade_original assert shade_dup_1.properties.radiance.host is shade_dup_1 assert shade_original.properties.radiance.host is not shade_dup_1.properties.radiance.host assert shade_original.properties.radiance.modifier == \ shade_dup_1.properties.radiance.modifier shade_dup_1.properties.radiance.modifier = foliage assert shade_original.properties.radiance.modifier != \ shade_dup_1.properties.radiance.modifier shade_dup_2 = shade_dup_1.duplicate() assert shade_dup_1.properties.radiance.modifier == \ shade_dup_2.properties.radiance.modifier shade_dup_2.properties.radiance.modifier = None assert shade_dup_1.properties.radiance.modifier != \ shade_dup_2.properties.radiance.modifier
def reflect_state_shades(): """Check to be sure that dynamic shades are reflected with their parent.""" pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2)) ap = Shade('TestShade', Face3D(pts)) pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2, 0), Point3D(0, 2, 0)) shade = StateGeometry('RectangleShade', Face3D(pts_1)) tint1 = RadianceShadeState(shades=[shade]) ap.properties.radiance.dynamic_group_identifier = 'DeciduousTrees' ap.properties.radiance.states = [tint1] tint1.gen_geos_from_tmtx_thickness(0.05) new_ap = ap.duplicate() origin_1 = Point3D(1, 0, 2) normal_1 = Vector3D(1, 0, 0) plane_1 = Plane(normal_1, origin_1) new_ap.reflect(plane_1) new_shd = new_ap.properties.radiance.states[0].shades[0] assert new_shd.geometry[-1].x == pytest.approx(1, rel=1e-3) assert new_shd.geometry[-1].y == pytest.approx(1, rel=1e-3) assert new_shd.geometry[-1].z == pytest.approx(2, rel=1e-3) assert new_shd.geometry[1].x == pytest.approx(0, rel=1e-3) assert new_shd.geometry[1].y == pytest.approx(2, rel=1e-3) assert new_shd.geometry[1].z == pytest.approx(2, rel=1e-3)
def test_reflect(): """Test the Shade reflect method.""" pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2)) plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2)) shade = Shade('RectangleShade', Face3D(pts, plane)) origin_1 = Point3D(1, 0, 2) origin_2 = Point3D(0, 0, 2) normal_1 = Vector3D(1, 0, 0) normal_2 = Vector3D(-1, -1, 0).normalize() plane_1 = Plane(normal_1, origin_1) plane_2 = Plane(normal_2, origin_2) plane_3 = Plane(normal_2, origin_1) test_1 = shade.duplicate() test_1.reflect(plane_1) assert test_1.geometry[-1].x == pytest.approx(1, rel=1e-3) assert test_1.geometry[-1].y == pytest.approx(1, rel=1e-3) assert test_1.geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_1.geometry[1].x == pytest.approx(0, rel=1e-3) assert test_1.geometry[1].y == pytest.approx(2, rel=1e-3) assert test_1.geometry[1].z == pytest.approx(2, rel=1e-3) test_1 = shade.duplicate() test_1.reflect(plane_2) assert test_1.geometry[-1].x == pytest.approx(-1, rel=1e-3) assert test_1.geometry[-1].y == pytest.approx(-1, rel=1e-3) assert test_1.geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_1.geometry[1].x == pytest.approx(-2, rel=1e-3) assert test_1.geometry[1].y == pytest.approx(-2, rel=1e-3) assert test_1.geometry[1].z == pytest.approx(2, rel=1e-3) test_2 = shade.duplicate() test_2.reflect(plane_3) assert test_2.geometry[-1].x == pytest.approx(0, rel=1e-3) assert test_2.geometry[-1].y == pytest.approx(0, rel=1e-3) assert test_2.geometry[-1].z == pytest.approx(2, rel=1e-3) assert test_2.geometry[1].x == pytest.approx(-1, rel=1e-3) assert test_2.geometry[1].y == pytest.approx(-1, rel=1e-3) assert test_2.geometry[1].z == pytest.approx(2, rel=1e-3)
def test_shade_duplicate(): """Test the duplication of shade objects.""" pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0)) shd_1 = Shade('Test Shade', Face3D(pts)) shd_2 = shd_1.duplicate() assert shd_1 is not shd_2 for i, pt in enumerate(shd_1.vertices): assert pt == shd_2.vertices[i] assert shd_1.name == shd_2.name shd_2.move(Vector3D(0, 1, 0)) for i, pt in enumerate(shd_1.vertices): assert pt != shd_2.vertices[i]
def test_scale(): """Test the shade scale method.""" pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2)) plane = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 2)) shade = Shade('Rectangle Shade', Face3D(pts, plane)) new_shd = shade.duplicate() new_shd.scale(2) assert new_shd.geometry[0] == Point3D(2, 2, 4) assert new_shd.geometry[1] == Point3D(4, 2, 4) assert new_shd.geometry[2] == Point3D(4, 4, 4) assert new_shd.geometry[3] == Point3D(2, 4, 4) assert new_shd.area == shade.area * 2 ** 2 assert new_shd.perimeter == shade.perimeter * 2 assert new_shd.normal == shade.normal
def test_duplicate(): """Test what happens to energy properties when duplicating a Shade.""" verts = [ Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(1, 0, 3), Point3D(0, 0, 3) ] shade_original = Shade('overhang', Face3D(verts)) shade_dup_1 = shade_original.duplicate() light_shelf = ShadeConstruction('Light Shelf', 0.5, 0.5, True) bright_light_shelf = ShadeConstruction('Bright Light Shelf', 0.7, 0.7, True) fritted_glass_trans = ScheduleRuleset.from_constant_value( 'Fritted Glass', 0.5, schedule_types.fractional) assert shade_original.properties.energy.host is shade_original assert shade_dup_1.properties.energy.host is shade_dup_1 assert shade_original.properties.energy.host is not \ shade_dup_1.properties.energy.host assert shade_original.properties.energy.construction == \ shade_dup_1.properties.energy.construction shade_dup_1.properties.energy.construction = light_shelf assert shade_original.properties.energy.construction != \ shade_dup_1.properties.energy.construction shade_dup_2 = shade_dup_1.duplicate() assert shade_dup_1.properties.energy.construction == \ shade_dup_2.properties.energy.construction shade_dup_2.properties.energy.construction = bright_light_shelf assert shade_dup_1.properties.energy.construction != \ shade_dup_2.properties.energy.construction assert shade_original.properties.energy.transmittance_schedule == \ shade_dup_1.properties.energy.transmittance_schedule shade_dup_1.properties.energy.transmittance_schedule = fritted_glass_trans assert shade_original.properties.energy.transmittance_schedule != \ shade_dup_1.properties.energy.transmittance_schedule shade_dup_3 = shade_dup_1.duplicate() assert shade_dup_1.properties.energy.transmittance_schedule == \ shade_dup_3.properties.energy.transmittance_schedule shade_dup_3.properties.energy.transmittance_schedule = None assert shade_dup_1.properties.energy.transmittance_schedule != \ shade_dup_3.properties.energy.transmittance_schedule
def test_move(): """Test the shade move method.""" pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2, 0), Point3D(0, 2, 0)) plane_1 = Plane(Vector3D(0, 0, 1), Point3D(0, 0, 0)) shade = Shade('Rectangle Shade', Face3D(pts_1, plane_1)) vec_1 = Vector3D(2, 2, 2) new_shd = shade.duplicate() new_shd.move(vec_1) assert new_shd.geometry[0] == Point3D(2, 2, 2) assert new_shd.geometry[1] == Point3D(4, 2, 2) assert new_shd.geometry[2] == Point3D(4, 4, 2) assert new_shd.geometry[3] == Point3D(2, 4, 2) assert new_shd.normal == shade.normal assert shade.area == new_shd.area assert shade.perimeter == new_shd.perimeter
def test_set_states(): """Test the setting of states on a Shade.""" pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0)) shd = Shade('TreeTrunk', Face3D(pts)) shd1 = StateGeometry.from_vertices( 'tree_foliage1', [[0, 0, 5], [2, 0, 5], [2, 2, 5], [0, 2, 5]]) shd2 = StateGeometry.from_vertices( 'tree_foliage2', [[0, 0, 5], [-2, 0, 5], [-2, 2, 5], [0, 2, 5]]) trans1 = Glass.from_single_transmittance('TreeTrans1', 0.5) trans2 = Glass.from_single_transmittance('TreeTrans2', 0.27) trans3 = Glass.from_single_transmittance('TreeTrans3', 0.14) trans4 = Glass.from_single_transmittance('TreeTrans4', 0.01) tr1 = RadianceShadeState(trans1) tr2 = RadianceShadeState(trans2) tr3 = RadianceShadeState(trans3) tr4 = RadianceShadeState(trans4) states = (tr1, tr2, tr3, tr4) tr3.add_shade(shd1) with pytest.raises(AssertionError): tr4.add_shades([shd1, shd2]) tr4.add_shades([shd1.duplicate(), shd2]) with pytest.raises(AssertionError): shd.properties.radiance.states = states shd.properties.radiance.dynamic_group_identifier = 'DeciduousTrees' shd.properties.radiance.states = states for state in shd.properties.radiance.states: assert state.parent.identifier == 'TreeTrunk' new_shd = shd.duplicate() assert shd.properties.radiance.dynamic_group_identifier == \ new_shd.properties.radiance.dynamic_group_identifier == 'DeciduousTrees' assert len(new_shd.properties.radiance.states) == 4 for i, state in enumerate(new_shd.properties.radiance.states): assert state.modifier.identifier == 'TreeTrans{}'.format(i + 1) assert len(new_shd.properties.radiance.states[2].shades) == 1 assert len(new_shd.properties.radiance.states[3].shades) == 2
def scale_state_shades(): """Check to be sure that dynamic shades are scaled with their parent.""" pts = (Point3D(1, 1, 2), Point3D(2, 1, 2), Point3D(2, 2, 2), Point3D(1, 2, 2)) ap = Shade('TestShade', Face3D(pts)) pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2, 0), Point3D(0, 2, 0)) shade = StateGeometry('RectangleShade', Face3D(pts_1)) tint1 = RadianceShadeState(shades=[shade]) ap.properties.radiance.dynamic_group_identifier = 'DeciduousTrees' ap.properties.radiance.states = [tint1] tint1.gen_geo_from_vmtx_offset(0.05) tint1.gen_geo_from_dmtx_offset(0.1) new_ap = ap.duplicate() new_ap.scale(2) new_shd = new_ap.properties.radiance.states[0].shades[0] assert new_shd.geometry[0] == Point3D(2, 2, 4) assert new_shd.geometry[1] == Point3D(4, 2, 4) assert new_shd.geometry[2] == Point3D(4, 4, 4) assert new_shd.geometry[3] == Point3D(2, 4, 4)
def move_state_shades(): """Check to be sure that dynamic shades are moved with their parent.""" pts = (Point3D(0, 0, 0), Point3D(0, 0, 3), Point3D(1, 0, 3), Point3D(1, 0, 0)) ap = Shade('TestShade', Face3D(pts)) pts_1 = (Point3D(0, 0, 0), Point3D(2, 0, 0), Point3D(2, 2, 0), Point3D(0, 2, 0)) shade = StateGeometry('RectangleShade', Face3D(pts_1)) tint1 = RadianceShadeState(shades=[shade]) ap.properties.radiance.dynamic_group_identifier = 'DeciduousTrees' ap.properties.radiance.states = [tint1] tint1.gen_geos_from_tmtx_thickness(0.05) vec_1 = Vector3D(2, 2, 2) new_ap = ap.duplicate() new_ap.move(vec_1) new_shd = new_ap.properties.radiance.states[0].shades[0] assert new_shd.geometry[0] == Point3D(2, 2, 2) assert new_shd.geometry[1] == Point3D(4, 2, 2) assert new_shd.geometry[2] == Point3D(4, 4, 2) assert new_shd.geometry[3] == Point3D(2, 4, 2)