Skip to content

Commit 3e8d215

Browse files
committed
Reduce code clones
1 parent 3a309f6 commit 3e8d215

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ object HudGuiLayout : Loadable {
5656
val kindY: Guide.Kind?
5757
)
5858

59-
// Precomputed Float PI values to avoid repeated conversions
6059
private const val PI_F = PI.toFloat()
6160
private const val HALF_PI_F = (0.5f * PI).toFloat()
6261
private const val THREE_HALVES_PI_F = (1.5f * PI).toFloat()
@@ -106,7 +105,6 @@ object HudGuiLayout : Loadable {
106105
)
107106
}
108107
with(hud) { buildLayout() }
109-
// Rounded-corner only outline; pull parameters from settings
110108
if (ClickGui.isEnabled) {
111109
drawHudOutline(
112110
draw = foregroundDrawList,

src/main/kotlin/com/lambda/gui/snap/SnapManager.kt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,26 @@ object SnapManager {
8787
val bestScreenX = Best(); val bestScreenY = Best()
8888
val bestGridX = Best(); val bestGridY = Best()
8989

90-
fun considerX(g: Guide, point: Float, out: Best) {
90+
fun consider(g: Guide, point: Float, out: Best) {
9191
val dist = abs(point - g.pos)
9292
if (dist <= max(1f, thresholdFor(g.kind))) {
9393
val sc = score(dist, g.strength)
9494
if (sc < out.s) { out.s = sc; out.d = g.pos - point; out.p = g.pos; out.k = g.kind }
9595
}
9696
}
97-
fun considerY(g: Guide, point: Float, out: Best) {
98-
val dist = abs(point - g.pos)
99-
if (dist <= max(1f, thresholdFor(g.kind))) {
100-
val sc = score(dist, g.strength)
101-
if (sc < out.s) { out.s = sc; out.d = g.pos - point; out.p = g.pos; out.k = g.kind }
97+
98+
fun processAxis(
99+
g: Guide,
100+
points: FloatArray,
101+
tier: String,
102+
elem: Best,
103+
screen: Best,
104+
grid: Best
105+
) {
106+
when (tier) {
107+
"elem" -> for (p in points) consider(g, p, elem)
108+
"screen" -> for (p in points) consider(g, p, screen)
109+
"grid" -> for (p in points) consider(g, p, grid)
102110
}
103111
}
104112

@@ -113,20 +121,12 @@ object SnapManager {
113121

114122
when (g.orientation) {
115123
Guide.Orientation.Vertical -> {
116-
val pts = floatArrayOf(proposed.left, proposed.cx, proposed.right)
117-
when (tier) {
118-
"elem" -> for (p in pts) considerX(g, p, bestElemX)
119-
"screen" -> for (p in pts) considerX(g, p, bestScreenX)
120-
"grid" -> for (p in pts) considerX(g, p, bestGridX)
121-
}
124+
val points = floatArrayOf(proposed.left, proposed.cx, proposed.right)
125+
processAxis(g, points, tier, bestElemX, bestScreenX, bestGridX)
122126
}
123127
Guide.Orientation.Horizontal -> {
124-
val pts = floatArrayOf(proposed.top, proposed.cy, proposed.bottom)
125-
when (tier) {
126-
"elem" -> for (p in pts) considerY(g, p, bestElemY)
127-
"screen" -> for (p in pts) considerY(g, p, bestScreenY)
128-
"grid" -> for (p in pts) considerY(g, p, bestGridY)
129-
}
128+
val points = floatArrayOf(proposed.top, proposed.cy, proposed.bottom)
129+
processAxis(g, points, tier, bestElemY, bestScreenY, bestGridY)
130130
}
131131
}
132132
}

0 commit comments

Comments
 (0)