View Javadoc
1   /*
2    * Copyright (C) 2017 Alberto Irurueta Carro (alberto@irurueta.com)
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    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.irurueta.geometry;
18  
19  import java.io.Serializable;
20  
21  /**
22   * Interface defining a point (either in 2D or 3D, or any other further dimensions that might be defined).
23   */
24  public interface Point<P extends Point<P>> extends Serializable {
25  
26      /**
27       * Returns number of dimensions of this point implementation.
28       *
29       * @return number of dimensions.
30       */
31      int getDimensions();
32  
33      /**
34       * Gets value of inhomogeneous coordinate for provided dimension.
35       *
36       * @param dim dimension to retrieve coordinate for (i.e. 0 means x, 1 means y, 2 means z, etc).
37       * @return value of inhomogeneous coordinate.
38       * @throws IllegalArgumentException if provided dimension value is negative or exceeds number of dimensions.
39       */
40      double getInhomogeneousCoordinate(final int dim);
41  
42      /**
43       * Sets value of inhomogeneous coordinate for provided dimension.
44       *
45       * @param dim   dimension to set coordinate for (i.e. 0 means x, 1 means y, 2 means z, etc.).
46       * @param value value to be set.
47       * @throws IllegalArgumentException if provided dimension value is negative or exceeds number of dimensions.
48       */
49      void setInhomogeneousCoordinate(final int dim, final double value);
50  
51      /**
52       * Returns Euclidean distance between this point and provided point.
53       *
54       * @param point point to compare.
55       * @return Euclidean distance between this point and provided point.
56       */
57      double distanceTo(final P point);
58  
59      /**
60       * Returns squared Euclidean distance between this point and provided point.
61       *
62       * @param point point to compare.
63       * @return Euclidean distance between this point and provided point.
64       */
65      double sqrDistanceTo(final P point);
66  }