diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/math/Line2d.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/math/Line2d.kt index 9ac2251a..bef12a02 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/math/Line2d.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/math/Line2d.kt @@ -163,7 +163,7 @@ data class Line2d(val p0: Vector2d, val p1: Vector2d) { if (!infinite) proj = proj.coerceIn(0.0, 1.0) - return (Vector2d(other) - p0 + difference * proj).length + return (Vector2d(other) - (p0 + difference * proj)).length } fun distanceTo(other: Vector2d, infinite: Boolean = false): Double { @@ -172,7 +172,7 @@ data class Line2d(val p0: Vector2d, val p1: Vector2d) { if (!infinite) proj = proj.coerceIn(0.0, 1.0) - return (other - p0 + difference * proj).length + return (other - (p0 + difference * proj)).length } class Adapter(gson: Gson) : TypeAdapter() { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt index 3d607c18..bc412467 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt @@ -240,7 +240,7 @@ data class WorldGeometry(val size: Vector2i, val loopX: Boolean = true, val loop fun nearestTo(source: IStruct2d, target: IStruct2d) = Vector2d(x.nearestTo(source.component1(), target.component1()), y.nearestTo(source.component2(), target.component2())) fun polyDistance(poly: Poly, point: IStruct2d): Double { - return poly.distance(nearestTo(poly.centre, point)) + return split(poly).minOf { it.distance(nearestTo(it.centre, point)) } } val splitLines: ImmutableList>> by lazy {