View Javadoc
1   /*
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
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
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.
16   */
17  package org.apache.commons.geometry.core.partitioning.test;
18  
19  import org.apache.commons.geometry.core.Point;
20  
21  /** Class representing a point in two dimensional Euclidean space. This
22   * class should only be used for testing purposes.
23   */
24  public final class TestPoint2D implements Point<TestPoint2D> {
25  
26      /** Instance representing the coordinates {@code (0, 0)} */
27      public static final TestPoint2D ZERO = new TestPoint2D(0, 0);
28  
29      /** Instance representing the coordinates {@code (1, 0)} */
30      public static final TestPoint2D PLUS_X = new TestPoint2D(1, 0);
31  
32      /** Instance representing the coordinates {@code (0, 1)} */
33      public static final TestPoint2D PLUS_Y = new TestPoint2D(0, 1);
34  
35      /** X coordinate */
36      private final double x;
37  
38      /** Y coordinate */
39      private final double y;
40  
41      /** Simple constructor.
42       * @param x x coordinate
43       * @param y y coordinate
44       */
45      public TestPoint2D(final double x, final double y) {
46          this.x = x;
47          this.y = y;
48      }
49  
50      /** Get the x coordinate value.
51       * @return x coordinate value
52       */
53      public double getX() {
54          return x;
55      }
56  
57      /** Get the y coordinate value.
58       * @return y coordinate value
59       */
60      public double getY() {
61          return y;
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public int getDimension() {
67          return 2;
68      }
69  
70      /** {@inheritDoc} */
71      @Override
72      public boolean isNaN() {
73          return Double.isNaN(x) || Double.isNaN(y);
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public boolean isInfinite() {
79          return Double.isInfinite(x) || Double.isInfinite(y);
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public boolean isFinite() {
85          return Double.isFinite(x) && Double.isFinite(y);
86      }
87  
88      /** {@inheritDoc} */
89      @Override
90      public double distance(final TestPoint2D p) {
91          final double dx = x - p.x;
92          final double dy = y - p.y;
93  
94          return Math.sqrt((dx * dx) + (dy * dy));
95      }
96  
97      /** {@inheritDoc} */
98      @Override
99      public String toString() {
100         return "(" + x + ", " + y + ")";
101     }
102 }