Skip to content

Commit 21408d0

Browse files
authored
Fix panic on zero points AddSurface (#113)
1 parent 9a8622b commit 21408d0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

command.go

+5
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ func (c *commandContext) AddSurface(resolution float32) bool {
504504

505505
w := int(l0 / resolution)
506506
h := int(l1 / resolution)
507+
508+
if w*h == 0 {
509+
return true
510+
}
511+
507512
pcNew := &pc.PointCloud{
508513
PointCloudHeader: c.editor.pp.PointCloudHeader.Clone(),
509514
Points: w * h,

command_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,34 @@ func TestBaseFileter(t *testing.T) {
285285
}, c.baseFilterByMask(false))
286286
})
287287
}
288+
289+
func TestAddSurface(t *testing.T) {
290+
var selectRange float32 = 1.0
291+
t.Run("NotSelected", func(t *testing.T) {
292+
c := &commandContext{
293+
selected: []mat.Vec3{
294+
{0, 0, 0},
295+
{0.1, 0, 0},
296+
},
297+
selectRange: &selectRange,
298+
}
299+
c.updateRect()
300+
if ok := c.AddSurface(0.11); ok {
301+
t.Fatal("AddSurface must success (but do nothing) if surface has zero points")
302+
}
303+
})
304+
t.Run("ZeroPoints", func(t *testing.T) {
305+
c := &commandContext{
306+
selected: []mat.Vec3{
307+
{0, 0, 0},
308+
{0.1, 0, 0},
309+
{0.1, 0.1, 0},
310+
},
311+
selectRange: &selectRange,
312+
}
313+
c.updateRect()
314+
if ok := c.AddSurface(0.11); !ok {
315+
t.Fatal("AddSurface must fail if region is not selected")
316+
}
317+
})
318+
}

0 commit comments

Comments
 (0)