File size: 1,019 Bytes
2f5e0ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')))
import utils3d
import numpy as np

def run():
    args = [
        {'W':2, 'H':2, 'backslash': np.array([False])},
        {'W':2, 'H':2, 'backslash': np.array([True])},
        {'H':2, 'W':3, 'backslash': np.array([True, False])},
    ]

    expected = [
        np.array([[0, 2, 1], [1, 2, 3]]),
        np.array([[0, 2, 3], [0, 3, 1]]),
        np.array([[0, 3, 4], [0, 4, 1], [1, 4, 2], [2, 4, 5]]),
    ]

    for args, expected in zip(args, expected):
        actual = utils3d.numpy.triangulate(
            utils3d.numpy.image_mesh(args['H'], args['W'])[1],
            backslash=args.get('backslash', None),
        )
                    
        assert np.allclose(expected, actual), '\n' + \
            'Input:\n' + \
            f'{args}\n' + \
            'Actual:\n' + \
            f'{actual}\n' + \
            'Expected:\n' + \
            f'{expected}'