Skip to content

Hausdorff Distance values odd #1456

@plooney

Description

@plooney

I'm using a python wrapper I wrote to test some functions. I expect the Hausdorff Distance to be close to 0 but I get nonzero values in Rust.Geo. Converting the shapes to shapely gives me a value close to zero.

If I simplify the multi polygon I can get very different values.

!uv pip install -U rust_geo_python
from rust_geo_python import RustPolygon, union
from shapely import from_wkt

def make_circle(centre, radius, nVerts=200):
    direction = -1

    pts = []
    for v in range(nVerts):
        theta = direction*v*2*np.pi/nVerts
        pts.append([radius*np.cos(theta), radius*np.sin(theta)])
    pts = pts + np.asarray(centre)
    return np.asarray(pts)

def test_buffering():
    rect_verts_ext = np.array([[2,2],[2,-2],[-2,-2],[-2,2]]).astype(float)
    rect_verts_int = np.array([[1,1],[1,-1],[-1,-1],[-1,1]]).astype(float)[::-1]
    rect_polygon = RustPolygon(rect_verts_ext, [rect_verts_int])
    rect_verts_int = np.array([[0.5,0.5],[0.5,-0.5],[-0.5,-0.5],[-0.5,0.5]]).astype(float)[::-1]
    rect_polygon_small_int = RustPolygon(rect_verts_ext, [rect_verts_int])
    n_points = 100
    x = np.linspace(-2,2,n_points)
    y = np.linspace(-2,2,n_points)
    left_points = list(zip(np.array([-2]*n_points), y))
    right_points = list(zip(np.array([2]*n_points), y))
    bottom_points = list(zip(x, [-2]*n_points))
    top_points = list(zip(x, [2]*n_points))
    circles = [RustPolygon(make_circle(x, 0.5, nVerts=100),[]) for x in left_points + right_points + top_points + bottom_points]
    rect_union = union(circles + [rect_polygon, rect_polygon_small_int])
    buffered_rect = rect_polygon.buffer(0.5)
    print(f"Rust value {rect_union.hausdorff_distance(buffered_rect)}")
    return buffered_rect, rect_union, rect_polygon_small_int

rect_buffer, rect_union, rect_small = test_buffering()

import shapely
print(f"Shapely value {shapely.hausdorff_distance(from_wkt(rect_buffer.to_wkt()), from_wkt(rect_union.to_wkt()))}")

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