X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felementclass%2Fconnection%2FPath2DOutlineShape.java;fp=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Felementclass%2Fconnection%2FPath2DOutlineShape.java;h=a5befdb2e10c2dc218c435fa646359642e4a3574;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=e04de9cf1dc776eb8d043015db1d448b1a6f7305;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/connection/Path2DOutlineShape.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/connection/Path2DOutlineShape.java index e04de9cf1..a5befdb2e 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/connection/Path2DOutlineShape.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/elementclass/connection/Path2DOutlineShape.java @@ -1,119 +1,119 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.elementclass.connection; - -import java.awt.Rectangle; -import java.awt.Shape; -import java.awt.geom.AffineTransform; -import java.awt.geom.Path2D; -import java.awt.geom.PathIterator; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; - -public class Path2DOutlineShape implements Shape { - - Path2D path; - - public Path2DOutlineShape(Path2D path) { - this.path = path; - } - - @Override - public boolean contains(Point2D p) { - return false; - } - - @Override - public boolean contains(Rectangle2D r) { - return false; - } - - @Override - public boolean contains(double x, double y) { - return false; - } - - @Override - public boolean contains(double x, double y, double w, double h) { - return false; - } - - @Override - public Rectangle getBounds() { - return path.getBounds(); - } - - @Override - public Rectangle2D getBounds2D() { - return path.getBounds2D(); - } - - @Override - public PathIterator getPathIterator(AffineTransform at) { - return path.getPathIterator(at); - } - - @Override - public PathIterator getPathIterator(AffineTransform at, double flatness) { - return path.getPathIterator(at, flatness); - } - - @Override - public boolean intersects(Rectangle2D r) { - return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); - } - - @Override - public boolean intersects(double x, double y, double w, double h) { - PathIterator it = path.getPathIterator(new AffineTransform(), 1.0); - double[] coords = new double[2]; - double x0, y0, x1=0.0, y1=0.0; - while(!it.isDone()) { - x0 = x1; - y0 = y1; - switch(it.currentSegment(coords)) { - case PathIterator.SEG_MOVETO: - x1 = coords[0]; - y1 = coords[1]; - break; - - case PathIterator.SEG_LINETO: - x1 = coords[0]; - y1 = coords[1]; - - // Lines are approximated by their bounding boxes. This works for - // orthogonal paths. - if(x0 < x1) { - if(x > x1 || x+w < x0) - break; - } - else { - if(x > x0 || x+w < x1) - break; - } - - if(y0 < y1) { - if(y > y1 || y+h < y0) - break; - } - else { - if(y > y0 || y+h < y1) - break; - } - return true; - } - it.next(); - } - return false; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.elementclass.connection; + +import java.awt.Rectangle; +import java.awt.Shape; +import java.awt.geom.AffineTransform; +import java.awt.geom.Path2D; +import java.awt.geom.PathIterator; +import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; + +public class Path2DOutlineShape implements Shape { + + Path2D path; + + public Path2DOutlineShape(Path2D path) { + this.path = path; + } + + @Override + public boolean contains(Point2D p) { + return false; + } + + @Override + public boolean contains(Rectangle2D r) { + return false; + } + + @Override + public boolean contains(double x, double y) { + return false; + } + + @Override + public boolean contains(double x, double y, double w, double h) { + return false; + } + + @Override + public Rectangle getBounds() { + return path.getBounds(); + } + + @Override + public Rectangle2D getBounds2D() { + return path.getBounds2D(); + } + + @Override + public PathIterator getPathIterator(AffineTransform at) { + return path.getPathIterator(at); + } + + @Override + public PathIterator getPathIterator(AffineTransform at, double flatness) { + return path.getPathIterator(at, flatness); + } + + @Override + public boolean intersects(Rectangle2D r) { + return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight()); + } + + @Override + public boolean intersects(double x, double y, double w, double h) { + PathIterator it = path.getPathIterator(new AffineTransform(), 1.0); + double[] coords = new double[2]; + double x0, y0, x1=0.0, y1=0.0; + while(!it.isDone()) { + x0 = x1; + y0 = y1; + switch(it.currentSegment(coords)) { + case PathIterator.SEG_MOVETO: + x1 = coords[0]; + y1 = coords[1]; + break; + + case PathIterator.SEG_LINETO: + x1 = coords[0]; + y1 = coords[1]; + + // Lines are approximated by their bounding boxes. This works for + // orthogonal paths. + if(x0 < x1) { + if(x > x1 || x+w < x0) + break; + } + else { + if(x > x0 || x+w < x1) + break; + } + + if(y0 < y1) { + if(y > y1 || y+h < y0) + break; + } + else { + if(y > y0 || y+h < y1) + break; + } + return true; + } + it.next(); + } + return false; + } + +}