Java Code Examples for java.awt.geom.AffineTransform#getShearY()

The following examples show how to use java.awt.geom.AffineTransform#getShearY() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sis   File: AffineTransforms2D.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the inverse transform of a point without applying the translation components.
 * In other words, calculates the inverse transform of a displacement vector.
 *
 * @param  transform  the affine transform to use.
 * @param  vector     the vector to transform stored as a point.
 *                    this point will not be modified except if {@code dest} references the same object.
 * @param  dest       point in which to place the result. If {@code null}, a new point will be created.
 * @return the inverse transform of the {@code vector}, or {@code null} if {@code source} was null.
 * @throws NoninvertibleTransformException if the affine transform can't be inverted.
 */
public static Point2D inverseDeltaTransform(final AffineTransform transform,
        final Point2D vector, final Point2D dest) throws NoninvertibleTransformException
{
    ArgumentChecks.ensureNonNull("transform", transform);
    if (vector == null) {
        return null;
    }
    final double m00 = transform.getScaleX();
    final double m11 = transform.getScaleY();
    final double m01 = transform.getShearX();
    final double m10 = transform.getShearY();
    final double det = m00*m11 - m01*m10;
    if (!(abs(det) > Double.MIN_VALUE)) {
        throw new NoninvertibleTransformException(null);
    }
    final double x0 = vector.getX();
    final double y0 = vector.getY();
    final double x = (x0*m11 - y0*m01) / det;
    final double y = (y0*m00 - x0*m10) / det;
    if (dest != null) {
        dest.setLocation(x, y);
        return dest;
    }
    return new Point2D.Double(x, y);
}
 
Example 2
public static PathConsumer2D
    inverseDeltaTransformConsumer(PathConsumer2D out,
                                  AffineTransform at)
{
    if (at == null) {
        return out;
    }
    float Mxx = (float) at.getScaleX();
    float Mxy = (float) at.getShearX();
    float Myx = (float) at.getShearY();
    float Myy = (float) at.getScaleY();
    if (Mxy == 0f && Myx == 0f) {
        if (Mxx == 1f && Myy == 1f) {
            return out;
        } else {
            return new DeltaScaleFilter(out, 1.0f/Mxx, 1.0f/Myy);
        }
    } else {
        float det = Mxx * Myy - Mxy * Myx;
        return new DeltaTransformFilter(out,
                                        Myy / det,
                                        -Mxy / det,
                                        -Myx / det,
                                        Mxx / det);
    }
}
 
Example 3
DPathConsumer2D inverseDeltaTransformConsumer(DPathConsumer2D out,
                                             AffineTransform at)
{
    if (at == null) {
        return out;
    }
    double mxx = at.getScaleX();
    double mxy = at.getShearX();
    double myx = at.getShearY();
    double myy = at.getScaleY();

    if (mxy == 0.0d && myx == 0.0d) {
        if (mxx == 1.0d && myy == 1.0d) {
            return out;
        } else {
            return iv_DeltaScaleFilter.init(out, 1.0d / mxx, 1.0d / myy);
        }
    } else {
        final double det = mxx * myy - mxy * myx;
        return iv_DeltaTransformFilter.init(out,
                                            myy / det,
                                           -mxy / det,
                                           -myx / det,
                                            mxx / det);
    }
}
 
Example 4
public static PathConsumer2D
    deltaTransformConsumer(PathConsumer2D out,
                           AffineTransform at)
{
    if (at == null) {
        return out;
    }
    float Mxx = (float) at.getScaleX();
    float Mxy = (float) at.getShearX();
    float Myx = (float) at.getShearY();
    float Myy = (float) at.getScaleY();
    if (Mxy == 0f && Myx == 0f) {
        if (Mxx == 1f && Myy == 1f) {
            return out;
        } else {
            return new DeltaScaleFilter(out, Mxx, Myy);
        }
    } else {
        return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
    }
}
 
Example 5
private static boolean matchTX(double[] lhs, AffineTransform rhs) {
    return
        lhs[0] == rhs.getScaleX() &&
        lhs[1] == rhs.getShearY() &&
        lhs[2] == rhs.getShearX() &&
        lhs[3] == rhs.getScaleY();
}
 
Example 6
public static PathConsumer2D
    transformConsumer(PathConsumer2D out,
                      AffineTransform at)
{
    if (at == null) {
        return out;
    }
    float Mxx = (float) at.getScaleX();
    float Mxy = (float) at.getShearX();
    float Mxt = (float) at.getTranslateX();
    float Myx = (float) at.getShearY();
    float Myy = (float) at.getScaleY();
    float Myt = (float) at.getTranslateY();
    if (Mxy == 0f && Myx == 0f) {
        if (Mxx == 1f && Myy == 1f) {
            if (Mxt == 0f && Myt == 0f) {
                return out;
            } else {
                return new TranslateFilter(out, Mxt, Myt);
            }
        } else {
            if (Mxt == 0f && Myt == 0f) {
                return new DeltaScaleFilter(out, Mxx, Myy);
            } else {
                return new ScaleFilter(out, Mxx, Myy, Mxt, Myt);
            }
        }
    } else if (Mxt == 0f && Myt == 0f) {
        return new DeltaTransformFilter(out, Mxx, Mxy, Myx, Myy);
    } else {
        return new TransformFilter(out, Mxx, Mxy, Mxt, Myx, Myy, Myt);
    }
}
 
Example 7
PathConsumer2D deltaTransformConsumer(PathConsumer2D out,
                                      AffineTransform at)
{
    if (at == null) {
        return out;
    }
    final float mxx = (float) at.getScaleX();
    final float mxy = (float) at.getShearX();
    final float myx = (float) at.getShearY();
    final float myy = (float) at.getScaleY();

    if (mxy == 0.0f && myx == 0.0f) {
        if (mxx == 1.0f && myy == 1.0f) {
            return out;
        } else {
            // Scale only
            if (rdrCtx.doClip) {
                // adjust clip rectangle (ymin, ymax, xmin, xmax):
                rdrCtx.clipInvScale = adjustClipScale(rdrCtx.clipRect,
                    mxx, myy);
            }
            return dt_DeltaScaleFilter.init(out, mxx, myy);
        }
    } else {
        if (rdrCtx.doClip) {
            // adjust clip rectangle (ymin, ymax, xmin, xmax):
            rdrCtx.clipInvScale = adjustClipInverseDelta(rdrCtx.clipRect,
                mxx, mxy, myx, myy);
        }
        return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
    }
}
 
Example 8
public void fillRectangle(SunGraphics2D sg2d,
                          double rx, double ry,
                          double rw, double rh)
{
    double px, py;
    double dx1, dy1, dx2, dy2;
    AffineTransform txform = sg2d.transform;
    dx1 = txform.getScaleX();
    dy1 = txform.getShearY();
    dx2 = txform.getShearX();
    dy2 = txform.getScaleY();
    px = rx * dx1 + ry * dx2 + txform.getTranslateX();
    py = rx * dy1 + ry * dy2 + txform.getTranslateY();
    dx1 *= rw;
    dy1 *= rw;
    dx2 *= rh;
    dy2 *= rh;
    if (adjustfill &&
        sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
        sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
    {
        double newx = normalize(px);
        double newy = normalize(py);
        dx1 = normalize(px + dx1) - newx;
        dy1 = normalize(py + dy1) - newy;
        dx2 = normalize(px + dx2) - newx;
        dy2 = normalize(py + dy2) - newy;
        px = newx;
        py = newy;
    }
    outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh,
                                  px, py, dx1, dy1, dx2, dy2);
}
 
Example 9
Source Project: gcs   File: Matrix.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a matrix with the same elements as the given AffineTransform.
 * @param at
 */
public Matrix(AffineTransform at)
{
    single = new float[DEFAULT_SINGLE.length];
    System.arraycopy(DEFAULT_SINGLE, 0, single, 0, DEFAULT_SINGLE.length);
    single[0] = (float)at.getScaleX();
    single[1] = (float)at.getShearY();
    single[3] = (float)at.getShearX();
    single[4] = (float)at.getScaleY();
    single[6] = (float)at.getTranslateX();
    single[7] = (float)at.getTranslateY();
}
 
Example 10
public void fillRectangle(SunGraphics2D sg2d,
                          double rx, double ry,
                          double rw, double rh)
{
    double px, py;
    double dx1, dy1, dx2, dy2;
    AffineTransform txform = sg2d.transform;
    dx1 = txform.getScaleX();
    dy1 = txform.getShearY();
    dx2 = txform.getShearX();
    dy2 = txform.getScaleY();
    px = rx * dx1 + ry * dx2 + txform.getTranslateX();
    py = rx * dy1 + ry * dy2 + txform.getTranslateY();
    dx1 *= rw;
    dy1 *= rw;
    dx2 *= rh;
    dy2 *= rh;
    if (adjustfill &&
        sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
        sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
    {
        double newx = normalize(px);
        double newy = normalize(py);
        dx1 = normalize(px + dx1) - newx;
        dy1 = normalize(py + dy1) - newy;
        dx2 = normalize(px + dx2) - newx;
        dy2 = normalize(py + dy2) - newy;
        px = newx;
        py = newy;
    }
    outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh,
                                  px, py, dx1, dy1, dx2, dy2);
}
 
