1
2 package hep.wired.heprep.util;
3
4 import java.awt.geom.*;
5 import java.io.*;
6
7 import org.freehep.graphicsio.CubicToLinePathConstructor;
8
9 /***
10 * Constructs a path while keeping track if the path crosses or is within a given rectangle.
11 *
12 * @author Mark Donszelmann
13 * @version $Id: InsideRectanglePathConstructor.java 289 2004-06-22 22:59:36Z duns $
14 */
15 public class InsideRectanglePathConstructor extends CubicToLinePathConstructor {
16
17 private Rectangle2D rectangle;
18 private transient Line2D line = new Line2D.Double();
19
20 /***
21 * Creates a path constructor with given rectangle
22 */
23 public InsideRectanglePathConstructor(Rectangle2D rectangle) {
24 this.rectangle = rectangle;
25 }
26
27 /***
28 * Adds a line to the path, called from addPath.
29 */
30 public void line(double x, double y) throws IOException {
31 line.setLine(currentX, currentY, x, y);
32 if (rectangle.intersectsLine(line)) {
33 lineFound(new Line2D.Double(currentX, currentY, x, y));
34 }
35 super.line(x, y);
36 }
37
38 /***
39 * Closes the current path, called from addPath.
40 */
41 public void closePath(double x0, double y0) throws IOException {
42 line(x0, y0);
43 super.closePath(x0, y0);
44 }
45
46 /***
47 * Called when a line is found that is inside the rectangle or crosses it, so that the subclass
48 * can use this to track some other information, such as keeping a reference
49 * of the object(s).
50 */
51 protected void lineFound(Line2D line) {
52 }
53 }