adze/adze/test/test_offset.py
2026-03-07 07:52:38 -08:00

46 lines
1.4 KiB
Python

import numpy
import adze
from adze.shapes import build_box
from adze.offset import offset
def test_offset_cube_expand() -> None:
# Unit cube: [0,1]x[0,1]x[0,1], vol=1
cube = build_box([[0, 0, 0], [1, 1, 1]])
# Expand by 0.1 on all sides
# New cube: [-0.1, 1.1] on all axes
# New side length = 1.2
# Expected volume = 1.2^3 = 1.728
expanded = offset(cube, 0.1)
vol = adze.get_volume(expanded)
assert numpy.isclose(vol, 1.728)
# Check bounds
vmin, vmax = adze.util.get_aabb(expanded)
assert numpy.allclose(vmin, [-0.1, -0.1, -0.1])
assert numpy.allclose(vmax, [1.1, 1.1, 1.1])
def test_offset_cube_shrink() -> None:
# Unit cube: [0,1]x[0,1]x[0,1], vol=1
cube = build_box([[0, 0, 0], [1, 1, 1]])
# Shrink by 0.1 on all sides
# New cube: [0.1, 0.9] on all axes
# New side length = 0.8
# Expected volume = 0.8^3 = 0.512
shrunk = offset(cube, -0.1)
vol = adze.get_volume(shrunk)
assert numpy.isclose(vol, 0.512)
# Check bounds
vmin, vmax = adze.util.get_aabb(shrunk)
assert numpy.allclose(vmin, [0.1, 0.1, 0.1])
assert numpy.allclose(vmax, [0.9, 0.9, 0.9])
def test_offset_zero() -> None:
cube = build_box([[0, 0, 0], [1, 1, 1]])
same = offset(cube, 0.0)
assert numpy.isclose(adze.get_volume(same), 1.0)
assert numpy.allclose(cube['vertices'], same['vertices'])