Formlabs / foxtrot

A fast, experimental STEP file viewer
Apache License 2.0
227 stars 16 forks source link

Incorrect CDT -- points not in the input added #6

Closed Indy2222 closed 2 years ago

Indy2222 commented 2 years ago

The following picture illustrates the issue:

image

All points except 4 in the corners were added as constraint edges (visualized with red color). The triangulation contains triangles (visualized with blue color) with vertices which do not correspond to any input point.

This is fully zoomed out image (scaled to 0-1):

image

Note that I have removed some triangles from the zoomed-out image above (the white areas were correctly covered).

Input points:

[[-500., -1000.], [-500., 1000.], [500., 1000.], [500., -1000.]]

Input edges (list of edges, each is list of a-b points):

[[[-420.56, -920.56], [-379.44, -920.56]], [[-379.44, -920.56], [-379.53156, -840.588]], [[-379.53156, -840.588], [-420.65155, -840.588]], [[-420.65155, -840.588], [-424.31952, -897.4294]], [[-424.31952, -897.4294], [-424.31952, -904.1894]], [[-424.31952, -904.1894], [-420.56, -920.56]], [[-420.56, 920.56], [-420.56, 879.44]], [[-420.56, 879.44], [-379.44, 879.44]], [[-379.44, 879.44], [-379.44, 920.56]], [[-379.44, 920.56], [-420.56, 920.56]], [[379.44, 920.56], [379.44, 879.44]], [[379.44, 879.44], [420.56, 879.44]], [[420.56, 879.44], [420.56, 920.56]], [[420.56, 920.56], [379.44, 920.56]], [[379.44, -879.44], [379.44, -920.56]], [[379.44, -920.56], [420.56, -920.56]], [[420.56, -920.56], [420.56, -879.44]], [[420.56, -879.44], [379.44, -879.44]]]
Indy2222 commented 2 years ago

For completeness, my code looks like this:

let mut triangulation = ConstrainedDelaunayTriangulation::<Point2<_>>::new();
// ...
// For corner points are added like this:
triangulation.insert(Point2::new(...)).unwrap();
// ...
// Then in a for loop:
triangulation
    .add_constraint_edge(edge.a_point2(), edge.b_point2())
    .unwrap();

// And then I get the triangles with:
triangulation
    .inner_faces()
    .filter_map(|f| {
        let vertices = f.vertices().map(|v| {
            let v = v.as_ref();
            Point::new(v.x, v.y)
        });
        let triangle = Triangle::new(vertices[0], vertices[1], vertices[2]);
        if polygon_ids.is_excluded(&triangle) {
            None
        } else {
            Some(triangle)
        }
    })
    .collect()
Indy2222 commented 2 years ago

Never mind, I opened the issue in wrong repository. :blush: