1 /*
2 * Copyright (c) 2002-2026 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.util.geometry;
16
17 import java.util.Objects;
18
19 /**
20 * Simple immutable 2D point.
21 *
22 * @author Ronald Brill
23 */
24 public class Point2D {
25 private final double myX_;
26 private final double myY_;
27
28 /**
29 * Creates a new point with the given coordinates.
30 *
31 * @param x the x coordinate
32 * @param y the y coordinate
33 */
34 public Point2D(final double x, final double y) {
35 myX_ = x;
36 myY_ = y;
37 }
38
39 /**
40 * Returns the x coordinate.
41 *
42 * @return the x coordinate
43 */
44 public double getX() {
45 return myX_;
46 }
47
48 /**
49 * Returns the y coordinate.
50 *
51 * @return the y coordinate
52 */
53 public double getY() {
54 return myY_;
55 }
56
57 @Override
58 public String toString() {
59 return "Point2D (" + myX_ + ", " + myY_ + ")";
60 }
61
62 @Override
63 public boolean equals(final Object o) {
64 if (o == null || getClass() != o.getClass()) {
65 return false;
66 }
67
68 final Point2D point2D = (Point2D) o;
69 return Double.compare(myX_, point2D.myX_) == 0 && Double.compare(myY_, point2D.myY_) == 0;
70 }
71
72 @Override
73 public int hashCode() {
74 return Objects.hash(myX_, myY_);
75 }
76 }