Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make roundToRealPixels round to 0 pixels on very small inputs #130

Merged
Merged
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
5 changes: 3 additions & 2 deletions src/main/kotlin/gg/essential/elementa/utils/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import gg.essential.universal.UResolution
import gg.essential.universal.shader.BlendState
import gg.essential.universal.shader.UShader
import java.awt.Color
import kotlin.math.abs
import kotlin.math.round
import kotlin.math.sign

Expand All @@ -14,11 +15,11 @@ fun Double.guiHint(roundDown: Boolean) = UIComponent.guiHint(this, roundDown)

fun Float.roundToRealPixels(): Float {
val factor = UResolution.scaleFactor.toFloat()
return round(this * factor).let { if (it == 0f && this != 0f) sign(this) else it } / factor
return round(this * factor).let { if (it == 0f && abs(this) > 0.001f) sign(this) else it } / factor
}
fun Double.roundToRealPixels(): Double {
val factor = UResolution.scaleFactor
return round(this * factor).let { if (it == 0.0 && this != 0.0) sign(this) else it } / factor
return round(this * factor).let { if (it == 0.0 && abs(this) > 0.001) sign(this) else it } / factor
}

fun Color.withAlpha(alpha: Int) = Color(this.red, this.green, this.blue, alpha)
Expand Down