From 19038dea7d3c086b8163a6c6041adb07d9f6f1f3 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 6 May 2024 14:18:38 +0700 Subject: [PATCH] Fix Line2d.distanceTo --- src/main/kotlin/ru/dbotthepony/kstarbound/math/Line2d.kt | 4 ++-- .../kotlin/ru/dbotthepony/kstarbound/world/WorldGeometry.kt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 {