FileDocCategorySizeDatePackage
JavaLineRasterizer.javaAPI DocAndroid 1.5 API25059Wed May 06 22:41:54 BST 2009org.apache.harmony.awt.gl.render

JavaLineRasterizer

public class JavaLineRasterizer extends Object
author
Denis M. Kishenko
version
$Revision$

Fields Summary
Constructors Summary
Methods Summary
static intclip(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 intclipX(int dx, int dy, int cy, boolean top)
Clipping along X axis

        return clip(dy, dx, cy, top);
    
static intclipY(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.MultiRectArearasterize(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

param
x1 - the x coordinate of the first control point
param
y1 - the y coordinate of the first control point
param
x2 - the x coordinate of the second control point
param
y2 - the y coordinate of the second control point
param
clip - the MultiRectArea object of clipping area
param
dasher - the dasher style
param
invert - the invert indicator, always false
return
a MultiRectArea of rasterizer line


        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;