Skip to content

Commit

Permalink
Fix too many points being projected (#5026)
Browse files Browse the repository at this point in the history
  • Loading branch information
superblaubeere27 authored Dec 23, 2024
1 parent fc67684 commit 1cb4e87
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object CommandConfig : CommandFactory {
// Load the config in a separate thread to prevent the client from freezing
AutoConfig.startLoaderTask {
runCatching {
if(name.startsWith("http")) {
if (name.startsWith("http")) {
// Load the config from the specified URL
get(name).reader()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,25 @@ fun ClosedFloatingPointRange<Float>.proportionOfValue(value: Float): Float {
infix fun ClosedRange<Double>.step(step: Double): DoubleIterable {
require(start.isFinite())
require(endInclusive.isFinite())
require(step > 0.0)

return DoubleIterable {
if (step == 0.0) {
DoubleIterators.singleton(this.start)
} else {
object : DoubleIterator {
private var current = start
private var hasNextValue = current <= endInclusive

override fun hasNext(): Boolean = hasNextValue

override fun nextDouble(): Double {
if (!hasNextValue) throw NoSuchElementException()
val nextValue = current
current += step
if (current > endInclusive) hasNextValue = false
return nextValue
}

override fun remove() {
throw UnsupportedOperationException("This iterator is read-only")
}
object : DoubleIterator {
private var current = start
private var hasNextValue = current <= endInclusive

override fun hasNext(): Boolean = hasNextValue

override fun nextDouble(): Double {
if (!hasNextValue) throw NoSuchElementException()
val nextValue = current
current += step
if (current > endInclusive) hasNextValue = false
return nextValue
}

override fun remove() {
throw UnsupportedOperationException("This iterator is read-only")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package net.ccbluex.liquidbounce.utils.math.geometry
import net.ccbluex.liquidbounce.utils.kotlin.step
import net.ccbluex.liquidbounce.utils.math.plus
import net.ccbluex.liquidbounce.utils.math.times
import net.minecraft.util.math.MathHelper
import net.minecraft.util.math.Vec3d
import kotlin.jvm.optionals.getOrNull
import kotlin.math.sqrt

class PlaneSection(
Expand All @@ -14,10 +14,7 @@ class PlaneSection(
) {

inline fun castPointsOnUniformly(maxPoints: Int, consumer: (Vec3d) -> Unit) {
val nPoints = maxPoints
val aspectRatio = this.dirVec2.length() / this.dirVec1.length()
val dz = sqrt(1 / (aspectRatio * nPoints))
val dy = sqrt(aspectRatio / nPoints)
val (dz, dy) = getFairStepSide(maxPoints)

for (y in 0.0..1.0 step dy) {
for (z in 0.0..1.0 step dz) {
Expand All @@ -28,4 +25,23 @@ class PlaneSection(
}
}

fun getFairStepSide(nPoints: Int): Pair<Double, Double> {
val aspectRatio = this.dirVec2.length() / this.dirVec1.length()

val vec1zero = MathHelper.approximatelyEquals(this.dirVec1.length(), 0.0)
val vec2zero = MathHelper.approximatelyEquals(this.dirVec2.length(), 0.0)

return when {
!vec1zero && !vec2zero -> {
val dz = sqrt(1 / (aspectRatio * nPoints))
val dy = sqrt(aspectRatio / nPoints)

dz to dy
}
vec1zero && vec2zero -> 1.0 to 1.0
vec1zero -> 1.0 to (2.0 / nPoints)
else -> 2.0 / nPoints to 1.0
}
}

}

0 comments on commit 1cb4e87

Please sign in to comment.