25 lines
1.4 KiB
Python
25 lines
1.4 KiB
Python
import io,unittest
|
|
import numpy as np
|
|
from PIL import Image
|
|
from build123d import Box,Cylinder,Pos
|
|
from engine.render import render_shape_png
|
|
|
|
class VisibleDepthTests(unittest.TestCase):
|
|
def test_aligned_pocket_remains_visible_with_same_colored_floor(self):
|
|
shape=Box(30,30,6)-Pos(5,0,2.5)*Cylinder(3,3)
|
|
image=np.asarray(Image.open(io.BytesIO(render_shape_png(shape,'top',300))).convert('RGB'))
|
|
# Boundary of the real pocket, vs a nearby uninterrupted top face.
|
|
edge=image[152:166,213:220].astype(float).mean(axis=2)
|
|
flat=image[159,150].astype(float).mean()
|
|
self.assertLess(edge.min(),flat*.8)
|
|
def test_hidden_underside_pocket_does_not_show_through_roof(self):
|
|
solid=Box(30,30,6);pocket=solid-Pos(5,0,-2.5)*Cylinder(3,3)
|
|
a=np.asarray(Image.open(io.BytesIO(render_shape_png(solid,'top',300))).convert('RGB')).astype(float)
|
|
b=np.asarray(Image.open(io.BytesIO(render_shape_png(pocket,'top',300))).convert('RGB')).astype(float)
|
|
self.assertLess(np.mean(np.abs(a-b)),.01)
|
|
def test_raised_pad_has_visible_boundary_in_top_view(self):
|
|
shape=Box(30,30,6)+Pos(0,0,4.5)*Box(8,8,3)
|
|
im=np.asarray(Image.open(io.BytesIO(render_shape_png(shape,'top',300))).convert('RGB')).astype(float)
|
|
self.assertLess(im[153:166,181:186].mean(axis=2).min(),im[159,150].mean()*.8)
|
|
if __name__=='__main__':unittest.main()
|