Example 11
DPathConsumer2D deltaTransformConsumer(DPathConsumer2D out,
                                      AffineTransform at)
{
    if (at == null) {
        return out;
    }
    final double mxx = at.getScaleX();
    final double mxy = at.getShearX();
    final double myx = at.getShearY();
    final double myy = at.getScaleY();

    if (mxy == 0.0d && myx == 0.0d) {
        if (mxx == 1.0d && myy == 1.0d) {
            return out;
        } else {
            // Scale only
            if (rdrCtx.doClip) {
                // adjust clip rectangle (ymin, ymax, xmin, xmax):
                rdrCtx.clipInvScale = adjustClipScale(rdrCtx.clipRect,
                    mxx, myy);
            }
            return dt_DeltaScaleFilter.init(out, mxx, myy);
        }
    } else {
        if (rdrCtx.doClip) {
            // adjust clip rectangle (ymin, ymax, xmin, xmax):
            rdrCtx.clipInvScale = adjustClipInverseDelta(rdrCtx.clipRect,
                mxx, mxy, myx, myy);
        }
        return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy);
    }
}
 
Example 12
private static boolean matchTX(double[] lhs, AffineTransform rhs) {
    return
        lhs[0] == rhs.getScaleX() &&
        lhs[1] == rhs.getShearY() &&
        lhs[2] == rhs.getShearX() &&
        lhs[3] == rhs.getScaleY();
}
 
Example 13
Source Project: Bytecoder   File: StandardGlyphVector.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean matchTX(double[] lhs, AffineTransform rhs) {
    return
        lhs[0] == rhs.getScaleX() &&
        lhs[1] == rhs.getShearY() &&
        lhs[2] == rhs.getShearX() &&
        lhs[3] == rhs.getScaleY();
}
 
Example 14
Source Project: TrakEM2   File: Stack.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Estimate the scale of atp to apply the
 * appropriate smoothing to the image.
 */
final static private double estimateAffineScale( final AffineTransform atp )
{
	final double dxx = atp.getScaleX();
	final double dxy = atp.getShearY();
	final double dxs = dxx * dxx + dxy * dxy;

	final double dyx = atp.getShearX();
	final double dyy = atp.getScaleY();
	final double dys = dyx * dyx + dyy * dyy;

	return Math.sqrt( Math.max( dxs, dys ) );
}
 
Example 15
public void fillRectangle(SunGraphics2D sg2d,
                          double rx, double ry,
                          double rw, double rh)
{
    double px, py;
    double dx1, dy1, dx2, dy2;
    AffineTransform txform = sg2d.transform;
    dx1 = txform.getScaleX();
    dy1 = txform.getShearY();
    dx2 = txform.getShearX();
    dy2 = txform.getScaleY();
    px = rx * dx1 + ry * dx2 + txform.getTranslateX();
    py = rx * dy1 + ry * dy2 + txform.getTranslateY();
    dx1 *= rw;
    dy1 *= rw;
    dx2 *= rh;
    dy2 *= rh;
    if (adjustfill &&
        sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
        sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
    {
        double newx = normalize(px);
        double newy = normalize(py);
        dx1 = normalize(px + dx1) - newx;
        dy1 = normalize(py + dy1) - newy;
        dx2 = normalize(px + dx2) - newx;
        dy2 = normalize(py + dy2) - newy;
        px = newx;
        py = newy;
    }
    outrenderer.fillParallelogram(sg2d, rx, ry, rx+rw, ry+rh,
                                  px, py, dx1, dy1, dx2, dy2);
}
 
Example 16
private float userSpaceLineWidth(AffineTransform at, float lw) {

        double widthScale;

        if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM |
                            AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
            widthScale = Math.sqrt(at.getDeterminant());
        } else {
            /* First calculate the "maximum scale" of this transform. */
            double A = at.getScaleX();       // m00
            double C = at.getShearX();       // m01
            double B = at.getShearY();       // m10
            double D = at.getScaleY();       // m11

            /*
             * Given a 2 x 2 affine matrix [ A B ] such that
             *                             [ C D ]
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
             * find the maximum magnitude (norm) of the vector v'
             * with the constraint (x^2 + y^2 = 1).
             * The equation to maximize is
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
             * Since sqrt is monotonic we can maximize |v'|^2
             * instead and plug in the substitution y = sqrt(1 - x^2).
             * Trigonometric equalities can then be used to get
             * rid of most of the sqrt terms.
             */

            double EA = A*A + B*B;          // x^2 coefficient
            double EB = 2*(A*C + B*D);      // xy coefficient
            double EC = C*C + D*D;          // y^2 coefficient

            /*
             * There is a lot of calculus omitted here.
             *
             * Conceptually, in the interests of understanding the
             * terms that the calculus produced we can consider
             * that EA and EC end up providing the lengths along
             * the major axes and the hypot term ends up being an
             * adjustment for the additional length along the off-axis
             * angle of rotated or sheared ellipses as well as an
             * adjustment for the fact that the equation below
             * averages the two major axis lengths.  (Notice that
             * the hypot term contains a part which resolves to the
             * difference of these two axis lengths in the absence
             * of rotation.)
             *
             * In the calculus, the ratio of the EB and (EA-EC) terms
             * ends up being the tangent of 2*theta where theta is
             * the angle that the long axis of the ellipse makes
             * with the horizontal axis.  Thus, this equation is
             * calculating the length of the hypotenuse of a triangle
             * along that axis.
             */

            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
            /* sqrt omitted, compare to squared limits below. */
            double widthsquared = ((EA + EC + hypot)/2.0);

            widthScale = Math.sqrt(widthsquared);
        }

        return (float) (lw / widthScale);
    }
 
