def test_triangle_area():
    a = geom.Point2D( [0.0, 0.0] )
    b = geom.Point2D( [1.0, 0.0] )
    c = geom.Point2D( [1.0, 1.0] )

    triangle2D_1 = geom.Triangle2D( a, b, c )
    if geom.triangle_area2D( triangle2D_1 ) != 0.5:
        raise ValueError( "[Test] Wrong result for triangle_area with query triangle triangle2D_1" )

    triangle2D_2 = geom.Triangle2D( a, b, a )
    if geom.triangle_area2D( triangle2D_2 ) != 0.0:
        raise ValueError( "[Test] Wrong result for triangle_area with query triangle triangle2D_2" )
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_polygon_area():
    polygonal_surface = mesh.PolygonalSurface2D.create()
    builder = mesh.PolygonalSurfaceBuilder2D.create( polygonal_surface )
    a = 6.0
    b = 8.0
    c = 4.0

    builder.create_point( geom.Point2D( [ 0.0, 0.0 ] ) )
    builder.create_point( geom.Point2D( [ a, 0.0 ] ) )
    builder.create_point( geom.Point2D( [ b, c ] ) )
    builder.create_point( geom.Point2D( [ 0.0, c ] ) )

    builder.create_polygon( [ 0, 1, 2, 3 ] )

    if polygonal_surface.polygon_area( 0 ) != 28:
        raise ValueError( "[Test] PolygonalSurface polygon area is not correct" )
def test_point_segment_distance():
    a = geom.Point2D([1.0, 5.0])
    b = geom.Point2D([-1.0, -5.0])
    segment2D = geom.Segment2D(a, b)

    distance, closest_point = geom.point_segment_distance2D(a, segment2D)
    if distance != 0 or closest_point != a:
        raise ValueError(
            "[Test] Wrong result for point_segment_distance2D with query point a"
        )

    distance, closest_point = geom.point_segment_distance2D(b, segment2D)
    if distance != 0 or closest_point != b:
        raise ValueError(
            "[Test] Wrong result for point_segment_distance2D with query point b"
        )

    q1 = geom.Point2D([0.0, 0.0])
    distance, closest_point = geom.point_segment_distance2D(q1, segment2D)
    if distance != 0 or closest_point != q1:
        raise ValueError(
            "[Test] Wrong result for point_segment_distance2D with query point q1"
        )

    q2 = geom.Point2D([10.0, 10.0])
    distance, closest_point = geom.point_segment_distance2D(q2, segment2D)
    if distance != math.sqrt(106) or closest_point != a:
        raise ValueError(
            "[Test] Wrong result for point_segment_distance2D with query point q2"
        )

    q3 = geom.Point2D([5.0, -1.0])
    distance, closest_point = geom.point_segment_distance2D(q3, segment2D)
    result_q3 = geom.Point2D([0.0, 0.0])
    if distance != math.sqrt(26) or closest_point != result_q3:
        raise ValueError(
            "[Test] Wrong result for point_segment_distance2D with query point q3"
        )

    q4 = geom.Point2D([5.5, 1.5])
    distance, closest_point = geom.point_segment_distance2D(q4, segment2D)
    result_q4 = geom.Point2D([0.5, 2.5])
    if distance != math.sqrt(26) or closest_point != result_q4:
        raise ValueError(
            "[Test] Wrong result for point_segment_distance2D with query point q4"
        )
def test_point_triangle_distance():
    a = geom.Point2D([0.0, 0.0])
    b = geom.Point2D([1.0, 0.0])
    c = geom.Point2D([1.0, 1.0])
    triangle2D = geom.Triangle2D(a, b, c)

    distance, closest_point = geom.point_triangle_distance2D(a, triangle2D)
    if distance != 0 or closest_point != a:
        raise ValueError(
            "[Test] Wrong result for point_triangle_distance2D with query point a"
        )

    distance, closest_point = geom.point_triangle_distance2D(b, triangle2D)
    if distance != 0 or closest_point != b:
        raise ValueError(
            "[Test] Wrong result for point_triangle_distance2D with query point b"
        )

    q1 = geom.Point2D([0.5, 0.5])
    distance, closest_point = geom.point_triangle_distance2D(q1, triangle2D)
    if distance != 0 or closest_point != q1:
        raise ValueError(
            "[Test] Wrong result for point_triangle_distance2D with query point q1"
        )

    q2 = geom.Point2D([0.0, 1.0])
    distance, closest_point = geom.point_triangle_distance2D(q2, triangle2D)
    result_q2 = geom.Point2D([0.5, 0.5])
    if distance != math.sqrt(2) / 2. or closest_point != result_q2:
        raise ValueError(
            "[Test] Wrong result for point_triangle_distance2D with query point q2"
        )

    q3 = geom.Point2D([2.0, 1.0])
    distance, closest_point = geom.point_triangle_distance2D(q3, triangle2D)
    if distance != 1 or closest_point != c:
        raise ValueError(
            "[Test] Wrong result for point_triangle_distance2D with query point q3"
        )

    q4 = geom.Point2D([0.5, 0.5])
    distance, closest_point = geom.point_triangle_distance2D(q4, triangle2D)
    if distance != 0 or closest_point != q4:
        raise ValueError(
            "[Test] Wrong result for point_triangle_distance2D with query point q4"
        )
Example #6
0
def test_triangle_barycentric_coordinates():
    a = geom.Point2D([0.0, 0.0])
    b = geom.Point2D([1.0, 0.0])
    c = geom.Point2D([1.0, 1.0])
    triangle2D = geom.Triangle2D(a, b, c)

    if not check_triangle_bary_coords(
            geom.triangle_barycentric_coordinates2D(a, triangle2D), [1, 0, 0]):
        raise ValueError(
            "[Test] Wrong result for triangle_barycentric_coordinates with query point a"
        )
    if not check_triangle_bary_coords(
            geom.triangle_barycentric_coordinates2D(b, triangle2D), [0, 1, 0]):
        raise ValueError(
            "[Test] Wrong result for triangle_barycentric_coordinates with query point b"
        )
    if not check_triangle_bary_coords(
            geom.triangle_barycentric_coordinates2D(c, triangle2D), [0, 0, 1]):
        raise ValueError(
            "[Test] Wrong result for triangle_barycentric_coordinates with query point c"
        )

    q1 = geom.Point2D([0.25, 0.0])
    if not check_triangle_bary_coords(
            geom.triangle_barycentric_coordinates2D(q1, triangle2D),
        [0.75, 0.25, 0]):
        raise ValueError(
            "[Test] Wrong result for triangle_barycentric_coordinates with query point q1"
        )

    q2 = geom.Point2D([0.5, 0.25])
    if not check_triangle_bary_coords(
            geom.triangle_barycentric_coordinates2D(q2, triangle2D),
        [0.5, 0.25, 0.25]):
        raise ValueError(
            "[Test] Wrong result for triangle_barycentric_coordinates with query point q2"
        )

    q3 = geom.Point2D([0.0, 1.0])
    if not check_triangle_bary_coords(
            geom.triangle_barycentric_coordinates2D(q3, triangle2D),
        [1, -1, 1]):
        raise ValueError(
            "[Test] Wrong result for triangle_barycentric_coordinates with query point q3"
        )
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.

import opengeode_py_geometry as geom

if __name__ == '__main__':
    a = geom.Point2D([1.0, 5.0])
    b = geom.Point2D([-1.0, -5.0])
    segment2D = geom.Segment2D(a, b)
    closest_point = geom.point_segment_projection2D(a, segment2D)
    if closest_point != a:
        raise ValueError(
            "[Test] Wrong result for point_segment_projection with query point a"
        )
    closest_point = geom.point_segment_projection2D(b, segment2D)
    if closest_point != b:
        raise ValueError(
            "[Test] Wrong result for point_segment_projection with query point b"
        )
    q1 = geom.Point2D([0.0, 0.0])
    closest_point = geom.point_segment_projection2D(q1, segment2D)
    if closest_point != q1:
Example #8
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import opengeode_py_geometry as geom

if __name__ == '__main__':
    box = geom.BoundingBox2D()
    box.add_point(geom.Point2D([-1, -1]))
    box.add_point(geom.Point2D([1, 1]))

    box2 = box
    box2.add_point(geom.Point2D([-2, -2]))
    box2.add_point(geom.Point2D([0, 0]))

    box2.add_box(box)
    if box2.min() != geom.Point2D([-2, -2]):
        raise ValueError("[Test] Error in BoundingBox union computation")
    if box2.max() != geom.Point2D([1, 1]):
        raise ValueError("[Test] Error in BoundingBox union computation")

    if not box2.contains(geom.Point2D([0, 0])):
        raise ValueError("[Test] BBox should contain this point")
    if box2.contains(geom.Point2D([10, 0])):
Example #9
0
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import opengeode_py_geometry as geom

if __name__ == '__main__':
    search = geom.NNSearch2D([
        geom.Point2D([0.1, 4.2]),
        geom.Point2D([5.9, 7.3]),
        geom.Point2D([1.8, -5]),
        geom.Point2D([-7.3, -1.6])
    ])

    if search.closest_neighbor(geom.Point2D([0, 0])) != 0:
        raise ValueError("[Test] Error in closest neighbor")
    if search.closest_neighbor(geom.Point2D([1, -4])) != 2:
        raise ValueError("[Test] Error in closest neighbor")

    answer_radius = [0, 2]
    if search.radius_neighbors(geom.Point2D([0, 0]), 5.4) != answer_radius:
        raise ValueError("[Test] Error in radius neighbors")

    answer_neighbors = [2, 0]