diff --git a/src/api/org/jzy3d/io/SimpleFile.java b/src/api/org/jzy3d/io/SimpleFile.java index e503f5fa..7aa6d2b6 100644 --- a/src/api/org/jzy3d/io/SimpleFile.java +++ b/src/api/org/jzy3d/io/SimpleFile.java @@ -17,13 +17,20 @@ import java.util.ArrayList; import java.util.List; public class SimpleFile { - public static void write(String content, String file) throws IOException { + public static void write(String content, String file) throws Exception { createParentFoldersIfNotExist(file); Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8"); out.write(content); out.close(); } + public static void createParentFoldersIfNotExist(String file) { + File parent = (new File(file)).getParentFile(); + if (parent != null && !parent.exists()) + parent.mkdirs(); + } + + public static List read(String filename) throws IOException { List output = new ArrayList(); File file = new File(filename); @@ -35,6 +42,7 @@ public class SimpleFile { output.add(dis.readLine()); } + fis.close(); bis.close(); dis.close(); @@ -54,7 +62,6 @@ public class SimpleFile { while (dis.available() != 0) { sb.append((new StringBuilder()).append(dis.readLine()).append(newLineString)); } - fis.close(); bis.close(); dis.close(); @@ -76,11 +83,4 @@ public class SimpleFile { else return f1.lastModified() > f2.lastModified(); } - - public static void createParentFoldersIfNotExist(String file) { - File parent = (new File(file)).getParentFile(); - if (parent != null && !parent.exists()) - parent.mkdirs(); - } - } diff --git a/src/api/org/jzy3d/maths/Coord2d.java b/src/api/org/jzy3d/maths/Coord2d.java index dcbde72b..25165830 100644 --- a/src/api/org/jzy3d/maths/Coord2d.java +++ b/src/api/org/jzy3d/maths/Coord2d.java @@ -39,9 +39,17 @@ public class Coord2d { public Coord2d clone(){ return new Coord2d(x,y); } - - /**************************************************************/ - + + public void set(Coord2d c){ + this.x = c.x; + this.y = c.y; + } + + public void set(float x, float y){ + this.x = x; + this.y = y; + } + /** Add a Coord2d to the current one and return the result * in a new Coord2d. * @param c2 @@ -61,6 +69,14 @@ public class Coord2d { this.y+=y; } + public void addSelfX(float x){ + this.x+=x; + } + + public void addSelfY(float y){ + this.y+=y; + } + /** Add a value to all components of the current Coord and return the result * in a new Coord2d. * @param value @@ -194,7 +210,25 @@ public class Coord2d { public double distance(Coord2d c){ return Math.sqrt( Math.pow(x-c.x,2) + Math.pow(y-c.y,2) ); } + + public double distanceSq(Coord2d c){ + return Math.pow(x-c.x,2) + Math.pow(y-c.y,2); + } + /** + * Returns an interpolated point between the current and given point, + * according to an input ratio in [0;1] that indicates how near to the + * current point the new point will stand. + * + * A value of 1 will return a copy of the current point. + */ + public Coord2d interpolation(Coord2d c, float ratio){ + float inv = 1-ratio; + float xx = x*ratio+c.x*inv; + float yy = y*ratio+c.y*inv; + return new Coord2d(xx,yy); + } + /** Return a string representation of this coordinate.*/ public String toString(){ return ("x=" + x + " y=" + y); diff --git a/src/api/org/jzy3d/plot3d/rendering/view/View.java b/src/api/org/jzy3d/plot3d/rendering/view/View.java index 648df3f2..67618e21 100644 --- a/src/api/org/jzy3d/plot3d/rendering/view/View.java +++ b/src/api/org/jzy3d/plot3d/rendering/view/View.java @@ -804,11 +804,7 @@ public class View { } public BoundingBox3d computeScaling() { - // -- Scale the scene's view ------------------- - if (squared) // force square scale - scaling = squarify(); - else - scaling = Coord3d.IDENTITY.clone(); + scaling = computeSceneScaling(); // -- Compute the bounds for computing cam distance, clipping planes, // etc @@ -823,6 +819,14 @@ public class View { return boundsScaled; } + public Coord3d computeSceneScaling() { + // -- Scale the scene's view ------------------- + if (squared) // force square scale + return squarify(); + else + return Coord3d.IDENTITY.clone(); + } + public void updateCamera(GL gl, GLU glu, ViewportConfiguration viewport, BoundingBox3d boundsScaled) { updateCamera(gl, glu, viewport, boundsScaled, diff --git a/src/tests/org/jzy3d/tests/TestFaceOrdering1.java b/src/tests/org/jzy3d/tests/PseudoTestFaceOrdering1.java similarity index 99% rename from src/tests/org/jzy3d/tests/TestFaceOrdering1.java rename to src/tests/org/jzy3d/tests/PseudoTestFaceOrdering1.java index 8a6f1d8c..433b5d7a 100644 --- a/src/tests/org/jzy3d/tests/TestFaceOrdering1.java +++ b/src/tests/org/jzy3d/tests/PseudoTestFaceOrdering1.java @@ -48,11 +48,11 @@ import org.jzy3d.plot3d.text.drawable.DrawableTextBillboard; * * @author Martin */ -public class TestFaceOrdering1 { +public class PseudoTestFaceOrdering1 { static double MAPPER_ZSCALE_FACTOR = 100; public static void main(String[] args) throws Exception { - TestFaceOrdering1 surface = new TestFaceOrdering1(); + PseudoTestFaceOrdering1 surface = new PseudoTestFaceOrdering1(); surface.BuildAndLaunch(); } @@ -195,7 +195,7 @@ public class TestFaceOrdering1 { /** * Surface */ - public TestFaceOrdering1() { + public PseudoTestFaceOrdering1() { _expX = new double[] { -1.0, 1.0, 0.0, 0.0, 0.0 }; _expY = new double[] { 0.0, 0.0, -1.0, 1.0, 0.0 }; _expZ = new double[] { 1799635.862225038, 2778958.3605334656, 2308941.6737486282, 2791418.430038142, 2778052.031336538 }; diff --git a/src/tests/org/jzy3d/tests/TestManualBounds.java b/src/tests/org/jzy3d/tests/PseudoTestManualBounds.java similarity index 96% rename from src/tests/org/jzy3d/tests/TestManualBounds.java rename to src/tests/org/jzy3d/tests/PseudoTestManualBounds.java index 11403263..72279bbe 100644 --- a/src/tests/org/jzy3d/tests/TestManualBounds.java +++ b/src/tests/org/jzy3d/tests/PseudoTestManualBounds.java @@ -19,9 +19,9 @@ import org.jzy3d.plot3d.primitives.Shape; import org.jzy3d.plot3d.rendering.canvas.Quality; import org.jzy3d.plot3d.rendering.view.modes.ViewBoundMode; -public class TestManualBounds extends AbstractAnalysis { +public class PseudoTestManualBounds extends AbstractAnalysis { public static void main(String[] args) throws Exception { - IAnalysis d = new TestManualBounds(); + IAnalysis d = new PseudoTestManualBounds(); d.setCanvasType("newt"); AnalysisLauncher.open(d);