Skip to content

closest_point_on_segment_xy returns a 3D point (Z corrdinate !=0) #837

@sanzoghenzo

Description

@sanzoghenzo

Describe the bug

If the closest_point_on_segment_xy is one of the endpoints, it is returned with z coordinate different than 0.
This is because the logic returns the endpoint as-is, without zeroing the Z coordinate.

To Reproduce

from compas.geometry import Point, Line, closest_point_on_segment_xy


def test_closest_point_segment_xy():
    point = Point(0, 0, -10)
    line = Line([1, 1, -15], [10, 10, 20])
    ponl= closest_point_on_segment_xy(point, line)
    assert ponl == Point(1, 1, 0)

it returns

=============================== FAILURES ================================
_________________ test_closest_point_segment_xy ________________________

    def test_closest_point_segment_xy():
        point = Point(0, 0, -10)
        line = Line([1, 1, -15], [10, 10, 20])
        ponl = closest_point_on_segment_xy(point, line)
>       assert ponl == Point(1, 1, 0)
E       assert Point(1.000, 1.000, -15.000) == Point(1.000, 1.000, 0.000)
E         Use -v to get the full diff

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions