Skip to content

Boundary CoordinatePosition for Triangle returning incorrect results #1468

@wwaltersdavis

Description

@wwaltersdavis

Currently when getting the coordinate position for some triangle boundary coords, a different CoordPos is returned when using a Triangle vs the same triangle as a Polygon. The Polygon implementation looks to be returning the correct position. This can be created with the following:

use geo::{coord, CoordinatePosition, Polygon, Triangle};

fn triangle_coordpos_error() {
    let p = coord! { x: 10.0, y: 5.0 };

    let triangle: Triangle = Triangle::new(
        coord! { x: 0.0, y: 0.0 },
        coord! { x: 10.0, y: 0.0 },
        coord! { x: 10.0, y: 10.0 },
    );
    let pos_1 = triangle.coordinate_position(&p);

    let triangle_as_polygon: Polygon = triangle.to_polygon();
    let pos_2 = triangle_as_polygon.coordinate_position(&p);

    assert_eq!(pos_1, pos_2);
}

Issue

  • Arises when a triangle has one edge which is parallel to the y-axis and the coordinate to get the position of is on that edge.
  • Looks to be caused by line 195 where only coords without the same x as the line end.x are accepted as boundary coords.

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