| 
 | 1 | +# -*- coding: utf-8 -*-  | 
 | 2 | +# Copyright (c) 2019 - 2023 Geode-solutions  | 
 | 3 | +#  | 
 | 4 | +# Permission is hereby granted, free of charge, to any person obtaining a copy  | 
 | 5 | +# of this software and associated documentation files (the "Software"), to deal  | 
 | 6 | +# in the Software without restriction, including without limitation the rights  | 
 | 7 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  | 
 | 8 | +# copies of the Software, and to permit persons to whom the Software is  | 
 | 9 | +# furnished to do so, subject to the following conditions:  | 
 | 10 | +#  | 
 | 11 | +# The above copyright notice and this permission notice shall be included in  | 
 | 12 | +# all copies or substantial portions of the Software.  | 
 | 13 | +#  | 
 | 14 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  | 
 | 15 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  | 
 | 16 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  | 
 | 17 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  | 
 | 18 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  | 
 | 19 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  | 
 | 20 | +# SOFTWARE.  | 
 | 21 | + | 
 | 22 | +import os  | 
 | 23 | +import sys  | 
 | 24 | +import platform  | 
 | 25 | +if sys.version_info >= (3, 8, 0) and platform.system() == "Windows":  | 
 | 26 | +    for path in [x.strip() for x in os.environ['PATH'].split(';') if x]:  | 
 | 27 | +        os.add_dll_directory(path)  | 
 | 28 | + | 
 | 29 | +import opengeode as geode  | 
 | 30 | +import opengeode_inspector_py_inspector as inspector  | 
 | 31 | + | 
 | 32 | +def check_intersections2D():  | 
 | 33 | +    surface = geode.TriangulatedSurface2D.create()  | 
 | 34 | +    builder = geode.TriangulatedSurfaceBuilder2D.create( surface )  | 
 | 35 | +    builder.create_vertices( 5 )  | 
 | 36 | +    builder.set_point( 0, geode.Point2D( [ 0., 0. ] ) )  | 
 | 37 | +    builder.set_point( 1, geode.Point2D( [ 3., 0. ] ) )  | 
 | 38 | +    builder.set_point( 2, geode.Point2D( [ 0., 4. ] ) )  | 
 | 39 | +    builder.set_point( 3, geode.Point2D( [ 3., 4. ] ) )  | 
 | 40 | +    builder.set_point( 4, geode.Point2D( [ -1., 2. ] ) )  | 
 | 41 | +    builder.create_triangle( [ 0, 1, 2 ] )  | 
 | 42 | +    builder.create_triangle( [ 0, 1, 3 ] )  | 
 | 43 | +    builder.create_triangle( [ 1, 3, 4 ] )  | 
 | 44 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 0, 0 ), 1 )  | 
 | 45 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 1, 0 ), 0 )  | 
 | 46 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 1, 1 ), 2 )  | 
 | 47 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 2, 0 ), 1 )  | 
 | 48 | + | 
 | 49 | +    intersections_inspector = inspector.SurfaceMeshIntersections2D( surface )  | 
 | 50 | +    if not intersections_inspector.mesh_has_self_intersections():  | 
 | 51 | +        raise ValueError( "[Test] 2D Surface should have intersections." )  | 
 | 52 | +    if not intersections_inspector.nb_intersecting_elements_pair() == 3:  | 
 | 53 | +        raise ValueError( "[Test] 2D Surface should have 3 intersecting elements pair." )  | 
 | 54 | +    triangles_inter = intersections_inspector.intersecting_elements()  | 
 | 55 | +    if len( triangles_inter ) != 3 or triangles_inter[0][0] != 2 or triangles_inter[0][1] != 0 or triangles_inter[1][0] != 2 or triangles_inter[1][1] != 1 or triangles_inter[2][0] != 0 or triangles_inter[2][1] != 1:  | 
 | 56 | +        raise ValueError( "[Test] 2D Surface has wrong intersecting elements pairs." )  | 
 | 57 | + | 
 | 58 | +def check_intersections3D():  | 
 | 59 | +    surface = geode.TriangulatedSurface3D.create()  | 
 | 60 | +    builder = geode.TriangulatedSurfaceBuilder3D.create( surface )  | 
 | 61 | +    builder.create_vertices( 7 )  | 
 | 62 | +    builder.set_point( 0, geode.Point3D( [ 0., 0., 0. ] ) )  | 
 | 63 | +    builder.set_point( 1, geode.Point3D( [ 0., 0., 3. ] ) )  | 
 | 64 | +    builder.set_point( 2, geode.Point3D( [ 0., 2., 0. ] ) )  | 
 | 65 | +    builder.set_point( 3, geode.Point3D( [ 2., 0., 0. ] ) )  | 
 | 66 | +    builder.set_point( 4, geode.Point3D( [ 5., 0., 1.5 ] ) )  | 
 | 67 | +    builder.set_point( 5, geode.Point3D( [ 2., 0.5, 2. ] ) )  | 
 | 68 | +    builder.set_point( 6, geode.Point3D( [ 0., 0., 1.5 ] ) )  | 
 | 69 | +    builder.create_triangle( [ 0, 1, 2 ] )  | 
 | 70 | +    builder.create_triangle( [ 0, 2, 3 ] )  | 
 | 71 | +    builder.create_triangle( [ 3, 5, 2 ] )  | 
 | 72 | +    builder.create_triangle( [ 5, 2, 4 ] )  | 
 | 73 | +    builder.create_triangle( [ 4, 2, 6 ] )  | 
 | 74 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 0, 2 ), 1 )  | 
 | 75 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 1, 0 ), 0 )  | 
 | 76 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 1, 1 ), 2 )  | 
 | 77 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 2, 2 ), 1 )  | 
 | 78 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 2, 1 ), 3 )  | 
 | 79 | +    builder.set_polygon_adjacent( geode.PolygonEdge( 3, 0 ), 2 )  | 
 | 80 | + | 
 | 81 | +    intersections_inspector = inspector.SurfaceMeshIntersections3D(surface)  | 
 | 82 | +    if not intersections_inspector.mesh_has_self_intersections():  | 
 | 83 | +        raise ValueError( "[Test] 3D Surface should have intersections." )  | 
 | 84 | +    nb_intersections = intersections_inspector.nb_intersecting_elements_pair()  | 
 | 85 | +    if not nb_intersections == 2:  | 
 | 86 | +        raise ValueError( "[Test] 3D Surface should have 2 intersecting elements pair." )  | 
 | 87 | +    triangles_inter = intersections_inspector.intersecting_elements()  | 
 | 88 | +    if len( triangles_inter ) != 2 or triangles_inter[0][0] != 0 or triangles_inter[0][1] != 4 or triangles_inter[1][0] != 2 or triangles_inter[1][1] != 4:  | 
 | 89 | +        raise ValueError( "[Test] 3D Surface has wrong intersecting elements pairs." )  | 
 | 90 | + | 
 | 91 | +if __name__ == '__main__':  | 
 | 92 | +    inspector.OpenGeodeInspectorInspector.initialize()  | 
 | 93 | +    check_intersections2D()  | 
 | 94 | +    check_intersections3D()  | 
0 commit comments