1 /*
2 * Copyright (c) 2002-2025 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 /**
18 * Simple 2D shape circle.
19 *
20 * @author Ronald Brill
21 */
22 public class Circle2D implements Shape2D {
23 private final double centerX_;
24 private final double centerY_;
25 private final double radius_;
26
27 /**
28 * Ctor.
29 * @param centerX x value of the second center
30 * @param centerY y value of the second center
31 * @param radius the radius
32 */
33 public Circle2D(final double centerX, final double centerY, final double radius) {
34 centerX_ = centerX;
35 centerY_ = centerY;
36 radius_ = radius;
37 }
38
39 /**
40 * {@inheritDoc}
41 */
42 @Override
43 public boolean contains(final double x, final double y) {
44 final double offsetX = centerX_ - x;
45 final double offsetY = centerY_ - y;
46
47 return offsetX * offsetX + offsetY * offsetY <= radius_ * radius_;
48 }
49
50 /**
51 * {@inheritDoc}
52 */
53 @Override
54 public boolean isEmpty() {
55 return radius_ < EPSILON;
56 }
57
58 @Override
59 public String toString() {
60 return "Circle2D [ (" + centerX_ + ", " + centerY_ + ") radius = " + radius_ + "]";
61 }
62 }