All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.batik.dom.svg.SVGOMPoint Maven / Gradle / Ivy

There is a newer version: 1.18
Show newest version
/*

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package org.apache.batik.dom.svg;

import org.w3c.dom.DOMException;
import org.w3c.dom.svg.SVGMatrix;
import org.w3c.dom.svg.SVGPoint;

/**
 * An implementation of {@link SVGPoint} that is not associated with any
 * attribute.
 *
 * @author Stephane Hillion
 * @version $Id: SVGOMPoint.java 475477 2006-11-15 22:44:28Z cam $
 */
public class SVGOMPoint implements SVGPoint {

    /**
     * The x coordinate.
     */
    protected float x;
    
    /**
     * The y coordinate.
     */
    protected float y;

    /**
     * Creates a new SVGOMPoint with coordinates set to 0.
     */
    public SVGOMPoint() {
    }

    /**
     * Creates a new SVGOMPoint with coordinates set to the specified values.
     */
    public SVGOMPoint(float x, float y) {
        this.x = x;
        this.y = y;
    }

    /**
     * DOM: Implements {@link SVGPoint#getX()}.
     */
    public float getX() {
        return x;
    }

    /**
     * DOM: Implements {@link SVGPoint#setX(float)}.
     */
    public void setX(float x) throws DOMException {
        this.x = x;
    }

    /**
     * DOM: Implements {@link SVGPoint#getY()}.
     */
    public float getY() {
        return y;
    }

    /**
     * DOM: Implements {@link SVGPoint#setY(float)}.
     */
    public void setY(float y) throws DOMException {
        this.y = y;
    }

    /**
     * DOM: Implements {@link SVGPoint#matrixTransform(SVGMatrix)}.
     */
    public SVGPoint matrixTransform(SVGMatrix matrix) {
        return matrixTransform(this, matrix);
    }

    /**
     * Transforms an {@link SVGPoint} by an {@link SVGMatrix} and returns
     * the new point.
     */
    public static SVGPoint matrixTransform(SVGPoint point, SVGMatrix matrix) {
        float newX = matrix.getA() * point.getX() + matrix.getC() * point.getY()
            + matrix.getE();
        float newY = matrix.getB() * point.getX() + matrix.getD() * point.getY()
            + matrix.getF();
        return new SVGOMPoint(newX, newY);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy