changes: generated annotated code but it still causes type errors + re-formatting...
[IRC.git] / Robust / src / Benchmarks / SSJava / EyeTrackingInfer / ScanArea.java
1 /*
2  * Copyright 2009 (c) Florian Frankenberger (darkblue.de)
3  * 
4  * This file is part of LEA.
5  * 
6  * LEA is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU Lesser General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option) any
9  * later version.
10  * 
11  * LEA is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13  * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  * 
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with LEA. If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 /**
21  * 
22  * @author Florian
23  */
24
25 public class ScanArea {
26
27   private Point fromPoint;
28
29   private Point toPoint;
30
31   private float size;
32
33   /**
34    * Imagine you want to classify an image with 100px x 100px what would be the scanarea in this
35    * kind of image. That size gets automatically scalled to fit bigger images
36    * 
37    * @param fromPoint
38    * @param toPoint
39    */
40   public ScanArea(Point fromPoint, Point toPoint) {
41     this.fromPoint = fromPoint;
42     this.toPoint = toPoint;
43
44     this.size = (this.toPoint.x - this.fromPoint.x) * (this.toPoint.y - this.fromPoint.y);
45   }
46
47   public ScanArea(Point fromPoint, Point toPoint, float size) {
48     this.fromPoint = fromPoint;
49     this.toPoint = toPoint;
50     this.size = size;
51   }
52
53   public ScanArea(int fromX, int fromY, int width, int height) {
54     this(new Point(fromX, fromY), new Point(fromX + width, fromY + height));
55   }
56
57   public int getFromX(float scaleFactor) {
58     return (int) (this.fromPoint.x * scaleFactor);
59   }
60
61   public int getFromY(float scaleFactor) {
62     return (int) (this.fromPoint.y * scaleFactor);
63   }
64
65   public int getToX(float scaleFactor) {
66     return (int) (this.toPoint.x * scaleFactor);
67   }
68
69   public int getToY(float scaleFactor) {
70     return (int) (this.toPoint.y * scaleFactor);
71   }
72
73   public int getSize(float scaleFactor) {
74     return (int) (this.size * Math.pow(scaleFactor, 2));
75   }
76
77   @Override
78   public boolean equals(Object o) {
79     ScanArea other = (ScanArea) o;
80
81     return pointsWithin(other.fromPoint.x, other.toPoint.x, this.fromPoint.x, this.toPoint.x)
82         && pointsWithin(other.fromPoint.y, other.toPoint.y, this.fromPoint.y, this.toPoint.y);
83   }
84
85   private static boolean pointsWithin(int pointA1, int pointA2, int pointB1, int pointB2) {
86     boolean within = false;
87     within = within || (pointB1 >= pointA1 && pointB1 <= pointA2);
88     within = within || (pointB2 >= pointA1 && pointB2 <= pointA2);
89     within = within || (pointA1 >= pointB1 && pointA1 <= pointB2);
90     within = within || (pointA2 >= pointB1 && pointA2 <= pointB2);
91
92     return within;
93   }
94
95   // private boolean checkPoints(ScanArea a, ScanArea b) {
96   // Point[] pointsToCheck = new Point[] {
97   // a.fromPoint, a.toPoint,
98   // new Point (a.fromPoint.x, a.toPoint.y),
99   // new Point (a.toPoint.x, a.fromPoint.y)
100   // };
101   // for (Point point: pointsToCheck) {
102   // if (point.x >= b.fromPoint.x && point.x <= b.toPoint.x &&
103   // point.y >= b.fromPoint.y && point.y <= b.toPoint.y) return true;
104   // }
105   //
106   // return false;
107   // }
108
109   public String toString() {
110     String str = "";
111     str += "fromPoint=(" + fromPoint.x + "," + fromPoint.y + ")";
112     str += "toPoint=(" + toPoint.x + "," + toPoint.y + ")";
113     str += "size=" + size;
114     return str;
115   }
116 }