X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2FAffineTransformFunctions.java;fp=bundles%2Forg.simantics.scenegraph%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Fg2d%2FAffineTransformFunctions.java;h=40e58e94911428eb66ff7216d3ff72086146223d;hb=2b0fe692f116091f8d65da664174c92591a077b8;hp=0000000000000000000000000000000000000000;hpb=043ed4538f5bdc16d299bc40c2dd8285a3120f9b;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/AffineTransformFunctions.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/AffineTransformFunctions.java new file mode 100644 index 000000000..40e58e949 --- /dev/null +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/AffineTransformFunctions.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2017 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.scenegraph.g2d; + +import java.awt.geom.AffineTransform; +import java.awt.geom.NoninvertibleTransformException; +import java.awt.geom.Point2D; + +import org.simantics.scl.runtime.tuple.Tuple2; + +/** + * @author Antti Villberg + * @since 1.29.0 + */ +public class AffineTransformFunctions { + + public static Tuple2 transform(AffineTransform transform, Tuple2 point) { + Point2D result = new Point2D.Double((Double) point.c0, (Double) point.c1); + transform.transform(result, result); + return new Tuple2(result.getX(), result.getY()); + } + + public static Tuple2 inverseTransform(AffineTransform transform, Tuple2 point) throws NoninvertibleTransformException { + Point2D result = new Point2D.Double((Double)point.c0, (Double)point.c1); + transform.inverseTransform(result, result); + return new Tuple2(result.getX(), result.getY()); + } + +}