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