Skip to content

Commit

Permalink
triangulation of polygons possible via public api
Browse files Browse the repository at this point in the history
  • Loading branch information
miho committed Apr 7, 2018
1 parent dcce1e3 commit cf00df3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group = eu.mihosoft.vrl.jcsg
version = 0.5.7-SNAPSHOT
version = 0.5.7
32 changes: 32 additions & 0 deletions src/main/java/eu/mihosoft/jcsg/Polygon.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,38 @@ public StringBuilder toStlString(StringBuilder sb) {
return sb;
}

/**
* Returns a triangulated version of this polygon.
*
* @return triangles
*/
public List<Polygon> toTriangles() {

List<Polygon> 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.
*
Expand Down

0 comments on commit cf00df3

Please sign in to comment.