def test_load_throws_if_file_not_exists(): model = an.Model() with pytest.raises(RuntimeError) as ex: model.load('invalid_filename') assert_equal('File not found', str(ex.value))
def test_bspline_3d(): curve_geometry = an.NurbsCurveGeometry3D( degree=4, nb_poles=8, is_rational=False, ) curve_geometry.knots = [0, 0, 0, 0, 32.9731425998736, 65.9462851997473, 98.9194277996209, 131.892570399495, 131.892570399495, 131.892570399495, 131.892570399495] curve_geometry.poles = [ [ 0, -25, - 5], [-15, -15, 0], [ 5, - 5, - 3], [ 15, -15, 3], [ 25, 0, 6], [ 15, 15, 6], [- 5, - 5, - 3], [-25, 15, 4], ] model = an.Model() curve_geometry_ptr = model.add(curve_geometry) curve = an.Curve3D(curve_geometry_ptr, curve_geometry.domain) # point_at assert_array_almost_equal( curve.point_at(t=65.9462851997), [18.8888888889, -6.1111111111, 4.1666666667], )
def test_integration_points_curve_2d(): model = an.Model() model.add_array(r"""[ { "key": "TestData", "type": "NurbsCurveGeometry2D", "degree": 1, "nb_poles": 2, "knots": [-1, 0, 1], "poles": [[-1, 0], [0, 0], [2, 0]] } ]""") curve = model.get(0).data integration_points = an.integration_points( degree=2, curve=curve, ) assert_array_almost_equal( integration_points, [(-0.788675, 0.5), (-0.211325, 0.5), (0.211325, 1.0), (0.788675, 1.0)], )
def test_integration_points_surface_3d(): model = an.Model() model.add_array(r"""[ { "type": "NurbsSurfaceGeometry3D", "degree_u": 2, "degree_v": 1, "knots_u": [0.0,0.0,5.0,10.0,10.0], "knots_v": [0.0,20.0], "nb_poles_u": 4, "nb_poles_v": 2, "poles": [[0.0,0.0,0.0],[0.0,10.0,0.0],[2.00900107273569,0.0,0.0],[4.0763840660860486,7.8742350860349752,0.0],[7.0668900221629363,0.0,0.0],[12.011764418152659,7.1771412301834934,0.0],[10.0,0.0,0.0],[15.0,10.0,0.0]] } ]""") surface = model.get(0).data integration_points = an.integration_points( degree=2, surface=surface, ) assert_array_almost_equal( integration_points, [(1.0566243270259357, 4.226497308103743, 11.759664385301264), (1.0566243270259357, 15.773502691896258, 17.31405070545194), (3.9433756729740645, 4.226497308103743, 10.883683768349144), (3.9433756729740645, 15.773502691896258, 15.000698744981156), (6.0566243270259355, 4.226497308103743, 10.603123001336892), (6.0566243270259355, 15.773502691896258, 12.7153914474524), (8.943375672974064, 4.226497308103743, 11.952054522910226), (8.943375672974064, 15.773502691896258, 9.795549688797168)], )
def test_load_array(data): model = an.Model() model.add_array(data) key, data = model.get(0) assert_equal(key, 'TestData') assert_equal(type(data), an.NurbsCurveGeometry2D)
def test_load(): model = an.Model() model.load(path('data/model.ibra')) key, data = model.get(0) assert_equal(key, 'TestData') assert_equal(type(data), an.NurbsCurveGeometry2D)
def test_bspline_3d(): surface_geometry = an.NurbsSurfaceGeometry3D( degree_u=2, degree_v=1, nb_poles_u=4, nb_poles_v=3, is_rational=False, ) surface_geometry.knots_u = [0, 0, 7.5, 15, 15] surface_geometry.knots_v = [0, 10, 20] surface_geometry.poles = [ [-10.0, - 5.0, -1.0 ], [-12.0, 3.0, 3.0 ], [- 9.0, 11.0, -0.0701928417], [- 5.0, - 3.0, 1.0 ], [- 6.0, 4.0, -2.0 ], [- 5.0, 7.0, 0.9298071583], [ 0.0, - 4.0, -1.0 ], [ 1.0, 6.0, 5.0 ], [ 0.0, 13.0, -0.2350184214], [ 4.0, - 2.0, 0.0 ], [ 5.0, 4.0, -1.0 ], [ 5.0, 11.0, 0.7649815786], ] model = an.Model() surface_geometry_ptr = model.add(surface_geometry) surface = an.Surface3D(surface_geometry_ptr) # point_at assert_array_almost_equal( surface.point_at(u=12, v=5), [1.46, 0.96, 0.9], ) # derivarives_at assert_array_almost_equal( surface.derivatives_at(u=12, v=5, order=2), [[1.46, 0.96, 0.9], [0.96, 0.0266666667, -0.2666666667], [0.084, 0.832, 0.276], [0.0355555556, -0.0088888889, -0.1333333333], [0.0106666667, -0.048, -0.064], [0, 0, 0]], )
def run(self, config, job, data, log): model = an.Model() log.info(f'Read "{self.path}"...') model.load(self.path) data['cad_model'] = model # output nb_faces = len(model.of_type('BrepFace')) nb_edges = len(model.of_type('BrepEdge')) log.info(f'{nb_faces} faces') log.info(f'{nb_edges} edges')
def test_to_string(curve): model = an.Model() model.add(key='TestData', data=curve) actual = model.to_string() expected = r"""[ { "key": "TestData", "type": "NurbsCurveGeometry2D", "degree": 1, "nb_poles": 2, "knots": [0.0,1.0], "poles": [[1.0,2.0],[3.0,4.0]] } ]""" for actual_line, expected_line in zip(actual.split('\n'), expected.split('\n')): assert_equal(actual_line.strip(), expected_line.strip())
def test_point_inversion(self): model = an.Model() model.load( f'{os.path.dirname(__file__)}/data/point_on_surface_projection.ibra' ) surface = model.of_type('NurbsSurfaceGeometry3D')[0].data projection = an.PointOnSurfaceProjection3D(surface) test_data = [ [0.2486685842, 0.1107439772], [0.9978910512, 0.875821514], [0.0830195928, 0.9259765381], [0.9496291005, 0.1502956968], [0.459878301, 0.6225033205], [0.6025333179, 0.9861121243], [0.0790516166, 0.5709693747], [0.5655969403, 0.2574736384], [0.8305452102, 0.5624009979], [0.2794794688, 0.8097236998], [0.3071577155, 0.3822328865], [0.99964868, 0.4057108985], [0.0189992101, 0.2765154416], [0.0056710457, 0.0347536937], [0.7897584256, 0.8313703019], [0.7195281758, 0.1178902761], [0.4422092407, 0.0883118692], [0.6658555305, 0.4627695477], [0.5076745905, 0.8196537363], [0.2832733436, 0.6378145738], [0.0645325822, 0.7572020105], [0.9879030846, 0.6847038878], [0.7960193063, 0.3109410034], [0.6945010543, 0.6643853852], [0.8336644866, 0.0037464825], [0.3930552445, 0.9678212548], [0.4785460939, 0.3808379352], [0.585713005, 0.0070576593], [0.3991026969, 0.2632817497], [0.2006969681, 0.2421369582], [0.1202849104, 0.4221172297], [0.7358854449, 0.9698849781], [0.5188882311, 0.5018097253], [0.3654126839, 0.5201963845], [0.6403577298, 0.8467138102], [0.8726223264, 0.9882953218], [0.0928173764, 0.1633056552], [0.155525548, 0.028770891], [0.0010793009, 0.456353415], [0.5686607461, 0.7125619164], [0.1982382905, 0.7190583882], [0.3281335357, 0.0049134241], [0.8250263221, 0.6903648873], [0.2025081111, 0.9819264952], [0.2204824454, 0.5096595127], [0.3834477823, 0.8546278755], [0.9842980774, 0.0390799376], [0.1078386875, 0.3153865423], [0.3720683969, 0.7303910846], [0.9586810097, 0.5417624263], [0.6905896192, 0.2880027598], [0.5518418474, 0.1284805062], [0.7797412704, 0.4522544888], [0.9001546897, 0.7999264513], [0.7019192277, 0.5565699151], [0.8618938363, 0.8969601173], [0.573701815, 0.3725593828], [0.5645628416, 0.6001849126], [0.9691815544, 0.2581378097], [0.2934454783, 0.2084521582], [0.5663407671, 0.890895538], [0.8255418832, 0.1905749553], [0.9205142534, 0.4522520338], [0.4010180167, 0.4240173988], [0.6520043102, 0.7641253019], [0.4829338433, 0.2314186642], [0.6469415439, 0.1985799857], [0.0100815608, 0.8321075117], [0.2825933291, 0.9272068771], [0.2162422287, 0.4111952472], [0.1691770848, 0.6298445815], [0.9101820793, 0.3544982711], [0.7672993754, 0.7465931879], [0.9772622413, 0.7692543193], [0.0181493168, 0.3759801157], [0.7127572883, 0.0072015384], [0.5138806088, 0.9528929917], [0.8881267998, 0.633660035], [0.1209032033, 0.8468105364], [0.3423240503, 0.1053561797], [0.0060057966, 0.1696525231], [0.8454230683, 0.0981951589], [0.1910913443, 0.8742888891], [0.9726746664, 0.9913883214], [0.714155909, 0.3804675184], [0.8380541009, 0.3771821253], [0.4770630204, 0.6988195776], [0.1394817876, 0.4965714307], [0.2955455749, 0.7173407975], [0.3722430087, 0.3385346254], [0.8603301383, 0.259464834], [0.0317961453, 0.6580847188], [0.0028120549, 0.9568088497], [0.4066441252, 0.1674200367], [0.6186872817, 0.3124124684], [0.001451293, 0.5436467522], [0.6059298895, 0.5078425922], [0.6547791262, 0.0598361939], [0.1788401213, 0.1605233313], [0.460314065, 0.8863533544], ] for expected_uv in test_data: expected_point = surface.point_at(*expected_uv) success, u, v, point = projection.get(expected_point) self.assertTrue(success) assert_almost_equal([u, v], expected_uv) assert_almost_equal(point, expected_point)
def test_init_empty(): model = an.Model() assert_equal(model.nb_entries, 0)
def dome(): model = an.Model() model.load(f'{os.path.dirname(__file__)}/data/dome.ibra') return model.of_type('NurbsSurfaceGeometry3D')[0][1]