1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.g2d.elementclass.connection;
\r
14 import java.awt.Rectangle;
\r
15 import java.awt.Shape;
\r
16 import java.awt.geom.AffineTransform;
\r
17 import java.awt.geom.Path2D;
\r
18 import java.awt.geom.PathIterator;
\r
19 import java.awt.geom.Point2D;
\r
20 import java.awt.geom.Rectangle2D;
\r
22 public class Path2DOutlineShape implements Shape {
\r
26 public Path2DOutlineShape(Path2D path) {
\r
31 public boolean contains(Point2D p) {
\r
36 public boolean contains(Rectangle2D r) {
\r
41 public boolean contains(double x, double y) {
\r
46 public boolean contains(double x, double y, double w, double h) {
\r
51 public Rectangle getBounds() {
\r
52 return path.getBounds();
\r
56 public Rectangle2D getBounds2D() {
\r
57 return path.getBounds2D();
\r
61 public PathIterator getPathIterator(AffineTransform at) {
\r
62 return path.getPathIterator(at);
\r
66 public PathIterator getPathIterator(AffineTransform at, double flatness) {
\r
67 return path.getPathIterator(at, flatness);
\r
71 public boolean intersects(Rectangle2D r) {
\r
72 return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
\r
76 public boolean intersects(double x, double y, double w, double h) {
\r
77 PathIterator it = path.getPathIterator(new AffineTransform(), 1.0);
\r
78 double[] coords = new double[2];
\r
79 double x0, y0, x1=0.0, y1=0.0;
\r
80 while(!it.isDone()) {
\r
83 switch(it.currentSegment(coords)) {
\r
84 case PathIterator.SEG_MOVETO:
\r
89 case PathIterator.SEG_LINETO:
\r
93 // Lines are approximated by their bounding boxes. This works for
\r
94 // orthogonal paths.
\r
96 if(x > x1 || x+w < x0)
\r
100 if(x > x0 || x+w < x1)
\r
105 if(y > y1 || y+h < y0)
\r
109 if(y > y0 || y+h < y1)
\r