Example 17
private static boolean equalNonTranslateTX(AffineTransform lhs, AffineTransform rhs) {
    return lhs.getScaleX() == rhs.getScaleX() &&
        lhs.getShearY() == rhs.getShearY() &&
        lhs.getShearX() == rhs.getShearX() &&
        lhs.getScaleY() == rhs.getScaleY();
}
 
Example 18
public void drawRectangle(SunGraphics2D sg2d,
                          double rx, double ry,
                          double rw, double rh,
                          double lw)
{
    double px, py;
    double dx1, dy1, dx2, dy2;
    double lw1, lw2;
    AffineTransform txform = sg2d.transform;
    dx1 = txform.getScaleX();
    dy1 = txform.getShearY();
    dx2 = txform.getShearX();
    dy2 = txform.getScaleY();
    px = rx * dx1 + ry * dx2 + txform.getTranslateX();
    py = rx * dy1 + ry * dy2 + txform.getTranslateY();
    // lw along dx1,dy1 scale by transformed length of dx2,dy2 vectors
    // and vice versa
    lw1 = len(dx1, dy1) * lw;
    lw2 = len(dx2, dy2) * lw;
    dx1 *= rw;
    dy1 *= rw;
    dx2 *= rh;
    dy2 *= rh;
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
        sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
    {
        double newx = normalize(px);
        double newy = normalize(py);
        dx1 = normalize(px + dx1) - newx;
        dy1 = normalize(py + dy1) - newy;
        dx2 = normalize(px + dx2) - newx;
        dy2 = normalize(py + dy2) - newy;
        px = newx;
        py = newy;
    }
    lw1 = Math.max(lw1, minPenSize);
    lw2 = Math.max(lw2, minPenSize);
    double len1 = len(dx1, dy1);
    double len2 = len(dx2, dy2);
    if (lw1 >= len1 || lw2 >= len2) {
        // The line widths are large enough to consume the
        // entire hole in the middle of the parallelogram
        // so we can just fill the outer parallelogram.
        fillOuterParallelogram(sg2d,
                               rx, ry, rx+rw, ry+rh,
                               px, py, dx1, dy1, dx2, dy2,
                               len1, len2, lw1, lw2);
    } else {
        outrenderer.drawParallelogram(sg2d,
                                      rx, ry, rx+rw, ry+rh,
                                      px, py, dx1, dy1, dx2, dy2,
                                      lw1 / len1, lw2 / len2);
    }
}
 
