Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased/Snapshot]

### Changed
- `GeoUtils.calcOrderedCoordinateDistances()` now returns a manually sorted `List` instead of a `SortedSet` [#449](https://github.com/ie3-institute/PowerSystemUtils/issues/449)


### Fixed
- Bug where `GeoUtils.calcOrderedCoordinateDistances()` didn't return all `CoordinateDistance` [#449](https://github.com/ie3-institute/PowerSystemUtils/issues/449)


## [2.2.0]

### Changed
Expand Down
23 changes: 4 additions & 19 deletions src/main/java/edu/ie3/util/geo/GeoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import edu.ie3.util.exceptions.GeoException;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.measure.Quantity;
import javax.measure.quantity.Angle;
Expand Down Expand Up @@ -116,28 +115,14 @@ private static Coordinate buildSafeCoord(Coordinate coord) {
*
* @param baseCoordinate the base point
* @param coordinates the points to calculate the distance from the base point for
* @return a sorted set of distances between the base and other coordinates
* @deprecated Use {@link #calcOrderedCoordinateDistances(Point, Collection)} instead.
* @return a sorted list of distances between the base and other coordinates
*/
@Deprecated(since = "2.0", forRemoval = true)
public static SortedSet<CoordinateDistance> getCoordinateDistances(
Point baseCoordinate, Collection<Point> coordinates) {
return calcOrderedCoordinateDistances(baseCoordinate, coordinates);
}

/**
* Calculates and sorts the distances between a base coordinate and other given coordinates using
* {@link #calcHaversine(double, double, double, double)}
*
* @param baseCoordinate the base point
* @param coordinates the points to calculate the distance from the base point for
* @return a sorted set of distances between the base and other coordinates
*/
public static SortedSet<CoordinateDistance> calcOrderedCoordinateDistances(
public static List<CoordinateDistance> calcOrderedCoordinateDistances(
Point baseCoordinate, Collection<Point> coordinates) {
return coordinates.stream()
.map(coordinate -> new CoordinateDistance(baseCoordinate, coordinate))
.collect(Collectors.toCollection(TreeSet::new));
.sorted(Comparator.comparing(CoordinateDistance::getDistance))
.toList();
}

/**
Expand Down
19 changes: 17 additions & 2 deletions src/test/groovy/edu/ie3/util/geo/GeoUtilsTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,29 @@ class GeoUtilsTest extends Specification {
GeoUtils.buildPoint(49d, 7.1d)
]
def coordinateDistances = [
new CoordinateDistance(basePoint, points[3]),
new CoordinateDistance(basePoint, points[0]),
new CoordinateDistance(basePoint, points[1]),
new CoordinateDistance(basePoint, points[3]),
new CoordinateDistance(basePoint, points[2])
]

expect:
GeoUtils.calcOrderedCoordinateDistances(basePoint, points) == new TreeSet(coordinateDistances)
GeoUtils.calcOrderedCoordinateDistances(basePoint, points) == coordinateDistances
}

def "GeoUtils should return all CoordinateDistances correctly"() {
given:
def basePoint = GeoUtils.buildPoint(50.5, 7d)
def points = [
GeoUtils.buildPoint(50d, 7d),
GeoUtils.buildPoint(51d, 7d)
]

when:
def actual = GeoUtils.calcOrderedCoordinateDistances(basePoint, points)

then:
actual.size() == 2
}

def "GeoUtils should calculate haversine distance between two points correctly"() {
Expand Down