View Javadoc
1   /*******************************************************************************
2    * Copyright (c) 2015 Voyager Search and MITRE
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Apache License, Version 2.0 which
5    * accompanies this distribution and is available at
6    *    http://www.apache.org/licenses/LICENSE-2.0.txt
7    ******************************************************************************/
8   
9   package org.locationtech.spatial4j.distance;
10  
11  import org.locationtech.spatial4j.context.SpatialContext;
12  import org.locationtech.spatial4j.shape.Circle;
13  import org.locationtech.spatial4j.shape.Point;
14  import org.locationtech.spatial4j.shape.Rectangle;
15  
16  /**
17   * Performs calculations relating to distance, such as the distance between a pair of points.  A
18   * calculator might be based on Euclidean space, or a spherical model, or theoretically something
19   * else like an ellipsoid.
20   */
21  public interface DistanceCalculator {
22  
23    /** The distance between <code>from</code> and <code>to</code>. */
24    public double distance(Point from, Point to);
25  
26    /** The distance between <code>from</code> and <code>Point(toX,toY)</code>. */
27    public double distance(Point from, double toX, double toY);
28  
29    /** Returns true if the distance between from and to is &lt;= distance. */
30    public boolean within(Point from, double toX, double toY, double distance);
31  
32    /**
33     * Calculates where a destination point is given an origin (<code>from</code>)
34     * distance, and bearing (given in degrees -- 0-360).  If reuse is given, then
35     * this method may reset() it and return it.
36     */
37    public Point pointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse);
38  
39    /**
40     * Calculates the bounding box of a circle, as specified by its center point
41     * and distance.
42     */
43    public Rectangle calcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse);
44  
45    /**
46     * The <code>Y</code> coordinate of the horizontal axis of a circle that has maximum width. On a
47     * 2D plane, this result is always <code>from.getY()</code> but, perhaps surprisingly, on a sphere
48     * it is going to be slightly different.
49     */
50    public double calcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx);
51  
52    public double area(Rectangle rect);
53  
54    public double area(Circle circle);
55  
56  }