enhancement in circle drawing

pull/1/head
Michael Peter Christen 13 years ago
parent 34f4225d7e
commit e5ca7f22b1

@ -69,8 +69,8 @@ public class CircleTool {
crc.add(new short[]{x, y});
crds.add(co);
}
x = (short) (((double) r + 0.5) * Math.cos(Math.PI * a / (4 * r1)));
y = (short) (((double) r + 0.5) * Math.sin(Math.PI * a / (4 * r1)));
x = (short) ((r + 0.5) * Math.cos(Math.PI * a / (4 * r1)));
y = (short) ((r + 0.5) * Math.sin(Math.PI * a / (4 * r1)));
co = x + "|" + y;
if (!(crds.contains(co))) {
crc.add(new short[]{x, y});
@ -132,8 +132,11 @@ public class CircleTool {
} else {
final short[] c = getCircleCoords((short) radius);
final short q = (short) (c.length / 2);
final short[] c4x = new short[q * 4];
final short[] c4y = new short[q * 4];
final short q2 = (short) (q * 2);
final short q3 = (short) (q * 3);
final short q4 = (short) (q * 4);
final short[] c4x = new short[q4];
final short[] c4y = new short[q4];
short a0, a1, a2, a3, b0, b1;
for (short i = 0; i < q; i++) {
b0 = (short) (2 * (i ));
@ -144,27 +147,31 @@ public class CircleTool {
a3 = c[b1 + 1];
c4x[i ] = a0 ; // quadrant 1
c4y[i ] = (short) (-a1 - 1); // quadrant 1
c4x[i + q] = (short) ( 1 - a2); // quadrant 2
c4y[i + q] = (short) (-a3 - 1); // quadrant 2
c4x[i + 2 * q] = (short) ( 1 - a0); // quadrant 3
c4y[i + 2 * q] = a1 ; // quadrant 3
c4x[i + 3 * q] = a2 ; // quadrant 4
c4y[i + 3 * q] = a3 ; // quadrant 4
c4x[i + q ] = (short) ( 1 - a2); // quadrant 2
c4y[i + q ] = (short) (-a3 - 1); // quadrant 2
c4x[i + q2] = (short) ( 1 - a0); // quadrant 3
c4y[i + q2] = a1 ; // quadrant 3
c4x[i + q3] = a2 ; // quadrant 4
c4y[i + q3] = a3 ; // quadrant 4
}
if (fromArc == toArc) {
int i = q * 4 * fromArc / 360;
int i = q4 * fromArc / 360;
matrix.plot(xc + c4x[i], yc + c4y[i], 100);
} else if (fromArc > toArc) {
// draw two parts
for (int i = q * 4 * fromArc / 360; i < q * 4; i++) {
int from = q4 * fromArc / 360;
int to = q4 * toArc / 360;
for (int i = from; i < q4; i++) {
matrix.plot(xc + c4x[i], yc + c4y[i], 100);
}
for (int i = 0; i < q * 4 * toArc / 360; i++) {
for (int i = 0; i < to; i++) {
matrix.plot(xc + c4x[i], yc + c4y[i], 100);
}
} else {
// can be drawn in one part
for (int i = q * 4 * fromArc / 360; i < q * 4 * toArc / 360; i++) {
int from = q4 * fromArc / 360;
int to = q4 * toArc / 360;
for (int i = from; i < to; i++) {
matrix.plot(xc + c4x[i], yc + c4y[i], 100);
}
}

Loading…
Cancel
Save