Skip to content

Commit

Permalink
add the possibility to define a triangulation tolerance for the case …
Browse files Browse the repository at this point in the history
…of list of linestring
  • Loading branch information
ptaillandier committed Feb 29, 2024
1 parent a197aff commit 72a4dc6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
5 changes: 3 additions & 2 deletions gama.core/src/gama/core/common/geometry/GeometryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,10 @@ public static IList<IShape> voronoi(final IScope scope, final IList<GamaPoint> p
* the lines
* @return the i list
*/
public static IList<IShape> triangulation(final IScope scope, final IList<IShape> lines) {
public static IList<IShape> triangulation(final IScope scope, final IList<IShape> lines, double tol) {
final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY);
final ConformingDelaunayTriangulationBuilder dtb = new ConformingDelaunayTriangulationBuilder();

dtb.setTolerance(tol);
final Geometry points = GamaGeometryType.geometriesToGeometry(scope, lines).getInnerGeometry();
dtb.setSites(points);
dtb.setConstraints(points);
Expand All @@ -720,6 +720,7 @@ public static IList<IShape> triangulation(final IScope scope, final IList<IShape
return geoms;
}


/**
* Triangulation.
*
Expand Down
23 changes: 22 additions & 1 deletion gama.core/src/gama/gaml/operators/Spatial.java
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,7 @@ public static IList<IShape> triangulate(final IScope scope, final IShape g) {
return GeometryUtils.triangulation(scope, g.getInnerGeometry(), 0.0, 0.0, false);
}


/**
* Triangulate.
*
Expand Down Expand Up @@ -3735,8 +3736,28 @@ public static IList<IShape> triangulate(final IScope scope, final IShape g, fina
@no_test
public static IList<IShape> triangulate(final IScope scope, final IList<IShape> gs) {
if (gs == null || gs.isEmpty()) return null;
return GeometryUtils.triangulation(scope, gs);
return GeometryUtils.triangulation(scope, gs, 0.0);
}


@operator (
value = { "triangulate", "to_triangles" },
content_type = IType.GEOMETRY,
category = { IOperatorCategory.SPATIAL, IOperatorCategory.SP_TRANSFORMATIONS },
concept = { IConcept.GEOMETRY, IConcept.SPATIAL_COMPUTATION, IConcept.SPATIAL_TRANSFORMATION })
@doc (
value = "A list of geometries (triangles) corresponding to the Delaunay triangulation computed from the list of polylines with the given tolerance for the triangulation",
masterDoc = true,
examples = { @example (
value = "triangulate([line([{0,50},{100,50}]), line([{50,0},{50,100}], 0.01))",
equals = "the list of geometries (triangles) corresponding to the Delaunay triangulation of the geometry of the agent applying the operator with the a tolerance of 0.01 for the triangulation.",
test = false) })
@no_test
public static IList<IShape> triangulate(final IScope scope, final IList<IShape> gs, final double tol) {
if (gs == null || gs.isEmpty()) return null;
return GeometryUtils.triangulation(scope, gs, tol);
}


/**
* Triangulate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ global {

//define the size of the world from the countour line shapefile
geometry shape <- envelope(shape_file_cl);

//tolerance for the triangulation; if an error appears during the triangulation, a workaround consists in increasing this tolerance (0.01 for instance).
float tolerance <- 0.0;

init {
//create the contour line agents from the shapefile, and init the elevation for each agent
create contour_line from: shape_file_cl with: [elevation:: float(read("ELEVATION"))];

//triangulate the contour lines
list<geometry> triangles <- triangulate (list(contour_line));
list<geometry> triangles <- triangulate (list(contour_line), tolerance);

//for each triangle geometry, create a triangle_ag agent and compute the elevation of each of its points (and modified their z value)
loop tr over: triangles {
Expand Down

0 comments on commit 72a4dc6

Please sign in to comment.