def test_bounding_box(edged_curve): answer_min = geom.Point3D([0.1, 0.2, 0.3]) answer_max = geom.Point3D([8.7, 9.4, 6.7]) if edged_curve.bounding_box().min() != answer_min: raise ValueError("[Test] Wrong computation of bounding box (min)") if edged_curve.bounding_box().max() != answer_max: raise ValueError("[Test] Wrong computation of bounding box (max)")
def test_bounding_box(point_set): answer_min = geom.Point3D([0.0, 0.0, -1.2]) if point_set.bounding_box().min() != answer_min: raise ValueError("[Test] Wrong computation of bounding box (min)") answer_max = geom.Point3D([2.3, 9.4, 6.7]) if point_set.bounding_box().max() != answer_max: raise ValueError("[Test] Wrong computation of bounding box (max)")
def test_bounding_box(polyhedral_solid): answer_min = geom.Point3D([0.1, 0.2, 0.3]) answer_max = geom.Point3D([9.3, 9.4, 6.7]) if polyhedral_solid.bounding_box().min() != answer_min: raise ValueError("[Test] Wrong computation of bounding box (min)") if polyhedral_solid.bounding_box().max() != answer_max: raise ValueError("[Test] Wrong computation of bounding box (max)")
def test_edge_requests(edged_curve, builder): if not edged_curve.edge_barycenter(0).inexact_equal( geom.Point3D([4.8, 7.3, 6.5]), 1e-15): raise ValueError("[Test] Edge barycenter is not correct") p0 = builder.create_point(geom.Point3D([1, 1, 1])) p1 = builder.create_point(geom.Point3D([1, 4, -3])) if edged_curve.edge_length(builder.create_edge_with_vertices(p0, p1)) != 5: raise ValueError("[Test] Edge length is not correct")
def test_permutation(point_set, builder): builder.permute_vertices([2, 0, 3, 1]) if point_set.point(2) != geom.Point3D(): raise ValueError( "[Test] Point coordinates have not been correctly permuted") if point_set.point(0) != geom.Point3D([2.3, 5.0, -1.2]): raise ValueError( "[Test] Point coordinates have not been correctly permuted")
def test_create_vertices( surface, builder ): builder.create_point( geom.Point3D( [ 0.1, 0.2, 0.3 ] ) ) builder.create_point( geom.Point3D( [ 2.1, 9.4, 6.7 ] ) ) builder.create_point( geom.Point3D( [ 7.5, 5.2, 6.3 ] ) ) builder.create_point( geom.Point3D( [ 8.1, 1.4, 4.7 ] ) ) builder.create_point( geom.Point3D( [ 4.7, 2.1, 1.3 ] ) ) if surface.nb_vertices() != 5: raise ValueError( "[Test] TriangulatedSurface should have 5 vertices" )
def test_create_vertices(edged_curve, builder): builder.create_point(geom.Point3D([0.1, 0.2, 0.3])) builder.create_point(geom.Point3D([2.1, 9.4, 6.7])) if edged_curve.nb_vertices() != 2: raise ValueError("[Test] EdgedCurve should have 2 vertices") builder.create_vertices(2) builder.set_point(2, geom.Point3D([7.5, 5.2, 6.3])) builder.set_point(3, geom.Point3D([8.7, 1.4, 4.7])) if edged_curve.nb_vertices() != 4: raise ValueError("[Test] EdgedCurve should have 4 vertices")
def test_point_plane_distance(): a = geom.Point3D([0.0, 0.0, 0.0]) b = geom.Point3D([1.0, 0.0, 0.0]) c = geom.Point3D([1.0, 1.0, 0.0]) triangle = geom.Triangle3D(a, b, c) plane = triangle.plane() q1 = geom.Point3D([0.5, 0.5, 1]) distance, closest_point = geom.point_plane_distance(q1, plane) answer = geom.Point3D([0.5, 0.5, 0.0]) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_plane_distance with query point q1") distance, closest_point = geom.point_plane_signed_distance(q1, plane) answer = geom.Point3D([0.5, 0.5, 0.0]) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_plane_signed_distance with query point q1" ) q2 = geom.Point3D([0.5, 0.5, -1]) distance, closest_point = geom.point_plane_distance(q2, plane) answer = geom.Point3D([0.5, 0.5, 0.0]) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_plane_distance with query point q2") distance, closest_point = geom.point_plane_signed_distance(q2, plane) answer = geom.Point3D([0.5, 0.5, 0.0]) if distance != -1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_plane_signed_distance with query point q2" )
def test_comparison(): p = geom.Point3D([2, 1.0, 2.6]) p2 = p if p != p2: raise ValueError("[Test] Points should be equal") P = geom.Point2D([15, 2.6]) P2 = geom.Point2D([16, 2.6]) if P == P2: raise ValueError("[Test] Points should be different") p_epsilon = geom.Point3D([2.0000000001, 1, 2.6]) if not p.inexact_equal(p_epsilon, 0.0001): raise ValueError("[Test] Points should be almost equal")
def test_create_vertices(point_set, builder): builder.create_point(geom.Point3D([0.1, 0.2, 0.3])) builder.create_point(geom.Point3D([2.1, 9.4, 6.7])) if point_set.nb_vertices() != 2: raise ValueError("[Test] PointSet should have 2 vertices") builder.create_vertices(2) if point_set.nb_vertices() != 4: raise ValueError("[Test] PointSet should have 4 vertices") if point_set.point(2) != geom.Point3D(): raise ValueError("[Test] Default coordinates are not correct") builder.set_point(2, geom.Point3D([2.3, 5.0, -1.2])) if point_set.point(2) != geom.Point3D([2.3, 5.0, -1.2]): raise ValueError( "[Test] Point coordinates have not been correctly set")
def test_barycenters(): polyhedral_solid = mesh.PolyhedralSolid3D.create() builder = mesh.PolyhedralSolidBuilder3D.create(polyhedral_solid) o = 0.0 a = 0.6 b = 2.4 c = 1.8 builder.create_point(geom.Point3D([o, o, o])) builder.create_point(geom.Point3D([a, o, o])) builder.create_point(geom.Point3D([o, o, c])) builder.create_point(geom.Point3D([o, b, o])) builder.create_point(geom.Point3D([a, b, o])) builder.create_point(geom.Point3D([o, b, c])) builder.create_polyhedron( [0, 1, 2, 3, 4, 5], [[0, 1, 2], [0, 1, 4, 3], [1, 2, 5, 4], [0, 3, 5, 2], [3, 4, 5]]) answer_facet_barycenter = geom.Point3D([a / 3., 0, c / 3.]) if polyhedral_solid.facet_barycenter(0) != answer_facet_barycenter: raise ValueError( "[Test] PolyhedralSolid facet_barycenter is not correct") answer_polyhedron_barycenter = geom.Point3D([a / 3., 0.5 * b, c / 3.]) if polyhedral_solid.polyhedron_barycenter( 0) != answer_polyhedron_barycenter: raise ValueError( "[Test] PolyhedralSolid polyhedron barycenter is not correct")
def test_operators(): p = geom.Point3D() p.set_value(0, 2) p.set_value(1, 1) p.set_value(2, 2.6) p2 = p answer = geom.Point3D([4, 2, 5.2]) if p + p2 != answer: raise ValueError("[Test] Points should be equal") if p * 2 != answer: raise ValueError("[Test] Points should be equal") if p - p2 != geom.Point3D(): raise ValueError("[Test] Points should be equal") if answer / 2 != p: raise ValueError("[Test] Points should be equal")
def test_delete_vertex(polyhedral_solid, builder): to_delete = [False] * polyhedral_solid.nb_vertices() to_delete[0] = True builder.delete_vertices(to_delete) if polyhedral_solid.nb_vertices() != 7: raise ValueError("[Test] PolyhedralSolid should have 7 vertices") answer = geom.Point3D([2.1, 9.4, 6.7]) if polyhedral_solid.point(0) != answer: raise ValueError( "[Test] PolyhedralSolid vertex coordinates are not correct") if polyhedral_solid.nb_polyhedra() != 2: raise ValueError("[Test] PolyhedralSolid should have 2 polyhedra") if polyhedral_solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 3)) != 0: raise ValueError( "[Test] PolyhedralSolid adjacent index is not correct") if polyhedral_solid.nb_facets() != 7: raise ValueError("[Test] PolyhedralSolid should have 7 facets") if polyhedral_solid.nb_edges() != 9: raise ValueError("[Test] PolyhedralSolid should have 9 edges") attribute = polyhedral_solid.edge_attribute_manager().find_attribute_uint( "test") if attribute.value(0) != 8: raise ValueError( "[Test] Wrong value for attribute on edge 0 after vertex deletion") if attribute.value(1) != 7: raise ValueError( "[Test] Wrong value for attribute on edge 1 after vertex deletion")
def test_delete_vertex(edged_curve, builder): to_delete = [False] * edged_curve.nb_vertices() to_delete[0] = True builder.delete_vertices(to_delete) if edged_curve.nb_vertices() != 3: raise ValueError("[Test] EdgedCurve should have 3 vertices") answer = geom.Point3D([2.1, 9.4, 6.7]) if edged_curve.point(0) != answer: raise ValueError( "[Test] EdgedCurve vertex coordinates are not correct") if edged_curve.nb_edges() != 2: raise ValueError("[Test] EdgedCurve should have 2 edges") edges_around_0 = edged_curve.edges_around_vertex(0) if len(edges_around_0) != 1: raise ValueError("[Test] edges_around_0 should have 1 edge") if edges_around_0[0].edge_id != 1: raise ValueError("[Test] edges_around_0 has wrong value") if edges_around_0[0].vertex_id != 0: raise ValueError("[Test] edges_around_0 has wrong value") edges_around_2 = edged_curve.edges_around_vertex(2) if len(edges_around_2) != 1: raise ValueError("[Test] edges_around_2 should have 1 edge") if edges_around_2[0].edge_id != 0: raise ValueError("[Test] edges_around_2 has wrong value") if edges_around_2[0].vertex_id != 0: raise ValueError("[Test] edges_around_2 has wrong value")
def test_polygon_vertex_normal(): polygonal_surface = mesh.PolygonalSurface3D.create() builder = mesh.PolygonalSurfaceBuilder3D.create( polygonal_surface ) builder.create_point( geom.Point3D( [ 0.0, 0.0, 0.0 ] ) ) builder.create_point( geom.Point3D( [ 1.0, 0.0, 0.0 ] ) ) builder.create_point( geom.Point3D( [ 0.0, 1.0, 1.0 ] ) ) builder.create_point( geom.Point3D( [ 0.0, -1.0, 1.0 ] ) ) builder.create_polygon( [ 0, 1, 2 ] ) builder.create_polygon( [ 0, 3, 1 ] ) builder.compute_polygon_adjacencies() answer = geom.Vector3D( [ 0., 0., 1. ] ) if polygonal_surface.polygon_vertex_normal( 0 ) != answer: raise ValueError( "[Test] PolygonalSurface polygon vertex normal is not correct" )
def test_delete_vertex( polygonal_surface, builder ): to_delete = [False] * polygonal_surface.nb_vertices() to_delete[0] = True builder.delete_vertices( to_delete ) if polygonal_surface.nb_vertices() != 6: raise ValueError( "[Test] PolygonalSurface should have 6 vertices" ) answer = geom.Point3D( [ 2.1, 9.4, 6.7 ] ) if polygonal_surface.point( 2 ) != answer: raise ValueError( "[Test] PolygonalSurface vertex coordinates are not correct" ) if polygonal_surface.nb_polygons() != 2: raise ValueError( "[Test] PolygonalSurface should have 2 polygons" ) if polygonal_surface.polygon_adjacent( mesh.PolygonEdge( 1, 2 ) ): raise ValueError( "[Test] PolygonalSurface adjacent index is not correct" ) builder.edges_builder().delete_isolated_edges() if polygonal_surface.edges().nb_edges() != 7: raise ValueError( "[Test] PolygonalSurface should have 7 edges" ) attribute = polygonal_surface.edges().edge_attribute_manager().find_attribute_uint( "test" ) if attribute.value( 4 ) != 6: raise ValueError( "[Test] Update of edge attributes after " "vertex deletion is not correct (value of 4)" ) if attribute.value( 5 ) != 7: raise ValueError( "[Test] Update of edge attributes after " "vertex deletion is not correct (value of 5)" ) if attribute.value( 6 ) != 8: raise ValueError( "[Test] Update of edge attributes after " "vertex deletion is not correct (value of 6)" )
def test_polygon_normal(): polygonal_surface = mesh.PolygonalSurface3D.create() builder = mesh.PolygonalSurfaceBuilder3D.create( polygonal_surface ) a = 6.0 b = 8.0 c = 4.0 builder.create_point( geom.Point3D( [ 0.0, 0.0, 0.0 ] ) ) builder.create_point( geom.Point3D( [ a, 0.0, 0.0 ] ) ) builder.create_point( geom.Point3D( [ b, c, 0.0 ] ) ) builder.create_point( geom.Point3D( [ 0.0, c, 0.0 ] ) ) builder.create_polygon( [ 0, 1, 2, 3 ] ) answer = geom.Vector3D( [ 0., 0., 1. ] ) if polygonal_surface.polygon_normal( 0 ) != answer: raise ValueError( "[Test] PolygonalSurface polygon normal is not correct" )
def test_normals(): polyhedral_solid = mesh.PolyhedralSolid3D.create() builder = mesh.PolyhedralSolidBuilder3D.create(polyhedral_solid) o = 0.0 a = 0.6 b = 2.4 c = 1.8 builder.create_point(geom.Point3D([o, b, -c])) builder.create_point(geom.Point3D([o, o, o])) builder.create_point(geom.Point3D([a, o, o])) builder.create_point(geom.Point3D([a, b, o])) builder.create_point(geom.Point3D([o, b, o])) builder.create_point(geom.Point3D([o, b, c])) builder.create_polyhedron( [0, 1, 2, 3, 4], [[1, 2, 0], [1, 2, 3, 4], [2, 3, 0], [3, 4, 0], [4, 1, 0]]) builder.create_polyhedron( [5, 1, 4, 3, 2], [[1, 2, 0], [1, 2, 3, 4], [2, 3, 0], [3, 4, 0], [4, 1, 0]]) answer_facet_normal = geom.Point3D([0, 0, 1]) if polyhedral_solid.polyhedron_facet_normal(mesh.PolyhedronFacet( 0, 1)) != answer_facet_normal: raise ValueError( "[Test] PolyhedralSolid polyhedron_facet_normal is not correct (0, 1)" ) if polyhedral_solid.polyhedron_facet_normal(mesh.PolyhedronFacet( 1, 1)) != answer_facet_normal * -1.: raise ValueError( "[Test] PolyhedralSolid polyhedron_facet_normal is not correct )1, 1)" )
def test_delete_vertex(point_set, builder): to_delete = [False] * point_set.nb_vertices() to_delete[1] = True builder.delete_vertices(to_delete) if point_set.nb_vertices() != 3: raise ValueError("[Test] PointSet should have 3 vertices") answer = geom.Point3D([2.1, 9.4, 6.7]) if point_set.point(2) != answer: raise ValueError("[Test] PointSet vertex coordinates are not correct")
def test_create_vertices(polyhedral_solid, builder): builder.create_point(geom.Point3D([0.1, 0.2, 0.3])) builder.create_point(geom.Point3D([2.1, 9.4, 6.7])) builder.create_point(geom.Point3D([7.5, 5.2, 6.3])) builder.create_point(geom.Point3D([8.1, 1.4, 4.7])) builder.create_point(geom.Point3D([4.7, 2.1, 1.3])) builder.create_point(geom.Point3D([9.3, 5.3, 6.7])) builder.create_point(geom.Point3D([7.5, 4.2, 2.8])) builder.create_point(geom.Point3D([2.2, 3.3, 4.4])) if polyhedral_solid.nb_vertices() != 8: raise ValueError("[Test] PolyhedralSolid should have 8 vertices")
def test_create_vertices( polygonal_surface, builder ): builder.create_point( geom.Point3D( [ 0.1, 0.2, 0.3 ] ) ) builder.create_point( geom.Point3D( [ 2.1, 9.4, 6.7 ] ) ) builder.create_point( geom.Point3D( [ 7.5, 5.2, 6.3 ] ) ) builder.create_point( geom.Point3D( [ 8.1, 1.4, 4.7 ] ) ) builder.create_point( geom.Point3D( [ 4.7, 2.1, 1.3 ] ) ) builder.create_point( geom.Point3D( [ 9.3, 5.3, 6.7 ] ) ) builder.create_point( geom.Point3D( [ 7.5, 4.2, 2.8 ] ) ) if polygonal_surface.nb_vertices() != 7: raise ValueError( "[Test] PolygonalSurface should have 7 vertices" )
def test_clone(point_set): point_set2 = point_set.clone() if point_set2.nb_vertices() != 3: raise ValueError("[Test] PointSet2 should have 3 vertices") attribute = point_set2.vertex_attribute_manager().find_attribute_bool( "test") if attribute.value(0) != True: raise ValueError("[Test] PointSet2 attribute value should be true") answer = geom.Point3D([2.1, 9.4, 6.7]) if point_set2.point(2) != answer: raise ValueError("[Test] PointSet2 vertex coordinates are not correct")
def create_cube(x_min, y_min, z_min, x_max, y_max, z_max): cube = model.BRep() builder = model.BRepBuilder(cube) point0 = geometry.Point3D([x_min, y_min, z_min]) point1 = geometry.Point3D([x_max, y_min, z_min]) point2 = geometry.Point3D([x_min, y_max, z_min]) point3 = geometry.Point3D([x_max, y_max, z_min]) point4 = geometry.Point3D([x_min, y_min, z_max]) point5 = geometry.Point3D([x_max, y_min, z_max]) point6 = geometry.Point3D([x_min, y_max, z_max]) point7 = geometry.Point3D([x_max, y_max, z_max]) corner0 = _create_corner(cube, builder, point0) corner1 = _create_corner(cube, builder, point1) corner2 = _create_corner(cube, builder, point2) corner3 = _create_corner(cube, builder, point3) corner4 = _create_corner(cube, builder, point4) corner5 = _create_corner(cube, builder, point5) corner6 = _create_corner(cube, builder, point6) corner7 = _create_corner(cube, builder, point7) line0 = _create_line(cube, builder, corner0, corner1) line1 = _create_line(cube, builder, corner1, corner3) line2 = _create_line(cube, builder, corner3, corner2) line3 = _create_line(cube, builder, corner2, corner0) line4 = _create_line(cube, builder, corner4, corner5) line5 = _create_line(cube, builder, corner5, corner7) line6 = _create_line(cube, builder, corner7, corner6) line7 = _create_line(cube, builder, corner6, corner4) line8 = _create_line(cube, builder, corner0, corner4) line9 = _create_line(cube, builder, corner1, corner5) line10 = _create_line(cube, builder, corner2, corner6) line11 = _create_line(cube, builder, corner3, corner7) bottom = _create_surface(cube, builder, [corner0, corner1, corner3, corner2], [line0, line1, line2, line3]) top = _create_surface(cube, builder, [corner4, corner5, corner7, corner6], [line4, line5, line6, line7]) front = _create_surface(cube, builder, [corner0, corner1, corner5, corner4], [line0, line9, line4, line8]) back = _create_surface(cube, builder, [corner2, corner3, corner7, corner6], [line2, line11, line6, line10]) left = _create_surface(cube, builder, [corner0, corner4, corner6, corner2], [line8, line7, line10, line3]) right = _create_surface(cube, builder, [corner1, corner5, corner7, corner3], [line9, line5, line11, line1]) block = _create_block(cube, builder, [bottom, top, front, back, left, right]) return cube
def test_create_vertices(solid, builder): builder.create_point(geom.Point3D([0.1, 0.2, 0.3])) builder.create_point(geom.Point3D([2.1, 9.4, 6.7])) builder.create_point(geom.Point3D([7.5, 5.2, 6.3])) builder.create_point(geom.Point3D([8.1, 1.4, 4.7])) builder.create_point(geom.Point3D([4.7, 2.1, 1.3])) builder.create_point(geom.Point3D([1.6, 8.7, 6.1])) if solid.nb_vertices() != 6: raise ValueError("[Test] TetrahedralSolid should have 6 vertices")
def test_delete_vertex( surface, builder ): to_delete = [False] * surface.nb_vertices() to_delete[0] = True builder.delete_vertices( to_delete ) if surface.nb_vertices() != 4: raise ValueError( "[Test] TriangulatedSurface should have 4 vertices" ) answer = geom.Point3D( [ 2.1, 9.4, 6.7 ] ) if surface.point( 0 ) != answer: raise ValueError( "[Test] TriangulatedSurface vertex coordinates are not correct" ) if surface.nb_polygons() != 2: raise ValueError( "[Test] TriangulatedSurface should have 2 polygons" ) if surface.polygon_adjacent( mesh.PolygonEdge( 1, 2 ) ) != 0: raise ValueError( "[Test] TriangulatedSurface adjacent index is not correct" ) if surface.nb_edges() != 5: raise ValueError( "[Test] TriangulatedSurface should have 5 edges" )
def test_delete_vertex(solid, builder): to_delete = [False] * solid.nb_vertices() to_delete[0] = True builder.delete_vertices(to_delete) if solid.nb_vertices() != 5: raise ValueError("[Test] TetrahedralSolid should have 5 vertices") answer = geom.Point3D([2.1, 9.4, 6.7]) if solid.point(0) != answer: raise ValueError( "[Test] TetrahedralSolid vertex coordinates are not correct") if solid.nb_polyhedra() != 2: raise ValueError("[Test] TetrahedralSolid should have 2 tetrahedra") if solid.polyhedron_adjacent(mesh.PolyhedronFacet(1, 3)) != 0: raise ValueError( "[Test] TetrahedralSolid adjacent index is not correct") if solid.nb_facets() != 7: raise ValueError("[Test] PolyhedralSolid should have 7 facets") if solid.nb_edges() != 9: raise ValueError("[Test] PolyhedralSolid should have 9 edges")
def test_segment_segment_distance(): a = geom.Point3D([0.0, 0.0, 0.0]) b = geom.Point3D([2.0, 2.0, 0.0]) c = geom.Point3D([0.0, 2.0, 1.0]) d = geom.Point3D([2.0, 0.0, 1.0]) e = geom.Point3D([0.0, 0.0, 1.0]) f = geom.Point3D([2.0, 2.0, 1.0]) g = geom.Point3D([3.0, 0.0, 1.0]) h = geom.Point3D([5.0, -2.0, 1.0]) segment_ab = geom.Segment3D(a, b) segment_cd = geom.Segment3D(c, d) segment_ef = geom.Segment3D(e, f) segment_gh = geom.Segment3D(g, h) distance, closest_point0, closest_point1 = geom.segment_segment_distance3D( segment_ab, segment_cd) r00 = geom.Point3D([1.0, 1.0, 0.0]) r01 = geom.Point3D([1.0, 1.0, 1.0]) if distance != 1.0 or closest_point0 != r00 or closest_point1 != r01: raise ValueError( "[Test] Wrong result for segment_segment_distance3D with query segment_ab and segment_cd" ) distance, closest_point0, closest_point1 = geom.segment_segment_distance3D( segment_ab, segment_ef) r00 = geom.Point3D([0.0, 0.0, 0.0]) r01 = geom.Point3D([0.0, 0.0, 1.0]) if distance != 1.0 or closest_point0 != r00 or closest_point1 != r01: raise ValueError( "[Test] Wrong result for segment_segment_distance3D with query segment_ab and segment_ef" ) distance, closest_point0, closest_point1 = geom.segment_segment_distance3D( segment_cd, segment_gh) if distance != 1.0 or closest_point0 != d or closest_point1 != g: raise ValueError( "[Test] Wrong result for segment_segment_distance3D with query segment_cd and segment_gh" )
def test_point_circle_distance(): a = geom.Point3D([0.0, 0.0, 1.0]) normal_x = geom.Vector3D([-1.0, 0.0, 0.0]) normal_z = geom.Vector3D([0.0, 0.0, 1.0]) plane_x = geom.Plane(normal_x, a) plane_z = geom.Plane(normal_z, a) circle_x = geom.Circle(plane_x, 2) circle_z = geom.Circle(plane_z, 2) q1 = geom.Point3D([2.0, 0.0, 1.0]) distance, closest_point = geom.point_circle_distance(q1, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != math.sqrt(8) or closest_point != answer: raise ValueError( "[Test] Wrong result for point_circle_distance with query Point3D q1 and circle_x" ) distance, closest_point = geom.point_circle_distance(q1, circle_z) if distance != 0 or closest_point != q1: raise ValueError( "[Test] Wrong result for point_circle_distance with query Point3D q1 and circle_z" ) distance, closest_point = geom.point_circle_signed_distance(q1, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != -math.sqrt(8) or closest_point != answer: raise ValueError( "[Test] Wrong result for point_circle_signed_distance with query Point3D q1 and circle_x" ) distance, closest_point = geom.point_circle_signed_distance(q1, circle_z) if distance != 0 or closest_point != q1: raise ValueError( "[Test] Wrong result for point_circle_signed_distance with query Point3D q1 and circle_z" ) distance, closest_point = geom.point_disk_distance(q1, circle_x) answer = geom.Point3D([0.0, 0.0, 1.0]) if distance != 2 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_disk_distance with query Point3D q1 and circle_x" ) distance, closest_point = geom.point_disk_distance(q1, circle_z) if distance != 0 or closest_point != q1: raise ValueError( "[Test] Wrong result for point_disk_distance with query Point3D q1 and circle_z" ) q2 = geom.Point3D([0.0, 3.0, 1.0]) distance, closest_point = geom.point_circle_distance(q2, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 1 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_circle_distance with query Point3D q2 and circle_x" ) distance, closest_point = geom.point_circle_signed_distance(q2, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 1 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_circle_signed_distance with query Point3D q2 and circle_x" ) distance, closest_point = geom.point_disk_distance(q2, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 1 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_disk_distance with query Point3D q2 and circle_x" ) distance, closest_point = geom.point_circle_distance(a, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 2 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_circle_distance with query Point3D a and circle_x" ) distance, closest_point = geom.point_circle_signed_distance(a, circle_x) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 2 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_circle_signed_distance with query Point3D a and circle_x" ) distance, closest_point = geom.point_disk_distance(a, circle_x) if distance != 0 or closest_point != a: raise ValueError( "[Test] Wrong result for point_disk_distance with query Point3D a and circle_x" )
def test_point_sphere_distance(): a = geom.Point3D([0.0, 0.0, 1.0]) sphere = geom.Sphere3D(a, 2.0) q1 = geom.Point3D([2.0, 0.0, 1.0]) distance, closest_point = geom.point_sphere_distance3D(q1, sphere) if distance != 0.0 or closest_point != q1: raise ValueError( "[Test] Wrong result for point_sphere_distance with query point q1" ) q1 = geom.Point3D([2.0, 0.0, 1.0]) distance, closest_point = geom.point_sphere_signed_distance3D(q1, sphere) if distance != 0.0 or closest_point != q1: raise ValueError( "[Test] Wrong result for point_sphere_signed_distance with query point q1" ) q1 = geom.Point3D([2.0, 0.0, 1.0]) distance, closest_point = geom.point_ball_distance3D(q1, sphere) if distance != 0.0 or closest_point != q1: raise ValueError( "[Test] Wrong result for point_ball_distance with query point q1") q2 = geom.Point3D([0.0, 3.0, 1.0]) distance, closest_point = geom.point_sphere_distance3D(q2, sphere) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_sphere_distance with query point q3" ) q2 = geom.Point3D([0.0, 3.0, 1.0]) distance, closest_point = geom.point_sphere_signed_distance3D(q2, sphere) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_sphere_signed_distance with query point q3" ) q2 = geom.Point3D([0.0, 3.0, 1.0]) distance, closest_point = geom.point_ball_distance3D(q2, sphere) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_ball_distance with query point q3") q3 = geom.Point3D([0.0, 1.0, 1.0]) distance, closest_point = geom.point_sphere_distance3D(q3, sphere) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != 1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_sphere_distance with query point q3" ) q3 = geom.Point3D([0.0, 1.0, 1.0]) distance, closest_point = geom.point_sphere_signed_distance3D(q3, sphere) answer = geom.Point3D([0.0, 2.0, 1.0]) if distance != -1.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_sphere_signed__distance with query point q3" ) q3 = geom.Point3D([0.0, 1.0, 1.0]) distance, closest_point = geom.point_ball_distance3D(q3, sphere) if distance != 0.0 or closest_point != q3: raise ValueError( "[Test] Wrong result for point_ball_distance with query point q3") distance, closest_point = geom.point_sphere_distance3D(a, sphere) answer = geom.Point3D([2.0, 0.0, 1.0]) if distance != 2.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_sphere_distance with query point a") distance, closest_point = geom.point_sphere_signed_distance3D(a, sphere) answer = geom.Point3D([2.0, 0.0, 1.0]) if distance != -2.0 or closest_point != answer: raise ValueError( "[Test] Wrong result for point_sphere_signed_distance with query point a" ) distance, closest_point = geom.point_ball_distance3D(a, sphere) answer = geom.Point3D([2.0, 0.0, 1.0]) if distance != 0.0 or closest_point != a: raise ValueError( "[Test] Wrong result for point_ball_distance with query point a")
def test_permutation(edged_curve, builder): builder.permute_vertices([2, 0, 3, 1]) if edged_curve.point(2) != geom.Point3D([8.7, 1.4, 4.7]): raise ValueError( "[Test] Point coordinates have not been correctly permuted") if edged_curve.point(0) != geom.Point3D([7.5, 5.2, 6.3]): raise ValueError( "[Test] Point coordinates have not been correctly permuted") if edged_curve.edge_vertex(mesh.EdgeVertex(0, 0)) != 1: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(0, 1)) != 3: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(1, 0)) != 1: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(1, 1)) != 0: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(2, 0)) != 2: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(2, 1)) != 0: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(3, 0)) != 3: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") if edged_curve.edge_vertex(mesh.EdgeVertex(3, 1)) != 0: raise ValueError("[Test] Wrong EdgeVertex after vertex permute") builder.permute_edges([1, 3, 0, 2]) if edged_curve.edge_vertex(mesh.EdgeVertex(0, 0)) != 1: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(0, 1)) != 0: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(1, 0)) != 3: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(1, 1)) != 0: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(2, 0)) != 1: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(2, 1)) != 3: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(3, 0)) != 2: raise ValueError("[Test] Wrong EdgeVertex after edge permute") if edged_curve.edge_vertex(mesh.EdgeVertex(3, 1)) != 0: raise ValueError("[Test] Wrong EdgeVertex after edge permute") edges_around_1 = edged_curve.edges_around_vertex(1) if edges_around_1.size() != 2: raise ValueError("[Test] edges_around_1 should have 2 edges") if edges_around_1[0].edge_id != 2: raise ValueError("[Test] edges_around_1 has wrong value") if edges_around_1[0].vertex_id != 0: raise ValueError("[Test] edges_around_1 has wrong value") if edges_around_1[1].edge_id != 0: raise ValueError("[Test] edges_around_1 has wrong value") if edges_around_1[1].vertex_id != 0: raise ValueError("[Test] edges_around_1 has wrong value") edges_around_0 = edged_curve.edges_around_vertex(0) if edges_around_0.size() != 3: raise ValueError("[Test] edges_around_0 should have 3 edges") if edges_around_0[0].edge_id != 0: raise ValueError("[Test] edges_around_0 has wrong value") if edges_around_0[0].vertex_id != 1: raise ValueError("[Test] edges_around_0 has wrong value") if edges_around_0[1].edge_id != 3: raise ValueError("[Test] edges_around_0 has wrong value") if edges_around_0[1].vertex_id != 1: raise ValueError("[Test] edges_around_0 has wrong value") if edges_around_0[2].edge_id != 1: raise ValueError("[Test] edges_around_0 has wrong value") if edges_around_0[2].vertex_id != 1: raise ValueError("[Test] edges_around_0 has wrong value")