Skip to content

Commit 30cc651

Browse files
committed
Surface scan margin
1 parent d95eda5 commit 30cc651

File tree

3 files changed

+72
-37
lines changed

3 files changed

+72
-37
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/simulation/Simulation.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ data class Simulation(
8585
interact: InteractionConfig = TaskFlowModule.interact,
8686
rotation: RotationConfig = TaskFlowModule.rotation,
8787
inventory: InventoryConfig = TaskFlowModule.inventory,
88-
) = Simulation(this, interact, rotation, inventory)
88+
build: BuildConfig = TaskFlowModule.build,
89+
) = Simulation(this, interact, rotation, inventory, build)
8990
}
9091
}

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/VisibilityChecker.kt

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -136,49 +136,83 @@ object VisibilityChecker {
136136
scan: SurfaceScan = SurfaceScan.DEFAULT,
137137
check: (Direction, Vec3d) -> Unit,
138138
) {
139+
val margin = 0.1
140+
139141
excludedSides.forEach { side ->
140142
if (excludedSides.isNotEmpty() && side !in excludedSides) return@forEach
141-
val (minX, minY, minZ, maxX, maxY, maxZ) = box.contract(1.0E-6).bounds(side)
142-
val stepX = (maxX - minX) / resolution
143-
val stepY = (maxY - minY) / resolution
144-
val stepZ = (maxZ - minZ) / resolution
145-
146-
// Determine the bounds to scan based on the axis and mode
147-
val (startX, endX) = if (scan.axis == Direction.Axis.X && stepX != 0.0) {
148-
val centerX = (minX + maxX) / 2
149-
when (scan.mode) {
150-
ScanMode.GREATER_HALF -> centerX + 0.01 to maxX
151-
ScanMode.LESSER_HALF -> minX to centerX - 0.01
152-
ScanMode.FULL -> minX to maxX
143+
144+
val contractedBox = box.contract(1.0E-6)
145+
val (minX, minY, minZ, maxX, maxY, maxZ) = contractedBox.bounds(side)
146+
147+
// Determine start and end for each axis based on scan configuration
148+
val (startX, endX) = when (scan.axis) {
149+
Direction.Axis.X -> {
150+
val centerX = (minX + maxX) / 2
151+
when (scan.mode) {
152+
ScanMode.GREATER_HALF -> centerX + 0.01 to maxX
153+
ScanMode.LESSER_HALF -> minX to centerX - 0.01
154+
ScanMode.FULL -> minX to maxX
155+
}
153156
}
154-
} else minX to maxX
155-
156-
val (startY, endY) = if (scan.axis == Direction.Axis.Y && stepY != 0.0) {
157-
val centerY = (minY + maxY) / 2
158-
when (scan.mode) {
159-
ScanMode.GREATER_HALF -> centerY + 0.01 to maxY
160-
ScanMode.LESSER_HALF -> minY to centerY - 0.01
161-
ScanMode.FULL -> minY to maxY
157+
else -> minX to maxX
158+
}
159+
160+
val (startY, endY) = when (scan.axis) {
161+
Direction.Axis.Y -> {
162+
val centerY = (minY + maxY) / 2
163+
when (scan.mode) {
164+
ScanMode.GREATER_HALF -> centerY + 0.01 to maxY
165+
ScanMode.LESSER_HALF -> minY to centerY - 0.01
166+
ScanMode.FULL -> minY to maxY
167+
}
162168
}
163-
} else minY to maxY
164-
165-
val (startZ, endZ) = if (scan.axis == Direction.Axis.Z && stepZ != 0.0) {
166-
val centerZ = (minZ + maxZ) / 2
167-
when (scan.mode) {
168-
ScanMode.GREATER_HALF -> centerZ + 0.01 to maxZ
169-
ScanMode.LESSER_HALF -> minZ to centerZ - 0.01
170-
ScanMode.FULL -> minZ to maxZ
169+
else -> minY to maxY
170+
}
171+
172+
val (startZ, endZ) = when (scan.axis) {
173+
Direction.Axis.Z -> {
174+
val centerZ = (minZ + maxZ) / 2
175+
when (scan.mode) {
176+
ScanMode.GREATER_HALF -> centerZ + 0.01 to maxZ
177+
ScanMode.LESSER_HALF -> minZ to centerZ - 0.01
178+
ScanMode.FULL -> minZ to maxZ
179+
}
171180
}
172-
} else minZ to maxZ
181+
else -> minZ to maxZ
182+
}
173183

184+
// Apply margin and calculate adjusted step values
185+
val adjustedStartX = startX + margin
186+
val adjustedEndX = (endX - margin).coerceAtLeast(adjustedStartX)
187+
val stepX = if (resolution > 0) (adjustedEndX - adjustedStartX) / resolution else 0.0
188+
189+
val adjustedStartY = startY + margin
190+
val adjustedEndY = (endY - margin).coerceAtLeast(adjustedStartY)
191+
val stepY = if (resolution > 0) (adjustedEndY - adjustedStartY) / resolution else 0.0
192+
193+
val adjustedStartZ = startZ + margin
194+
val adjustedEndZ = (endZ - margin).coerceAtLeast(adjustedStartZ)
195+
val stepZ = if (resolution > 0) (adjustedEndZ - adjustedStartZ) / resolution else 0.0
196+
197+
// Iterate over the adjusted ranges
174198
(0..resolution).forEach outer@{ i ->
175-
val x = if (stepX != 0.0) startX + stepX * i else startX
176-
if (x > endX) return@outer
199+
val x = adjustedStartX + stepX * i
200+
if (x > adjustedEndX) return@outer
201+
177202
(0..resolution).forEach inner@{ j ->
178-
val y = if (stepY != 0.0) startY + stepY * j else startY
179-
if (y > endY) return@inner
180-
val z = if (stepZ != 0.0) startZ + stepZ * ((if (stepX != 0.0) j else i)) else startZ
181-
if (z > endZ) return@inner
203+
val y = adjustedStartY + stepY * j
204+
if (y > adjustedEndY) return@inner
205+
206+
// Determine z based on which axis is being scanned
207+
val z = when (scan.axis) {
208+
Direction.Axis.X, Direction.Axis.Y -> {
209+
adjustedStartZ + stepZ * (if (scan.axis == Direction.Axis.X) j else i)
210+
}
211+
else -> adjustedStartZ + stepZ * j
212+
}
213+
214+
if (z > adjustedEndZ) return@inner
215+
182216
check(side, Vec3d(x, y, z))
183217
}
184218
}

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class BuildTask @Ta5kBuilder constructor(
154154
override val pointSelection = interact.pointSelection
155155
override val swingHand = interact.swingHand
156156
}
157-
val goal = BuildGoal(blueprint.simulation(interaction, rotation, inventory))
157+
val goal = BuildGoal(blueprint.simulation(interaction, rotation, inventory, build))
158158
BaritoneUtils.setGoalAndPath(goal)
159159
}
160160

0 commit comments

Comments
 (0)