Skip to content

Commit

Permalink
Add euclidean distance function to Location. (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikmaeckel authored Sep 23, 2024
1 parent 7681d3f commit f2764dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- Add `PreEvaluationHooks` before evaluation of `TSCs` and `Segments` in `TSCEvaluation`.
- Add pre-defined `MinNodesInTSCHook` and `MinTicksPerSegmentHook`.
- Add `identifier` field to `TSC`.
- Add `euclideanDistance` function to `Location`.
- Add `vehicleType` field to `Vehicle`.

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@

package tools.aqua.stars.data.av.dataclasses

import kotlin.math.pow
import kotlin.math.sqrt

/**
* Data class for 3D locations.
*
* @property x The x ordinate.
* @property y The y ordinate.
* @property z The z ordinate.
*/
data class Location(val x: Double, val y: Double, val z: Double)
data class Location(val x: Double, val y: Double, val z: Double) {
companion object {
/**
* Calculates the Euclidean distance between two locations, i.e., the square root of the sum of
* the squared ordinates.
*/
fun euclideanDistance(loc1: Location, loc2: Location): Double =
sqrt((loc1.x - loc2.x).pow(2) + (loc1.y - loc2.y).pow(2) + (loc1.z - loc2.z).pow(2))
}
}

0 comments on commit f2764dc

Please sign in to comment.