Skip to content

Commit

Permalink
Aligning java 2D and cdk rendering element path data types to use arr…
Browse files Browse the repository at this point in the history
…ays.

Signed-off-by: Stephan Beisken <sbeisken@gmail.com>
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 18, 2013
1 parent 01b8463 commit 5cc07ae
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public Close() {
public float[] points() {
return new float[0];
}

/** @inheritDoc */
@Override public void points(double[] coords) {
// N/A
}
}
68 changes: 50 additions & 18 deletions src/main/org/openscience/cdk/renderer/elements/path/CubicTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@
@TestClass("org.openscience.cdk.renderer.elements.path.CubicToTest")
public class CubicTo extends PathElement {

/** first control point in the cubic. */
public final Point2d cp1;

/** second control point in the cubic. */
public final Point2d cp2;

/** end point of the cubic. */
public final Point2d ep;
/** Coordinates of control point 1, control point 2 and end point. */
public final double[] coords;

/**
* Make a cubic curve path element.
Expand All @@ -55,21 +49,59 @@ public class CubicTo extends PathElement {
*/
@TestMethod("testConstructor")
public CubicTo(Point2d cp1, Point2d cp2, Point2d ep) {
super( Type.CubicTo );
this.cp1 = cp1;
this.cp2 = cp2;
this.ep = ep;
this(cp1.x, cp1.y, cp2.x, cp2.y, ep.x, ep.y);
}

/**
* Make a cubic curve path element.
*
* @param coords [0,1] : control point 1, [2,3] : control point 2, [4,5] end
* point
*/
public CubicTo(double[] coords) {
super(Type.CubicTo);
this.coords = new double[6];
this.coords[0] = coords[0];
this.coords[1] = coords[1];
this.coords[2] = coords[2];
this.coords[3] = coords[3];
this.coords[4] = coords[4];
this.coords[5] = coords[5];
}

/**
* Make a cubic curve path element.
*
* @param cp1x first control point in the cubic x coord
* @param cp1y first control point in the cubic y coord
* @param cp2x second control point in the cubic x coord
* @param cp2y second control point in the cubic y coord
* @param epx end point of the cubic x coord
* @param epy end point of the cubic y coord
*/
public CubicTo(double cp1x, double cp1y, double cp2x, double cp2y, double epx, double epy) {
this(new double[]{cp1x, cp1y, cp2x, cp2y, epx, epy});
}

/** {@inheritDoc} **/
@Override
@TestMethod("testPoints")
public float[] points() {
return new float[] { (float) cp1.x,
(float) cp1.y,
(float) cp2.x,
(float) cp2.y,
(float) ep.x,
(float) ep.y};
return new float[] { (float) coords[0],
(float) coords[1],
(float) coords[2],
(float) coords[3],
(float) coords[4],
(float) coords[5]};
}

/** @inheritDoc */
@Override public void points(double[] coords) {
coords[0] = this.coords[0];
coords[1] = this.coords[1];
coords[2] = this.coords[2];
coords[3] = this.coords[3];
coords[4] = this.coords[4];
coords[5] = this.coords[5];
}
}
35 changes: 31 additions & 4 deletions src/main/org/openscience/cdk/renderer/elements/path/LineTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class LineTo extends PathElement {

/** The point to make a line to. */
public final Point2d point;
public final double[] coords;

/**
* Make a line to this point.
Expand All @@ -48,14 +48,41 @@ public class LineTo extends PathElement {
*/
@TestMethod("testConstructor")
public LineTo(Point2d point) {
super( Type.LineTo );
this.point = point;
this(point.x, point.y);
}

/**
* Make a line path element.
*
* @param coords the x,y coordinates in index 0,1
*/
public LineTo(double[] coords) {
super(Type.LineTo);
this.coords = new double[2];
this.coords[0] = coords[0];
this.coords[1] = coords[1];
}

/**
* Make a line path element.
*
* @param x x coord
* @param y y coord
*/
public LineTo(double x, double y) {
this(new double[]{x, y});
}

/** {@inheritDoc} **/
@Override
@TestMethod("testPoints")
public float[] points() {
return new float[]{ (float) point.x, (float) point.y};
return new float[]{ (float) coords[0], (float) coords[1]};
}

/** @inheritDoc */
@Override public void points(double[] coords) {
coords[0] = this.coords[0];
coords[1] = this.coords[1];
}
}
35 changes: 31 additions & 4 deletions src/main/org/openscience/cdk/renderer/elements/path/MoveTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class MoveTo extends PathElement {

/** The point to move to.*/
public final Point2d point;
public final double[] coords;

/**
* Make a move to path element.
Expand All @@ -49,14 +49,41 @@ public class MoveTo extends PathElement {
*/
@TestMethod("testConstructor")
public MoveTo(Point2d point) {
super( Type.MoveTo );
this.point = point;
this(point.x, point.y);
}

/**
* Make a move to path element.
*
* @param coords the x,y coordinates in index 0,1
*/
public MoveTo(double[] coords) {
super(Type.MoveTo);
this.coords = new double[2];
this.coords[0] = coords[0];
this.coords[1] = coords[1];
}

/**
* Make a move to path element.
*
* @param x x coord
* @param y y coord
*/
public MoveTo(double x, double y) {
this(new double[]{x, y});
}

/** {@inheritDoc} **/
@Override
@TestMethod("testPoints")
public float[] points() {
return new float[]{ (float) point.x, (float) point.y};
return new float[]{ (float) coords[0], (float) coords[1]};
}

/** @inheritDoc */
@Override public void points(double[] coords) {
coords[0] = this.coords[0];
coords[1] = this.coords[1];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,14 @@ public PathElement( Type type ) {
*
* @return a list of points
*/
@Deprecated
public abstract float[] points();

/**
* Load the provided array with the specified coordinates of this path
* element.
*
* @param coords coordinates (length = 6)
*/
public abstract void points(double[] coords);
}
55 changes: 43 additions & 12 deletions src/main/org/openscience/cdk/renderer/elements/path/QuadTo.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@
@TestClass("org.openscience.cdk.renderer.elements.path.QuadToTest")
public class QuadTo extends PathElement {

/** control point of the curve. */
public final Point2d cp;

/** end point of the curve. */
public final Point2d ep;
/** Coordinates of control point and end point. */
public final double[] coords;

/**
* Make a quad curve.
Expand All @@ -52,18 +49,52 @@ public class QuadTo extends PathElement {
*/
@TestMethod("testConstructor")
public QuadTo(Point2d cp, Point2d ep) {
super( Type.QuadTo );
this.cp = cp;
this.ep = ep;
this(cp.x, cp.y, ep.x, ep.y);
}


/**
* Make a quad curve path element.
*
* @param coords [0,1] : control point 1, [2,3] : control point 2, [4,5] end
* point
*/
public QuadTo(double[] coords) {
super(Type.QuadTo);
this.coords = new double[4];
this.coords[0] = coords[0];
this.coords[1] = coords[1];
this.coords[2] = coords[2];
this.coords[3] = coords[3];
}

/**
* Make a quad curve path element.
*
* @param cpx control point in the cubic x coord
* @param cpy control point in the cubic y coord
* @param epx end point of the cubic x coord
* @param epy end point of the cubic y coord
*/
public QuadTo(double cpx, double cpy, double epx, double epy) {
this(new double[]{cpx, cpy, epx, epy});
}

/** {@inheritDoc} **/
@Override
@TestMethod("testPoints")
public float[] points() {
return new float[] { (float) cp.x,
(float) cp.y,
(float) ep.x,
(float) ep.y};
return new float[] { (float) coords[0],
(float) coords[1],
(float) coords[2],
(float) coords[3]};
}

/** @inheritDoc */
@Override public void points(double[] coords) {
coords[0] = this.coords[0];
coords[1] = this.coords[1];
coords[2] = this.coords[2];
coords[3] = this.coords[3];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,10 @@ public int getWindingRule() {
return path.winding;
}

public int currentSegment( double[] coords ) {
float[] src = new float[6];
int type = currentSegment( src );
double[] srcD = coords;
for(int i=0;i<src.length;i++){
srcD[i] = (double) src[i];
}
return type;
public int currentSegment(double[] coords) {
path.elements.get(index).points(coords);
transform.transform(coords, 0, coords, 0, 3);
return type(path.elements.get(index).type);
}

public int currentSegment( float[] coords ) {
Expand Down

0 comments on commit 5cc07ae

Please sign in to comment.