Added tests on view bounds

This commit is contained in:
martin 2022-09-10 12:44:21 +02:00
parent 10655cf211
commit f57d8de263
3 changed files with 62 additions and 7 deletions

View File

@ -608,7 +608,7 @@ public class View {
}
protected BoundingBox3d getSceneGraphBounds(Scene scene) {
return squarifyGetSceneGraphBounds(scene);
return scene.getGraph().getBounds();
}
/**
@ -674,7 +674,7 @@ public class View {
protected void initBounds() {
if (viewBounds == null) {
viewBounds = squarifyGetSceneGraphBounds(scene);
viewBounds = scene.getGraph().getBounds();
}
lookToBox(viewBounds);
}
@ -845,7 +845,7 @@ public class View {
// Get the view bounds
BoundingBox3d bounds;
if (boundmode == ViewBoundMode.AUTO_FIT) {
bounds = squarifyGetSceneGraphBounds(scene);
bounds = scene.getGraph().getBounds();
} else if (boundmode == ViewBoundMode.MANUAL) {
/*
* if(scene.getGraph().getClipBox()!=null) { bounds = squarifyGetSceneGraphBounds(scene); }
@ -894,10 +894,6 @@ public class View {
/* LAYOUT */
protected BoundingBox3d squarifyGetSceneGraphBounds(Scene scene) {
return scene.getGraph().getBounds();
}
protected Coord3d squarifyComputeBoundsRanges(BoundingBox3d bounds) {
if (spaceTransformer == null) {
return bounds.getRange();

View File

@ -0,0 +1,55 @@
package org.jzy3d.plot3d.rendering.view;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Assert;
import org.junit.Test;
import org.jzy3d.maths.BoundingBox3d;
import org.jzy3d.plot3d.primitives.axis.AxisBox;
import org.jzy3d.plot3d.rendering.scene.Graph;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.modes.ViewBoundMode;
public class TestView {
@Test
public void whenViewBoundsMode_ThenCameraHasBounds() {
// Given
Graph graph = mock(Graph.class);
Scene scene = mock(Scene.class);
when(scene.getGraph()).thenReturn(graph);
View view = new View();
view.scene = scene;
view.cam = mock(Camera.class);
view.axis = new AxisBox();
// bounds are stored in axisbox
// so we don't mock it
// -------------------------------------
// When setting bounds to AUTO_FIT
BoundingBox3d bounds = new BoundingBox3d(0,1,0,1,0,1);
when(graph.getBounds()).thenReturn(bounds);
view.setBoundMode(ViewBoundMode.AUTO_FIT);
// Then bounds are those the whole scene graph
Assert.assertEquals(bounds, view.getBounds());
// -------------------------------------
// When setting bounds to MANUAL
BoundingBox3d boundsManual = new BoundingBox3d(0,10,0,10,0,10);
when(graph.getBounds()).thenReturn(null); // ensure graph can't be invoked
view.setBoundsManual(boundsManual);
//view.updateBounds();
// Then bounds are those the whole scene graph
Assert.assertEquals(boundsManual, view.getBounds());
}
}

View File

@ -19,6 +19,9 @@ import org.jzy3d.plot3d.rendering.view.View;
import org.jzy3d.plot3d.rendering.view.View2DLayout;
import org.jzy3d.plot3d.rendering.view.modes.ViewPositionMode;
/**
* Integration test
*/
public class TestView {
private static final double tolerance = 0.001;
@ -430,5 +433,6 @@ public class TestView {
Assert.assertEquals(new Coord3d(dir.x,dir.y,0), view.getCamera().getUp());
}
}