File: test_620_knot.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (102 lines) | stat: -rw-r--r-- 2,567 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Copyright (c) 2018-2020 Manfred Moitzi
# License: MIT License
from ezdxf.math.bspline import (
    open_uniform_knot_vector,
    uniform_knot_vector,
    required_knot_values,
)

open_uniform_order2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 4.0]
open_uniform_order3 = [0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 5.0, 5.0]
open_uniform_order4 = [
    0.0,
    0.0,
    0.0,
    0.0,
    1.0,
    2.0,
    3.0,
    4.0,
    5.0,
    6.0,
    6.0,
    6.0,
    6.0,
]


def _normalize(values, max_value):
    return [v / max_value for v in values]


def test_open_uniform_knot_order_2():
    result = open_uniform_knot_vector(5, 2, normalize=False)
    assert len(result) == required_knot_values(5, 2)
    assert result == open_uniform_order2
    assert open_uniform_knot_vector(5, 2, normalize=True) == _normalize(
        open_uniform_order2, 4.0
    )


def test_open_uniform_knot_order_3():
    result = open_uniform_knot_vector(7, 3, normalize=False)
    assert len(result) == required_knot_values(7, 3)
    assert result == open_uniform_order3
    assert open_uniform_knot_vector(7, 3, normalize=True) == _normalize(
        open_uniform_order3, 5.0
    )


def test_open_uniform_knot_order_4():
    result = open_uniform_knot_vector(9, 4, normalize=False)
    assert len(result) == required_knot_values(9, 4)
    assert result == open_uniform_order4
    assert open_uniform_knot_vector(9, 4, normalize=True) == _normalize(
        open_uniform_order4, 6.0
    )


uniform_order2 = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
uniform_order3 = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
uniform_order4 = [
    0.0,
    1.0,
    2.0,
    3.0,
    4.0,
    5.0,
    6.0,
    7.0,
    8.0,
    9.0,
    10.0,
    11.0,
    12.0,
]


def test_uniform_knot_order_2():
    result = uniform_knot_vector(5, 2, normalize=False)
    assert len(result) == required_knot_values(5, 2)
    assert result == uniform_order2
    assert uniform_knot_vector(5, 2, normalize=True) == _normalize(
        uniform_order2, 6.0
    )


def test_uniform_knot_order_3():
    result = uniform_knot_vector(7, 3, normalize=False)
    assert len(result) == required_knot_values(7, 3)
    assert result == uniform_order3
    assert uniform_knot_vector(7, 3, normalize=True) == _normalize(
        uniform_order3, 9.0
    )


def test_uniform_knot_order_4():
    result = uniform_knot_vector(9, 4, normalize=False)
    assert len(result) == required_knot_values(9, 4)
    assert result == uniform_order4
    assert uniform_knot_vector(9, 4, normalize=True) == _normalize(
        uniform_order4, 12.0
    )