JavaLineRasterizerpublic class JavaLineRasterizer extends Object
Methods Summary |
---|
static int | clip(int dX1, int dX2, int cX, boolean top)Common clipping method
int adX1 = dX1 < 0 ? -dX1 : dX1;
int adX2 = dX2 < 0 ? -dX2 : dX2;
if (adX1 <= adX2) {
// obtuse intersection angle
return ((dX1 << 1) * cX + (dX1 > 0 ? dX2 : -dX2)) / (dX2 << 1);
}
int k;
if (top) {
k = -dX1 + (dX2 < 0 ? 0 : dX1 > 0 ? (dX2 << 1) : -(dX2 << 1));
} else {
k = dX1 + (dX2 > 0 ? 0 : dX1 > 0 ? (dX2 << 1) : -(dX2 << 1));
}
k += dX1 > 0 == dX2 > 0 ? -1 : 1;
return ((dX1 << 1) * cX + k) / (dX2 << 1);
| static int | clipX(int dx, int dy, int cy, boolean top)Clipping along X axis
return clip(dy, dx, cy, top);
| static int | clipY(int dx, int dy, int cx, boolean top)Clipping along Y axis
return clip(dx, dy, cx, top);
| public static org.apache.harmony.awt.gl.MultiRectArea | rasterize(int x1, int y1, int x2, int y2, org.apache.harmony.awt.gl.MultiRectArea clip, org.apache.harmony.awt.gl.render.JavaLineRasterizer$LineDasher dasher, boolean invert)Rasterizes line using clippind and dashing style
MultiRectArea dst = new MultiRectArea(false);
int dx = x2 - x1;
int dy = y2 - y1;
// Point
if (dx == 0 && dy == 0) {
if ((clip == null || clip.contains(x1, y1)) && (dasher == null || dasher.visible)) {
dst = new MultiRectArea(x1, y1, x1, y1);
}
return dst;
}
if (dy < 0) {
return rasterize(x2, y2, x1, y1, clip, dasher, true);
}
Line line;
if (dasher == null) {
if (dx == 0) {
line = new Line.Ortog.Ver(x1, y1, x2, y2, dst);
} else
if (dy == 0) {
line = new Line.Ortog.Hor(x1, y1, x2, y2, dst);
} else {
if (dy < Math.abs(dx)) {
line = new Line.Diag.Hor(x1, y1, x2, y2, dst);
} else {
line = new Line.Diag.Ver(x1, y1, x2, y2, dst);
}
}
} else {
if (dx == 0) {
line = new Line.Ortog.VerDashed(x1, y1, x2, y2, dst, dasher, invert);
} else
if (dy == 0) {
line = new Line.Ortog.HorDashed(x1, y1, x2, y2, dst, dasher);
} else {
if (dy < Math.abs(dx)) {
line = new Line.Diag.HorDashed(x1, y1, x2, y2, dst, dasher, invert);
} else {
line = new Line.Diag.VerDashed(x1, y1, x2, y2, dst, dasher, invert);
}
}
}
if (clip == null || clip.isEmpty()) {
line.rasterize();
} else {
for(int i = 1; i < clip.rect[0]; i += 4) {
line.rasterize(clip.rect, i);
}
}
return dst;
|
|