From ad0d0f66afb185b61d4a63b07b0298c564a19d34 Mon Sep 17 00:00:00 2001 From: Michael Hoffer Date: Tue, 8 Nov 2016 18:06:37 +0100 Subject: [PATCH] fix for issue #24 : https://github.com/miho/JCSG/issues/24 --- .../java/eu/mihosoft/vrl/v3d/RoundedCube.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java b/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java index 534afe36..12d71c02 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/RoundedCube.java @@ -59,8 +59,8 @@ public RoundedCube(Vector3d center, Vector3d dimensions) { } /** - * Constructor. Creates a new rounded cuboid with center {@code [0,0,0]} - * and with the specified dimensions. + * Constructor. Creates a new rounded cuboid with center {@code [0,0,0]} and + * with the specified dimensions. * * @param w width * @param h height @@ -70,11 +70,10 @@ public RoundedCube(double w, double h, double d) { this(Vector3d.ZERO, new Vector3d(w, h, d)); } - @Override public List toPolygons() { - CSG spherePrototype = - new Sphere(getCornerRadius(), getResolution()*2, getResolution()).toCSG(); + CSG spherePrototype + = new Sphere(getCornerRadius(), getResolution() * 2, getResolution()).toCSG(); double x = dimensions.x / 2.0 - getCornerRadius(); double y = dimensions.y / 2.0 - getCornerRadius(); @@ -94,6 +93,12 @@ public List toPolygons() { sphere2, sphere3, sphere4, sphere5, sphere6, sphere7, sphere8).hull().getPolygons(); + Transform locTransform = Transform.unity().translate(center); + + for (Polygon p : result) { + p.transform(locTransform); + } + if (!centered) { Transform centerTransform = Transform.unity().translate(dimensions.x / 2.0, dimensions.y / 2.0, dimensions.z / 2.0); @@ -141,6 +146,7 @@ public void setDimensions(Vector3d dimensions) { /** * Defines that this cube will not be centered. + * * @return this cube */ public RoundedCube noCenter() { @@ -161,8 +167,8 @@ public int getResolution() { public void setResolution(int resolution) { this.resolution = resolution; } - - /** + + /** * @param resolution the resolution to set * @return this cube */ @@ -184,7 +190,7 @@ public double getCornerRadius() { public void setCornerRadius(double cornerRadius) { this.cornerRadius = cornerRadius; } - + /** * @param cornerRadius the corner radius to set * @return this cube