|
| 1 | +const test = require('ava') |
| 2 | + |
| 3 | +const { geometries, primitives, booleans } = require('../../index') |
| 4 | +const { geom3 } = geometries |
| 5 | + |
| 6 | +test('isConvex: throws for non-geom3 input', (t) => { |
| 7 | + t.throws(() => geom3.isConvex('invalid'), { message: /requires a geom3/ }) |
| 8 | + t.throws(() => geom3.isConvex(null), { message: /requires a geom3/ }) |
| 9 | +}) |
| 10 | + |
| 11 | +test('isConvex: empty geometry is convex', (t) => { |
| 12 | + const empty = geom3.create() |
| 13 | + t.true(geom3.isConvex(empty)) |
| 14 | +}) |
| 15 | + |
| 16 | +test('isConvex: cuboid is convex', (t) => { |
| 17 | + const cube = primitives.cuboid({ size: [10, 10, 10] }) |
| 18 | + t.true(geom3.isConvex(cube)) |
| 19 | +}) |
| 20 | + |
| 21 | +test('isConvex: sphere is convex', (t) => { |
| 22 | + const sph = primitives.sphere({ radius: 5, segments: 16 }) |
| 23 | + t.true(geom3.isConvex(sph)) |
| 24 | +}) |
| 25 | + |
| 26 | +test('isConvex: cylinder is convex', (t) => { |
| 27 | + const cyl = primitives.cylinderElliptic({ height: 10, startRadius: [3, 3], endRadius: [3, 3], segments: 16 }) |
| 28 | + t.true(geom3.isConvex(cyl)) |
| 29 | +}) |
| 30 | + |
| 31 | +test('isConvex: cube with hole is not convex', (t) => { |
| 32 | + const cube = primitives.cuboid({ size: [10, 10, 10] }) |
| 33 | + const hole = primitives.cuboid({ size: [4, 4, 20] }) // Hole through the cube |
| 34 | + |
| 35 | + const withHole = booleans.subtract(cube, hole) |
| 36 | + t.false(geom3.isConvex(withHole)) |
| 37 | +}) |
| 38 | + |
| 39 | +test('isConvex: L-shaped solid is not convex', (t) => { |
| 40 | + const big = primitives.cuboid({ size: [10, 10, 10], center: [0, 0, 0] }) |
| 41 | + const corner = primitives.cuboid({ size: [6, 6, 12], center: [3, 3, 0] }) |
| 42 | + |
| 43 | + const lShape = booleans.subtract(big, corner) |
| 44 | + t.false(geom3.isConvex(lShape)) |
| 45 | +}) |
0 commit comments