Skip to content

Commit cf00df3

Browse files
committed
triangulation of polygons possible via public api
1 parent dcce1e3 commit cf00df3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ plugins {
22
id 'application'
33
id 'java'
44
id 'maven-publish'
5-
id 'net.nemerosa.versioning' version '1.5.0'
6-
id 'com.jfrog.bintray' version '1.6'
5+
id 'net.nemerosa.versioning' version '2.6.1'
6+
id 'com.jfrog.bintray' version '1.7.2'
77
}
88

99
sourceCompatibility = '1.8'
@@ -13,7 +13,7 @@ sourceCompatibility = '1.8'
1313
//repairHeaders.licenseHeaderText = new File(projectDir,'./license-template.txt')
1414

1515
task wrapper(type: Wrapper, description: 'Creates and deploys the Gradle wrapper to the current directory.') {
16-
gradleVersion = '4.0'
16+
gradleVersion = '4.6'
1717
}
1818

1919
if (!hasProperty('mainClass')) {

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group = eu.mihosoft.vrl.jcsg
2-
version = 0.5.7-SNAPSHOT
2+
version = 0.5.7

src/main/java/eu/mihosoft/jcsg/Polygon.java

+32
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,38 @@ public StringBuilder toStlString(StringBuilder sb) {
272272
return sb;
273273
}
274274

275+
/**
276+
* Returns a triangulated version of this polygon.
277+
*
278+
* @return triangles
279+
*/
280+
public List<Polygon> toTriangles() {
281+
282+
List<Polygon> result = new ArrayList<>();
283+
284+
if (this.vertices.size() >= 3) {
285+
286+
// TODO: improve the triangulation?
287+
//
288+
// If our polygon has more vertices, create
289+
// multiple triangles:
290+
Vertex firstVertexStl = this.vertices.get(0);
291+
for (int i = 0; i < this.vertices.size() - 2; i++) {
292+
293+
// create triangle
294+
Polygon polygon = Polygon.fromPoints(
295+
firstVertexStl.pos,
296+
this.vertices.get(i + 1).pos,
297+
this.vertices.get(i + 2).pos
298+
);
299+
300+
result.add(polygon);
301+
}
302+
}
303+
304+
return result;
305+
}
306+
275307
/**
276308
* Translates this polygon.
277309
*

0 commit comments

Comments
 (0)