|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (c) 2019 - 2026 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 | + |
| 26 | +if sys.version_info >= (3, 8, 0) and platform.system() == "Windows": |
| 27 | + for path in [x.strip() for x in os.environ["PATH"].split("") if x]: |
| 28 | + os.add_dll_directory(path) |
| 29 | + |
| 30 | +import opengeode as geode |
| 31 | +import opengeode_inspector_py_validity as validity |
| 32 | + |
| 33 | +def check_non_validity2D(): |
| 34 | + pointset = geode.PointSet2D.create() |
| 35 | + builder = geode.PointSetBuilder2D.create( pointset ) |
| 36 | + builder.create_vertices( 4 ) |
| 37 | + builder.set_point( 0, geode.Point2D( [0., 2.]) ) |
| 38 | + builder.set_point( 1, geode.Point2D( [2., 0.]) ) |
| 39 | + builder.set_point( 2, geode.Point2D( [1., 4.]) ) |
| 40 | + builder.set_point( 3, geode.Point2D( [3., 3.]) ) |
| 41 | + |
| 42 | + object_validity = validity.is_pointset_valid2D( pointset ) |
| 43 | + if not object_validity.nb_issues() == 0: |
| 44 | + raise ValueError("PointSet has "+ str(object_validity.nb_issues())+ " object_validity when it should have none." ) |
| 45 | + |
| 46 | +def check_validity2D(): |
| 47 | + pointset = geode.PointSet2D.create() |
| 48 | + builder = geode.PointSetBuilder2D.create( pointset ) |
| 49 | + builder.create_vertices( 7 ) |
| 50 | + builder.set_point( 0, geode.Point2D([ 0., 2.])) |
| 51 | + builder.set_point( 1, geode.Point2D([ 0., 2.])) |
| 52 | + builder.set_point( 2, geode.Point2D([ 0., 0.])) |
| 53 | + builder.set_point( 3, geode.Point2D([ 2., 0.])) |
| 54 | + builder.set_point( 4, geode.Point2D([ 1., 4.])) |
| 55 | + builder.set_point( 5, geode.Point2D([ 2., geode.GLOBAL_EPSILON / 2 ]) ) |
| 56 | + builder.set_point( 6, geode.Point2D([ geode.GLOBAL_EPSILON / 1.1, 2. ]) ) |
| 57 | + |
| 58 | + object_validity = validity.is_pointset_valid2D( pointset ) |
| 59 | + print( "2D object_validity: \n"+ object_validity.string() ) |
| 60 | + if not object_validity.nb_issues() == 1: |
| 61 | + raise ValueError("PointSet should have 1 invalidity reason, not "+str(object_validity.nb_issues()) ) |
| 62 | + |
| 63 | +def check_non_validity3D(): |
| 64 | + pointset = geode.PointSet3D.create() |
| 65 | + builder = geode.PointSetBuilder3D.create( pointset ) |
| 66 | + builder.create_vertices( 4 ) |
| 67 | + builder.set_point( 0, geode.Point3D([ 0., 2., 0. ]) ) |
| 68 | + builder.set_point( 1, geode.Point3D([2., 0., 0.5 ]) ) |
| 69 | + builder.set_point( 2, geode.Point3D([ 1., 4., 1. ]) ) |
| 70 | + builder.set_point( 3, geode.Point3D([ 3., 3., 2. ]) ) |
| 71 | + |
| 72 | + object_validity = validity.is_pointset_valid3D( pointset ) |
| 73 | + if not object_validity.nb_issues() == 0: |
| 74 | + raise ValueError( "PointSet has "+ str(object_validity.nb_issues())+" object_validity when it should have none." ) |
| 75 | + |
| 76 | +def check_validity3D(): |
| 77 | + pointset = geode.PointSet3D.create() |
| 78 | + builder = geode.PointSetBuilder3D.create( pointset ) |
| 79 | + builder.create_vertices( 7 ) |
| 80 | + builder.set_point( 0, geode.Point3D([ 0., 2., 1. ]) ) |
| 81 | + builder.set_point( 1, geode.Point3D([ 0., 2., 1. ]) ) |
| 82 | + builder.set_point( 2, geode.Point3D([ 0., 0., 0. ]) ) |
| 83 | + builder.set_point( 3, geode.Point3D([ 2., 0., 0. ]) ) |
| 84 | + builder.set_point( 4, geode.Point3D([ 1., 4., 3. ]) ) |
| 85 | + builder.set_point( 5, geode.Point3D([ 2., geode.GLOBAL_EPSILON / 2, geode.GLOBAL_EPSILON / 2 ]) ) |
| 86 | + builder.set_point( 6, geode.Point3D([ geode.GLOBAL_EPSILON / 1.1, 2., 1. ]) ) |
| 87 | + |
| 88 | + object_validity = validity.is_pointset_valid3D( pointset ) |
| 89 | + print( "3D object_validity: \n"+ object_validity.string() ) |
| 90 | + if not object_validity.nb_issues() == 1: |
| 91 | + raise ValueError( "PointSet should have 1 invalidity reason, not "+ str(object_validity.nb_issues()) ) |
| 92 | + |
| 93 | + |
| 94 | +if __name__ == "__main__": |
| 95 | + validity.OpenGeodeInspectorValidityLibrary.initialize() |
| 96 | + check_non_validity2D() |
| 97 | + check_validity2D() |
| 98 | + check_non_validity3D() |
| 99 | + check_validity3D() |
0 commit comments