Skip to content

Commit 5531a8c

Browse files
authored
Merge pull request #174 from jgphilpott/copilot/fix-failing-tests-after-update
Fix failing tests after three-mesh-bvh upgrade to ^0.9.9
2 parents 2cc51d7 + 934bd30 commit 5531a8c

File tree

2 files changed

+69
-173
lines changed

2 files changed

+69
-173
lines changed

src/slicer/slice.test.coffee

Lines changed: 31 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -715,58 +715,48 @@ describe 'Slicing', ->
715715

716716
describe 'Wall Print Order with Holes', ->
717717

718-
test 'should print outer boundary walls before hole walls', ->
719-
720-
# This test uses three-bvh-csg to create a sheet with holes.
721-
# Import CSG dependencies.
722-
{ Brush, Evaluator, SUBTRACTION } = require('three-bvh-csg')
723-
724-
# Suppress MeshBVH deprecation warnings from three-bvh-csg.
725-
originalWarn = console.warn
726-
console.warn = jest.fn()
718+
SHEET_SIZE = 50
719+
THICKNESS = 5
720+
GRID_SIZE = 2
721+
HOLE_RADIUS = 3
727722

728-
# Create a sheet with holes using CSG operations.
729-
sheetGeometry = new THREE.BoxGeometry(50, 50, 5)
730-
sheetBrush = new Brush(sheetGeometry)
731-
sheetBrush.updateMatrixWorld()
732-
733-
csgEvaluator = new Evaluator()
723+
buildSheetWithHolesMesh = ->
734724

735-
# Create 2x2 grid of holes.
736-
gridSize = 2
737-
spacing = 50 / (gridSize + 1)
738-
offsetX = -50 / 2 + spacing
739-
offsetY = -50 / 2 + spacing
740-
holeRadius = 3
725+
spacing = SHEET_SIZE / (GRID_SIZE + 1)
726+
offsetX = -SHEET_SIZE / 2 + spacing
727+
offsetY = -SHEET_SIZE / 2 + spacing
728+
half = SHEET_SIZE / 2
741729

742-
resultBrush = sheetBrush
730+
sheetShape = new THREE.Shape()
731+
sheetShape.moveTo(-half, -half)
732+
sheetShape.lineTo(half, -half)
733+
sheetShape.lineTo(half, half)
734+
sheetShape.lineTo(-half, half)
735+
sheetShape.closePath()
743736

744-
for row in [0...gridSize]
737+
for row in [0...GRID_SIZE]
745738

746-
for col in [0...gridSize]
739+
for col in [0...GRID_SIZE]
747740

748-
# Calculate hole position.
749741
holeX = offsetX + col * spacing
750742
holeY = offsetY + row * spacing
751743

752-
# Create cylinder for hole.
753-
holeGeometry = new THREE.CylinderGeometry(holeRadius, holeRadius, 10, 32)
754-
holeMesh = new Brush(holeGeometry)
744+
holePath = new THREE.Path()
745+
holePath.absarc(holeX, holeY, HOLE_RADIUS, 0, Math.PI * 2, false)
746+
sheetShape.holes.push(holePath)
755747

756-
holeMesh.rotation.x = Math.PI / 2
757-
holeMesh.position.set(holeX, holeY, 0)
758-
holeMesh.updateMatrixWorld()
748+
sheetGeometry = new THREE.ExtrudeGeometry(sheetShape, { depth: THICKNESS, bevelEnabled: false })
759749

760-
# Subtract hole from sheet.
761-
resultBrush = csgEvaluator.evaluate(resultBrush, holeMesh, SUBTRACTION)
750+
mesh = new THREE.Mesh(sheetGeometry, new THREE.MeshBasicMaterial())
751+
mesh.position.set(0, 0, 0)
752+
mesh.updateMatrixWorld()
762753

763-
# Restore console.warn.
764-
console.warn = originalWarn
754+
return mesh
765755

766-
# Create final mesh.
767-
finalMesh = new THREE.Mesh(resultBrush.geometry, new THREE.MeshBasicMaterial())
768-
finalMesh.position.set(0, 0, 2.5)
769-
finalMesh.updateMatrixWorld()
756+
test 'should print outer boundary walls before hole walls', ->
757+
758+
# Create a sheet with holes using ExtrudeGeometry (no CSG required).
759+
finalMesh = buildSheetWithHolesMesh()
770760

