2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.lucene.spatial.geometry.shape;
24 * <p><font color="red"><b>NOTE:</b> This API is still in
25 * flux and might change in incompatible ways in the next
28 public class Rectangle implements Geometry2D {
29 private Point2D ptMin, ptMax;
32 ptMin=new Point2D(-1, 1);
33 ptMax=new Point2D(1, 1);
36 public Rectangle(Point2D ptMin, Point2D ptMax) {
37 this.ptMin=new Point2D(ptMin);
38 this.ptMax=new Point2D(ptMax);
41 public Rectangle(double x1, double y1, double x2, double y2) {
46 public String toString() {
47 return "[" + ptMin + "," + ptMax + "]";
50 private void set(double x1, double y1, double x2, double y2) {
51 this.ptMin=new Point2D(Math.min(x1, x2), Math.min(y1, y2));
52 this.ptMax=new Point2D(Math.max(x1, x2), Math.max(y1, y2));
55 public double area() {
56 return (ptMax.getX() - ptMin.getX()) * (ptMax.getY() - ptMin.getY());
59 public Point2D centroid() {
60 return new Point2D( (ptMin.getX() + ptMax.getX()) / 2,
61 (ptMin.getY() + ptMax.getY()) / 2);
64 public boolean contains(Point2D p) {
65 return p.getX() >= ptMin.getX() &&
66 p.getX() <= ptMax.getX() &&
67 p.getY() >= ptMin.getY() &&
68 p.getY() <= ptMax.getY();
71 public void translate(Vector2D v) {
84 public IntersectCase intersect(Rectangle r) {
85 throw new UnsupportedOperationException();
89 public Point2D getMaxPoint() {
93 public Point2D getMinPoint() {
98 public int hashCode() {
101 result = prime * result + ((ptMax == null) ? 0 : ptMax.hashCode());
102 result = prime * result + ((ptMin == null) ? 0 : ptMin.hashCode());
107 public boolean equals(Object obj) {
112 if (getClass() != obj.getClass())
114 Rectangle other = (Rectangle) obj;
116 if (other.ptMax != null)
118 } else if (!ptMax.equals(other.ptMax))
121 if (other.ptMin != null)
123 } else if (!ptMin.equals(other.ptMin))