-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds Delaunay-property test (no points are within circumscribed circle).
- Loading branch information
Showing
5 changed files
with
41 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
import torch | ||
import torch_delaunay._C as _C | ||
from torch import Tensor | ||
|
||
|
||
def shull2d(points: torch.Tensor) -> torch.Tensor: | ||
def shull2d(points: Tensor) -> Tensor: | ||
return _C.shull2d(points) | ||
|
||
|
||
def circumcenter2d(p0: Tensor, p1: Tensor, p2: Tensor) -> Tensor: | ||
return _C.circumcenter2d(p0, p1, p2) | ||
|
||
|
||
def circumradius2d(p0: Tensor, p1: Tensor, p2: Tensor) -> Tensor: | ||
return _C.circumradius2d(p0, p1, p2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,29 @@ | ||
import torch | ||
from shapely import Point | ||
from geopandas import GeoDataFrame | ||
from geopandas import points_from_xy | ||
|
||
from torch_delaunay.functional import shull2d | ||
from torch_delaunay.functional import shull2d, circumcenter2d, circumradius2d | ||
|
||
|
||
def test_shull2d() -> None: | ||
points = torch.randn((1000, 2), dtype=torch.float64) | ||
simplices = shull2d(points) | ||
|
||
assert (simplices >= 1000).sum() == 0, "simplices are outside of points array limit" | ||
|
||
assert simplices.shape[1] == 3 | ||
assert simplices.shape[0] > 0 | ||
|
||
vertices = GeoDataFrame(geometry=points_from_xy(points[:, 0], points[:, 1])) | ||
|
||
# Ensure that triangles comply with Delaunay definition. | ||
tri = points[simplices] | ||
|
||
centers = circumcenter2d(tri[:, 0], tri[:, 1], tri[:, 2]).detach().numpy() | ||
radii = circumradius2d(tri[:, 0], tri[:, 1], tri[:, 2]).detach().numpy() | ||
|
||
for center, radius in zip(centers, radii): | ||
circle = Point(*center).buffer(radius) | ||
incircle = vertices.intersection(circle) | ||
assert (~incircle.is_empty).sum() <= 3 |