Coverage for piemap/projections.py: 100.00%
37 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 21:26:31 +00:00
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-04 21:26:31 +00:00
1from typing import no_type_check
4@no_type_check
5def min_from_limit_max(limit, maximum):
6 """
7 Testdata: (-6, -1, 2, 5, 10) or (0, 5, 8, 11, 16)
8 yield (8*(-1) - 5*2) / 3 = -6 or (8*5 - 5*8) / 3 = 0
9 a ---- b -- c and bc/ac = 3/8 => 8c - 8b = 3c - 3a => a = (8b - 5c)/3
10 """
11 return (8.0 * limit - 5.0 * maximum) / 3.0
14@no_type_check
15def domain_from_limit_max(limit, maximum):
16 """Prepare the scales paradigm for non-folded axes."""
17 return min_from_limit_max(limit, maximum), maximum
20@no_type_check
21def limit_folded_from_limit_max(limit, maximum):
22 """
23 Testdata: (-6, -1, 2, 5, 10) or (0, 5, 8, 11, 16)
24 yield 2 * 2 - (-1) = 5 or 2 * 8 - 5 = 11
25 """
26 return 2.0 * maximum - limit # explicit maximum + ( maximum - limit )
29@no_type_check
30def min_folded_from_limit_max(limit, maximum):
31 """
32 Testdata: (-6, -1, 2, 5, 10) or (0, 5, 8, 11, 16)
33 yield (11*2 - 8*(-1)) / 3 = 10 or (11*8 - 8*5) / 3 = 16
34 a ---- b -- c ------- e and bc/ce = 3/8 => 8c - 8b = 3e - 3c => a = (11c - 8b)/3
35 """
36 return (11.0 * maximum - 8.0 * limit) / 3.0
39@no_type_check
40def domain_folded_from_limit_max(limit, maximum):
41 """Prepare the scales paradigm for folded axes."""
42 max_domain = min_folded_from_limit_max(limit, maximum)
43 min_domain = maximum + maximum - max_domain # maximum - (max_domain - maximum)
44 return min_domain, max_domain
47@no_type_check
48def value_folded_from_limit_max(value, maximum):
49 """
50 Testdata: (-6, -1, 2, 5, 10) or (0, 5, 8, 11, 16) # FIXME COPY
51 yield 2 * 2 - (-1) = 5 or 2 * 8 - 5 = 11 # FIXME COPY
52 """
53 return 2.0 * maximum - value # explicit maximum - ( value - maximum )
56@no_type_check
57def limit_ordered_from_domain(domain):
58 """
59 Testdata: ("3", "2c", "2b", "2a", "1") or ("ORIGIN", "not ok", "LIMIT_VALUE", "ok")
60 yield domain[len(domain) // 2] -> "2b" or "LIMIT_VALUE" in domain -> "LIMIT_VALUE"
61 """
62 if not domain:
63 return 'NULL'
64 if 'LIMIT_VALUE' in domain:
65 return 'LIMIT_VALUE'
66 return domain[len(domain) // 2]
69@no_type_check
70def min_ordered_from_domain(domain):
71 """
72 Testdata: ("3", "2c", "2b", "2a", "1") or ("ORIGIN", "not ok", "LIMIT_VALUE", "ok")
73 yield domain[0] -> "3" or domain[0] -> "ORIGIN"
74 """
75 return domain[0] if domain else 'NULL'
78@no_type_check
79def domain_ordered_from_domain(domain):
80 """Prepare the scales paradigm for ordered axes."""
81 return domain if domain else 'NULL'
84@no_type_check
85def max_ordered_from_domain(domain):
86 """
87 Testdata: ("3", "2c", "2b", "2a", "1") or ("ORIGIN", "not ok", "LIMIT_VALUE", "ok")
88 yield domain[-1] -> "1" or domain[-1] -> "ok"
89 """
90 return domain[-1] if domain else 'NULL'