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;
18
19 /** Interface representing a point in a mathematical space.
20 *
21 * <p>Implementations of this interface are sufficient to define a
22 * space since they define both the structure of the points making up
23 * the space and the operations permitted on them. The only mathematical
24 * requirement at this level is that the represented space have a defined
25 * distance metric, meaning an operation that can compute the distance
26 * between two points (ie, the space must be a metric space).
27 * </p>
28 *
29 * <p>This interface uses self-referencing generic parameters to ensure
30 * that implementations are only used with instances of their own type.
31 * This removes the need for casting inside of methods in order to access
32 * implementation-specific data, such as coordinate values.
33 * </p>
34 *
35 * @see <a href="https://en.wikipedia.org/wiki/Metric_space">Metric space</a>
36 *
37 * @param <P> Point implementation type
38 */
39 public interface Point<P extends Point<P>> extends Spatial {
40
41 /** Compute the distance between this point and another point.
42 * @param p second point
43 * @return the distance between this point and p
44 */
45 double distance(P p);
46 }