771761
# Configure slicer.
772762
slicer.setLayerHeight(0.2)
@@ -896,56 +886,8 @@ describe 'Slicing', ->
896886

897887
test 'should generate skin walls immediately after regular walls for holes on skin layers', ->
898888

899-
# This test validates the skin wall integration feature.
900-
# Import CSG dependencies.
901-
{ Brush, Evaluator, SUBTRACTION } = require('three-bvh-csg')
902-
903-
# Suppress MeshBVH deprecation warnings from three-bvh-csg.
904-
originalWarn = console.warn
905-
console.warn = jest.fn()
906-
907-
# Create a sheet with holes using CSG operations.
908-
sheetGeometry = new THREE.BoxGeometry(50, 50, 5)
909-
sheetBrush = new Brush(sheetGeometry)
910-
sheetBrush.updateMatrixWorld()
911-
912-
csgEvaluator = new Evaluator()
913-
914-
# Create 2x2 grid of holes.
915-
gridSize = 2
916-
spacing = 50 / (gridSize + 1)
917-
offsetX = -50 / 2 + spacing
918-
offsetY = -50 / 2 + spacing
919-
holeRadius = 3
920-
921-
resultBrush = sheetBrush
922-
923-
for row in [0...gridSize]
924-
925-
for col in [0...gridSize]
926-
927-
# Calculate hole position.
928-
holeX = offsetX + col * spacing
929-
holeY = offsetY + row * spacing
930-
931-
# Create cylinder for hole.
932-
holeGeometry = new THREE.CylinderGeometry(holeRadius, holeRadius, 10, 32)
933-
holeMesh = new Brush(holeGeometry)
934-
935-
holeMesh.rotation.x = Math.PI / 2
936-
holeMesh.position.set(holeX, holeY, 0)
937-
holeMesh.updateMatrixWorld()
938-
939-
# Subtract hole from sheet.
940-
resultBrush = csgEvaluator.evaluate(resultBrush, holeMesh, SUBTRACTION)
941-
942-
# Restore console.warn.
943-
console.warn = originalWarn
944-
945-
# Create final mesh.
946-
finalMesh = new THREE.Mesh(resultBrush.geometry, new THREE.MeshBasicMaterial())
947-
finalMesh.position.set(0, 0, 2.5)
948-
finalMesh.updateMatrixWorld()
889+
# Create a sheet with holes using ExtrudeGeometry (no CSG required).
890+
finalMesh = buildSheetWithHolesMesh()
949891

950892
# Configure slicer.
951893
slicer.setLayerHeight(0.2)

src/slicer/walls/walls.test.coffee

Lines changed: 38 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,34 @@ describe 'Wall Generation', ->
375375

376376
describe 'Travel Path Combing', ->
377377

378+
SHEET_W = 50
379+
DEPTH = 2
380+
HOLE_RADIUS = 3
381+
382+
buildSheetWithHolesMesh = (holePositions) ->
383+
384+
half = SHEET_W / 2
385+
sheetShape = new THREE.Shape()
386+
sheetShape.moveTo(-half, -half)
387+
sheetShape.lineTo(half, -half)
388+
sheetShape.lineTo(half, half)
389+
sheetShape.lineTo(-half, half)
390+
sheetShape.closePath()
391+
392+
for pos in holePositions
393+
394+
holePath = new THREE.Path()
395+
holePath.absarc(pos.x, pos.y, HOLE_RADIUS, 0, Math.PI * 2, false)
396+
sheetShape.holes.push(holePath)
397+
398+
sheetGeometry = new THREE.ExtrudeGeometry(sheetShape, { depth: DEPTH, bevelEnabled: false })
399+
400+
mesh = new THREE.Mesh(sheetGeometry, new THREE.MeshBasicMaterial())
401+
mesh.position.set(0, 0, 0)
402+
mesh.updateMatrixWorld()
403+
404+
return mesh
405+
378406
# Helper function to count combing paths in G-code.
379407
# A combing path is detected as 2+ consecutive G0 travel moves.
380408
countCombingPaths = (gcode) ->
@@ -402,45 +430,8 @@ describe 'Wall Generation', ->
402430

403431
test 'should use combing paths when traveling between hole walls', ->
404432

