From cf00df368264fdf71ce3fae1cd2a987d648499ff Mon Sep 17 00:00:00 2001 From: Michael Hoffer Date: Sat, 7 Apr 2018 23:11:13 +0200 Subject: [PATCH] triangulation of polygons possible via public api --- build.gradle | 6 ++-- gradle.properties | 2 +- src/main/java/eu/mihosoft/jcsg/Polygon.java | 32 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 959deb75..883988c3 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,8 @@ plugins { id 'application' id 'java' id 'maven-publish' - id 'net.nemerosa.versioning' version '1.5.0' - id 'com.jfrog.bintray' version '1.6' + id 'net.nemerosa.versioning' version '2.6.1' + id 'com.jfrog.bintray' version '1.7.2' } sourceCompatibility = '1.8' @@ -13,7 +13,7 @@ sourceCompatibility = '1.8' //repairHeaders.licenseHeaderText = new File(projectDir,'./license-template.txt') task wrapper(type: Wrapper, description: 'Creates and deploys the Gradle wrapper to the current directory.') { - gradleVersion = '4.0' + gradleVersion = '4.6' } if (!hasProperty('mainClass')) { diff --git a/gradle.properties b/gradle.properties index d6c234ff..5e990126 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group = eu.mihosoft.vrl.jcsg -version = 0.5.7-SNAPSHOT +version = 0.5.7 diff --git a/src/main/java/eu/mihosoft/jcsg/Polygon.java b/src/main/java/eu/mihosoft/jcsg/Polygon.java index 32a41866..22170b44 100644 --- a/src/main/java/eu/mihosoft/jcsg/Polygon.java +++ b/src/main/java/eu/mihosoft/jcsg/Polygon.java @@ -272,6 +272,38 @@ public StringBuilder toStlString(StringBuilder sb) { return sb; } + /** + * Returns a triangulated version of this polygon. + * + * @return triangles + */ + public List toTriangles() { + + List result = new ArrayList<>(); + + if (this.vertices.size() >= 3) { + + // TODO: improve the triangulation? + // + // If our polygon has more vertices, create + // multiple triangles: + Vertex firstVertexStl = this.vertices.get(0); + for (int i = 0; i < this.vertices.size() - 2; i++) { + + // create triangle + Polygon polygon = Polygon.fromPoints( + firstVertexStl.pos, + this.vertices.get(i + 1).pos, + this.vertices.get(i + 2).pos + ); + + result.add(polygon); + } + } + + return result; + } + /** * Translates this polygon. *