Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jzy3d committed May 24, 2022
2 parents 091654a + 7442aee commit ca2cdd2
Show file tree
Hide file tree
Showing 44 changed files with 475 additions and 268 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.jzy3d.mocks.jzy3d;

import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.AWTView;

public class AWTViewMock extends AWTView {

public AWTViewMock(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super(factory, scene, canvas, quality);
}

protected int counter_shoot = 0;
protected int counter_initInstance = 0;

@Override
public void initInstance(IChartFactory factory, Scene scene, ICanvas canvas, Quality quality) {
super.initInstance(factory, scene, canvas, quality);

counter_initInstance+=1;
}

@Override
public void shoot() {
super.shoot();

counter_shoot++;
}

public int getCounter_shoot() {
return counter_shoot;
}

public void resetCounter_shoot() {
this.counter_shoot = 0;
}

public int getCounter_initInstance() {
return counter_initInstance;
}

//public void resetCounter_initInstance() {
// this.counter_initInstance = 0;
// }



/*
* verify(chart.getView(), atLeast(1)).initInstance(factory, chart.getScene(), canvas,
chart.getQuality());
verify(chart.getView(), atLeast(1)).shoot();
// undesired
verify(chart.getView(), atLeast(1)).shoot(); // VIEW IS CALLED 2 OR 3 TIMES !!!!!!!!!!!!!!!!!!!!!!
// Then camera was called at least once
verify(chart.getView().getCamera(), atLeast(1)).shoot(chart.getPainter(),
chart.getView().getCameraMode());
*
*/
}
2 changes: 1 addition & 1 deletion jzy3d-core/data/objfiles/bunny.url
Original file line number Diff line number Diff line change
@@ -1 +1 @@
http://download.jzy3d.org/objfiles/bunny.obj
https://download.jzy3d.org/objfiles/bunny.obj
2 changes: 1 addition & 1 deletion jzy3d-core/data/objfiles/dragon.url
Original file line number Diff line number Diff line change
@@ -1 +1 @@
http://download.jzy3d.org/objfiles/dragon.obj
https://download.jzy3d.org/objfiles/dragon.obj
2 changes: 1 addition & 1 deletion jzy3d-core/src/main/java/org/jzy3d/maths/Coord2d.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Coord2d polar() {

/**
* Return a real polar value, with an angle in the range [0;2*PI]
* http://fr.wikipedia.org/wiki/Coordonn%C3%A9es_polaires
* https://en.wikipedia.org/wiki/Polar_coordinate_system
*/
public Coord2d fullPolar() {
double radius = Math.sqrt(x * x + y * y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* <p>
* This is a generic 3D B-Spline class for curves of arbitrary length, control handles and patches
* are created and joined automatically as described here:
* <a href="http://www.ibiblio.org/e-notes/Splines/Bint.htm">ibiblio.org/e-notes/
* <a href="https://www.ibiblio.org/e-notes/Splines/Bint.htm">ibiblio.org/e-notes/
* Splines/Bint.htm</a>
* </p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected void drawFace(IPainter painter) {
polygonOffsetFillDisable(painter); // DISABLE OFFSET

if (wireframeDisplayed && polygonWireframeDepthTrick)
applyDepthRangeDefault(painter); // DISAABLE RANGE FOR UNDER
applyDepthRangeDefault(painter); // DISABLE RANGE FOR UNDER

}
}
Expand Down
22 changes: 11 additions & 11 deletions jzy3d-core/src/main/java/org/jzy3d/plot3d/primitives/LineStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* Dotted line are built using
*
* http://www.glprogramming.com/red/images/Image35.gif
* https://www.glprogramming.com/red/images/Image35.gif
*
* @author Martin Pernollet
*/
Expand Down Expand Up @@ -316,7 +316,7 @@ public void setShowSymbols(boolean showSymbols) {
/**
* Indicates if stippled rendering is enabled for this line.
*
* @see http://www.glprogramming.com/red/chapter02.html (Stippled line section)
* @see https://www.glprogramming.com/red/chapter02.html (Stippled line section)
*/
public boolean isStipple() {
return stipple;
Expand All @@ -325,7 +325,7 @@ public boolean isStipple() {
/**
* Enable or disable stippled rendering.
*
* @see http://www.glprogramming.com/red/chapter02.html (Stippled line section)
* @see https://www.glprogramming.com/red/chapter02.html (Stippled line section)
*/
public void setStipple(boolean stipple) {
this.stipple = stipple;
Expand All @@ -334,8 +334,8 @@ public void setStipple(boolean stipple) {
/**
* Stippled line factor.
*
* @see http://www.glprogramming.com/red/images/Image35.gif
* @see http://www.glprogramming.com/red/chapter02.html (Stippled line section)
* @see https://www.glprogramming.com/red/images/Image35.gif
* @see https://www.glprogramming.com/red/chapter02.html (Stippled line section)
*/
public int getStippleFactor() {
return stippleFactor;
Expand All @@ -344,8 +344,8 @@ public int getStippleFactor() {
/**
* Stippled line factor.
*
* @see http://www.glprogramming.com/red/images/Image35.gif
* @see http://www.glprogramming.com/red/chapter02.html (Stippled line section)
* @see https://www.glprogramming.com/red/images/Image35.gif
* @see https://www.glprogramming.com/red/chapter02.html (Stippled line section)
*/
public void setStippleFactor(int stippleFactor) {
this.stippleFactor = stippleFactor;
Expand All @@ -354,8 +354,8 @@ public void setStippleFactor(int stippleFactor) {
/**
* Stippled line pattern.
*
* @see http://www.glprogramming.com/red/images/Image35.gif
* @see http://www.glprogramming.com/red/chapter02.html (Stippled line section)
* @see https://www.glprogramming.com/red/images/Image35.gif
* @see https://www.glprogramming.com/red/chapter02.html (Stippled line section)
*/
public short getStipplePattern() {
return stipplePattern;
Expand All @@ -364,8 +364,8 @@ public short getStipplePattern() {
/**
* Stippled line pattern.
*
* @see http://www.glprogramming.com/red/images/Image35.gif
* @see http://www.glprogramming.com/red/chapter02.html (Stippled line section)
* @see https://www.glprogramming.com/red/images/Image35.gif
* @see https://www.glprogramming.com/red/chapter02.html (Stippled line section)
*/
public void setStipplePattern(short stipplePattern) {
this.stipplePattern = stipplePattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public AxisBox(BoundingBox3d bbox, AxisLayout layout) {
}

/**
* Draws the AxeBox. The camera is used to determine which axis is closest to the ur point ov
* Draws the AxisBox. The camera is used to determine which axis is closest to the ur point ov
* view, in order to decide for an axis on which to diplay the tick values.
*/
@Override
Expand Down Expand Up @@ -142,8 +142,6 @@ protected void drawAnnotations(IPainter painter) {

/**
* reset to identity and apply scaling
*
* @param painter TODO
*/
public void doTransform(IPainter painter) {
painter.glLoadIdentity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void apply(IPainter painter, Coord3d scale) {
}
}

// http://www.sjbaker.org/steve/omniv/opengl_lighting.html
// https://www.sjbaker.org/steve/omniv/opengl_lighting.html
protected void initLight(IPainter painter) {
painter.glEnable_ColorMaterial();
painter.glEnable_Lighting();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ public void shoot(IPainter painter, CameraMode projection, boolean doPushMatrixB
public void doShoot(IPainter painter, CameraMode projection) {
// Set viewport
ViewportConfiguration viewport = applyViewport(painter);

// Set projection
if (projection == CameraMode.PERSPECTIVE) {
projectionPerspective(painter, viewport);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* It is define by a width and height, and support an X and Y offset
*
* @see http://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml
* @see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glViewport.xhtml
* @author Martin Pernollet
*/
public class ViewportConfiguration {
Expand Down
17 changes: 8 additions & 9 deletions jzy3d-core/src/test/java/org/jzy3d/mocks/jzy3d/Mocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import org.jzy3d.plot3d.rendering.canvas.ICanvasListener;
import org.jzy3d.plot3d.rendering.view.View;
import org.mockito.Mockito;
import org.smurn.jply.util.Axis;

public class Mocks {
public static AxisLayout AxisLayout() {
return mock(AxisLayout.class);
}

public static AxisBox Axis() {
return mock(AxisBox.class);
}
Expand All @@ -31,17 +30,17 @@ public static AxisBox Axis(AxisLayout layout) {
when(axis.getLayout()).thenReturn(layout);
return axis;
}

public static View View2D() {
View view = mock(View.class);
when(view.is2D()).thenReturn(true);
return view;
}

public static View View() {
return Mockito.mock(View.class);
}

public static View View(AxisBox axis, IPainter painter) {
return View(axis, painter, null);
}
Expand All @@ -55,7 +54,7 @@ public static View View(AxisBox axis, IPainter painter, ICanvas canvas) {
return view;
}


public static View ViewAndPainter(float viewScale) {
return ViewAndPainter(viewScale, "macos", "10", null, null);
}
Expand All @@ -68,7 +67,7 @@ public static View ViewAndPainter(float viewScale, String os, String version, Co
IPainter painter = Painter(os, version);

ICanvas canvas = mock(ICanvas.class);

if (gpuScale != null)
when(canvas.getPixelScale()).thenReturn(gpuScale);
if (jvmScale != null)
Expand Down Expand Up @@ -101,7 +100,7 @@ public static ICanvas Canvas(boolean isNative) {
when(canvas.isNative()).thenReturn(isNative);
return canvas;
}

public static ICanvas Canvas(Coord2d scaleHard, Coord2d scaleVM) {
return new ICanvas() {
@Override
Expand Down Expand Up @@ -178,7 +177,7 @@ public void removeCanvasListener(ICanvasListener listener) {}
public List<ICanvasListener> getCanvasListeners() {
return null;
}

@Override
public boolean isNative() {
return true;
Expand Down
7 changes: 7 additions & 0 deletions jzy3d-emul-gl-awt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
<artifactId>jzy3d-core-awt</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jzy3d-core-awt</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import org.jzy3d.chart.AWTChart;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.controllers.thread.camera.CameraThreadControllerWithTime;
import org.jzy3d.painters.EmulGLPainter;
import org.jzy3d.plot3d.rendering.canvas.EmulGLCanvas;
import org.jzy3d.plot3d.rendering.canvas.ICanvas;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.AWTView;
import org.jzy3d.plot3d.rendering.view.modes.ViewBoundMode;
import jgl.wt.awt.GL;

public class EmulGLChartFactory extends ChartFactory {
public EmulGLChartFactory() {
Expand Down Expand Up @@ -38,5 +41,28 @@ public CameraThreadControllerWithTime newCameraThreadController(Chart chart) {
CameraThreadControllerWithTime controller = new CameraThreadControllerWithTime(chart, 60);
return controller;
}

/**
* This return a factory with a custom GL instance which can be used for manual mocking
* @return
*/
public static EmulGLChartFactory forGL(GL glMock) {

// Given a surface chart with a mock GL injected for spying calls to glDepthRange
EmulGLPainterFactory painterF = new EmulGLPainterFactory() {
protected EmulGLCanvas newEmulGLCanvas(IChartFactory factory, Scene scene, Quality quality) {
EmulGLCanvas c = new EmulGLCanvas(factory, scene, quality);
c.setGL(glMock);
return c;
}
};

EmulGLChartFactory factory = new EmulGLChartFactory(painterF);
Chart chart = factory.newChart(Quality.Advanced());
EmulGLPainter painter = (EmulGLPainter)chart.getPainter();
painter.setGL(glMock); // << spy

return factory;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ public int getTextLengthInPixels(Font font, String string) {
// Try getting an offscreen image graphics
if(g==null) {
BufferedImage image = getGL().getRenderedImage();
g = image.getGraphics();
if(image!=null) {
g = image.getGraphics();
}
}

// Hope to have a graphics and process string width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import org.junit.Ignore;
import org.junit.Test;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.factories.EmulGLChartFactory;
Expand All @@ -21,10 +22,10 @@
import org.jzy3d.plot3d.rendering.canvas.Quality;

/**
* {@AxisBox} and
* @author martin
*
*/
@Ignore("This test is replaced by TestShape and TestAxisBox which handle mocking more efficiently")
public class TestDepthRange {
@Test
public void whenRenderAxis_DepthRangeModifiedByAxis() {
Expand Down
Loading

0 comments on commit ca2cdd2

Please sign in to comment.