Example 19
public void drawRectangle(SunGraphics2D sg2d,
                          double rx, double ry,
                          double rw, double rh,
                          double lw)
{
    double px, py;
    double dx1, dy1, dx2, dy2;
    double lw1, lw2;
    AffineTransform txform = sg2d.transform;
    dx1 = txform.getScaleX();
    dy1 = txform.getShearY();
    dx2 = txform.getShearX();
    dy2 = txform.getScaleY();
    px = rx * dx1 + ry * dx2 + txform.getTranslateX();
    py = rx * dy1 + ry * dy2 + txform.getTranslateY();
    // lw along dx1,dy1 scale by transformed length of dx2,dy2 vectors
    // and vice versa
    lw1 = len(dx1, dy1) * lw;
    lw2 = len(dx2, dy2) * lw;
    dx1 *= rw;
    dy1 *= rw;
    dx2 *= rh;
    dy2 *= rh;
    if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM &&
        sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE)
    {
        double newx = normalize(px);
        double newy = normalize(py);
        dx1 = normalize(px + dx1) - newx;
        dy1 = normalize(py + dy1) - newy;
        dx2 = normalize(px + dx2) - newx;
        dy2 = normalize(py + dy2) - newy;
        px = newx;
        py = newy;
    }
    lw1 = Math.max(lw1, minPenSize);
    lw2 = Math.max(lw2, minPenSize);
    double len1 = len(dx1, dy1);
    double len2 = len(dx2, dy2);
    if (lw1 >= len1 || lw2 >= len2) {
        // The line widths are large enough to consume the
        // entire hole in the middle of the parallelogram
        // so we can just fill the outer parallelogram.
        fillOuterParallelogram(sg2d,
                               rx, ry, rx+rw, ry+rh,
                               px, py, dx1, dy1, dx2, dy2,
                               len1, len2, lw1, lw2);
    } else {
        outrenderer.drawParallelogram(sg2d,
                                      rx, ry, rx+rw, ry+rh,
                                      px, py, dx1, dy1, dx2, dy2,
                                      lw1 / len1, lw2 / len2);
    }
}
 
Example 20
/**
 * We use OpenGL's texture coordinate generator to automatically
 * map the TexturePaint image to the geometry being rendered.  The
 * generator uses two separate plane equations that take the (x,y)
 * location (in device space) of the fragment being rendered to
 * calculate (u,v) texture coordinates for that fragment:
 *     u = Ax + By + Cz + Dw
 *     v = Ex + Fy + Gz + Hw
 *
 * Since we use a 2D orthographic projection, we can assume that z=0
 * and w=1 for any fragment.  So we need to calculate appropriate
 * values for the plane equation constants (A,B,D) and (E,F,H) such
 * that {u,v}=0 for the top-left of the TexturePaint's anchor
 * rectangle and {u,v}=1 for the bottom-right of the anchor rectangle.
 * We can easily make the texture image repeat for {u,v} values
 * outside the range [0,1] by specifying the GL_REPEAT texture wrap
 * mode.
 *
 * Calculating the plane equation constants is surprisingly simple.
 * We can think of it as an inverse matrix operation that takes
 * device space coordinates and transforms them into user space
 * coordinates that correspond to a location relative to the anchor
 * rectangle.  First, we translate and scale the current user space
 * transform by applying the anchor rectangle bounds.  We then take
 * the inverse of this affine transform.  The rows of the resulting
 * inverse matrix correlate nicely to the plane equation constants
 * we were seeking.
 */
private static void setTexturePaint(RenderQueue rq,
                                    SunGraphics2D sg2d,
                                    TexturePaint paint,
                                    boolean useMask)
{
    BufferedImage bi = paint.getImage();
    SurfaceData dstData = sg2d.surfaceData;
    SurfaceData srcData =
        dstData.getSourceSurfaceData(bi, SunGraphics2D.TRANSFORM_ISIDENT,
                                     CompositeType.SrcOver, null);
    boolean filter =
        (sg2d.interpolationType !=
         AffineTransformOp.TYPE_NEAREST_NEIGHBOR);

    // calculate plane equation constants
    AffineTransform at = (AffineTransform)sg2d.transform.clone();
    Rectangle2D anchor = paint.getAnchorRect();
    at.translate(anchor.getX(), anchor.getY());
    at.scale(anchor.getWidth(), anchor.getHeight());

    double xp0, xp1, xp3, yp0, yp1, yp3;
    try {
        at.invert();
        xp0 = at.getScaleX();
        xp1 = at.getShearX();
        xp3 = at.getTranslateX();
        yp0 = at.getShearY();
        yp1 = at.getScaleY();
        yp3 = at.getTranslateY();
    } catch (java.awt.geom.NoninvertibleTransformException e) {
        xp0 = xp1 = xp3 = yp0 = yp1 = yp3 = 0.0;
    }

    // assert rq.lock.isHeldByCurrentThread();
    rq.ensureCapacityAndAlignment(68, 12);
    RenderBuffer buf = rq.getBuffer();
    buf.putInt(SET_TEXTURE_PAINT);
    buf.putInt(useMask ? 1 : 0);
    buf.putInt(filter ? 1 : 0);
    buf.putLong(srcData.getNativeOps());
    buf.putDouble(xp0).putDouble(xp1).putDouble(xp3);
    buf.putDouble(yp0).putDouble(yp1).putDouble(yp3);
}