405-
# Create a simple mesh with a hole using CSG-like approach.
406-
# For testing, we'll create a thin box with a cylinder subtracted.
407-
Brush = null
408-
Evaluator = null
409-
SUBTRACTION = null
410-
411-
try
412-
{ Brush, Evaluator, SUBTRACTION } = require('three-bvh-csg')
413-
catch error
414-
console.warn('three-bvh-csg not available, skipping combing test')
415-
return
416-
417-
# Suppress MeshBVH deprecation warnings from three-bvh-csg.
418-
originalWarn = console.warn
419-
console.warn = jest.fn()
420-
421-
# Create a sheet (box).
422-
sheetGeometry = new THREE.BoxGeometry(50, 50, 2)
423-
sheetBrush = new Brush(sheetGeometry)
424-
sheetBrush.updateMatrixWorld()
425-
426-
# Create a hole (cylinder).
427-
holeGeometry = new THREE.CylinderGeometry(3, 3, 4, 32)
428-
holeBrush = new Brush(holeGeometry)
429-
holeBrush.rotation.x = Math.PI / 2
430-
holeBrush.position.set(0, 0, 0)
431-
holeBrush.updateMatrixWorld()
432-
433-
# Subtract hole from sheet.
434-
csgEvaluator = new Evaluator()
435-
resultBrush = csgEvaluator.evaluate(sheetBrush, holeBrush, SUBTRACTION)
436-
437-
# Restore console.warn.
438-
console.warn = originalWarn
439-
440-
# Create final mesh.
441-
mesh = new THREE.Mesh(resultBrush.geometry, new THREE.MeshBasicMaterial())
442-
mesh.position.set(0, 0, 1)
443-
mesh.updateMatrixWorld()
433+
# Create a sheet with a single centered hole using ExtrudeGeometry (no CSG required).
434+
mesh = buildSheetWithHolesMesh([{ x: 0, y: 0 }])
444435

445436
slicer.setNozzleDiameter(0.4)
446437
slicer.setShellWallThickness(0.8) # 2 walls
@@ -458,52 +449,15 @@ describe 'Wall Generation', ->
458449

459450
test 'should generate combing paths for multiple holes', ->
460451

461-
# Create a mesh with multiple holes.
462-
Brush = null
463-
Evaluator = null
464-
SUBTRACTION = null
465-
466-
try
467-
{ Brush, Evaluator, SUBTRACTION } = require('three-bvh-csg')
468-
catch error
469-
console.warn('three-bvh-csg not available, skipping combing test')
470-
return
452+
# Create a sheet with 4 holes in a 2x2 grid using ExtrudeGeometry (no CSG required).
453+
holePositions = [
454+
{ x: -12.5, y: -12.5 }
455+
{ x: 12.5, y: -12.5 }
456+
{ x: -12.5, y: 12.5 }
457+
{ x: 12.5, y: 12.5 }
458+
]
471459

472-
# Suppress MeshBVH deprecation warnings from three-bvh-csg.
473-
originalWarn = console.warn
474-
console.warn = jest.fn()
475-
476-
# Create a sheet (box).
477-
sheetGeometry = new THREE.BoxGeometry(50, 50, 2)
478-
sheetBrush = new Brush(sheetGeometry)
479-
sheetBrush.updateMatrixWorld()
480-
481-
csgEvaluator = new Evaluator()
482-
resultBrush = sheetBrush
483-
484-
# Create 4 holes in a 2x2 grid.
485-
for row in [0...2]
486-
487-
for col in [0...2]
488-
489-
x = -12.5 + col * 25
490-
y = -12.5 + row * 25
491-
492-
holeGeometry = new THREE.CylinderGeometry(3, 3, 4, 32)
493-
holeBrush = new Brush(holeGeometry)
494-
holeBrush.rotation.x = Math.PI / 2
495-
holeBrush.position.set(x, y, 0)
496-
holeBrush.updateMatrixWorld()
497-
498-
resultBrush = csgEvaluator.evaluate(resultBrush, holeBrush, SUBTRACTION)
499-
500-
# Restore console.warn.
501-
console.warn = originalWarn
502-
503-
# Create final mesh.
504-
mesh = new THREE.Mesh(resultBrush.geometry, new THREE.MeshBasicMaterial())
505-
mesh.position.set(0, 0, 1)
506-
mesh.updateMatrixWorld()
460+
mesh = buildSheetWithHolesMesh(holePositions)
507461

508462
slicer.setNozzleDiameter(0.4)
509463
slicer.setShellWallThickness(0.8) # 2 walls

0 commit comments

Comments
 (0)