src.acoustools.Paths.Numerals

  1import torch
  2from torch import Tensor
  3
  4
  5
  6def get_numeral(numeral:int|str, A:Tensor, B:Tensor, C:Tensor) -> list[Tensor]:
  7    '''
  8    Get positions to draw a given numeral \n
  9    :param numeral: The number to generate a path for [1,9] 
 10    :param A: top left corner of the box to draw in
 11    :param B: bottom left corner of the box to draw in
 12    :param C: top right corner of the box to draw in
 13    :return: path
 14
 15    '''
 16    if type(A) is not torch.Tensor or type(B) is not torch.Tensor or type(C) is not torch.Tensor:
 17        A = torch.Tensor(A)
 18        B = torch.Tensor(B)
 19        C = torch.Tensor(C)
 20    if int(numeral) == 1:
 21        return numeral_one(A,B,C)
 22    if int(numeral) == 2:
 23        return numeral_two(A,B,C)
 24    if int(numeral) == 3:
 25        return numeral_three(A,B,C)
 26    if int(numeral) == 4:
 27        return numeral_four(A,B,C)
 28    if int(numeral) == 5:
 29        return numeral_five(A,B,C)
 30    if int(numeral) == 6:
 31        return numeral_six(A,B,C)
 32    if int(numeral) == 7:
 33        return numeral_seven(A,B,C)
 34    if int(numeral) == 8:
 35        return numeral_eight(A,B,C)
 36    if int(numeral) == 9:
 37        return numeral_nine(A,B,C)
 38
 39def numeral_one(A,B,C):
 40    '''
 41    @private
 42    '''
 43    AB = B-A
 44    AC = C-A
 45    
 46    points = []
 47
 48    points.append(A + 0.5*AB + 0.1*AC)
 49    points.append(A + 0.5*AB + 0.9*AC)
 50
 51    return points
 52
 53def numeral_two(A,B,C):
 54    '''
 55    @private
 56    '''
 57    AB = B-A
 58    AC = C-A
 59    
 60    points = []
 61
 62    points.append(A+ 0.1*AB + 0.1 * AC)
 63    points.append(A+ 0.9*AB + 0.5 * AC)
 64    points.append(A+ 0.1*AB + 0.9 * AC)
 65    points.append(A+ 0.9*AB + 0.9 * AC)
 66
 67    return points
 68
 69def numeral_three(A,B,C):
 70    '''
 71    @private
 72    '''
 73    AB = B-A
 74    AC = C-A
 75    
 76    points = []
 77
 78    points.append(A+ 0.1*AB + 0.1 * AC)
 79    points.append(A+ 0.9*AB + 0.3 * AC)
 80    points.append(A+ 0.3*AB + 0.5 * AC)
 81    points.append(A+ 0.9*AB + 0.7 * AC)
 82    points.append(A+ 0.1*AB + 0.9 * AC)
 83
 84    return points
 85
 86def numeral_four(A,B,C):
 87    '''
 88    @private
 89    '''
 90    AB = B-A
 91    AC = C-A
 92    
 93    points = []
 94
 95    points.append(A+ 0.1*AB + 0.1 * AC)
 96    points.append(A+ 0.1*AB + 0.5 * AC)
 97    points.append(A+ 0.9*AB + 0.5 * AC)
 98    points.append(A+ 0.9*AB + 0.1 * AC)
 99    points.append(A+ 0.9*AB + 0.1 * AC)
100    points.append(A+ 0.9*AB + 0.9 * AC)
101
102    return points
103
104def numeral_five(A,B,C):
105    '''
106    @private
107    '''
108    AB = B-A
109    AC = C-A
110    
111    points = []
112
113    points.append(A+ 0.9*AB + 0.1 * AC)
114    points.append(A+ 0.1*AB + 0.1 * AC)
115    points.append(A+ 0.1*AB + 0.3 * AC)
116    points.append(A+ 0.9*AB + 0.6 * AC)
117    points.append(A+ 0.1*AB + 0.9 * AC)
118
119    return points
120
121def numeral_six(A,B,C):
122    '''
123    @private
124    '''
125    AB = B-A
126    AC = C-A
127
128    points = []
129    
130    points.append(A+ 0.1*AB + 0.1 * AC)
131    points.append(A+ 0.1*AB + 0.9 * AC)
132    points.append(A+ 0.9*AB + 0.9 * AC)
133    points.append(A+ 0.9*AB + 0.5 * AC)
134    points.append(A+ 0.1*AB + 0.5 * AC)
135
136    return points
137
138def numeral_seven(A,B,C):
139    '''
140    @private
141    '''
142    AB = B-A
143    AC = C-A
144
145    points = []
146    points.append(A+ 0.1*AB + 0.1 * AC)
147    points.append(A+ 0.5*AB + 0.1 * AC)
148    points.append(A+ 0.5*AB + 0.9 * AC)
149
150    return points
151
152def numeral_eight(A,B,C):
153    '''
154    @private
155    '''
156    AB = B-A
157    AC = C-A
158
159    points = []
160    points.append(A+ 0.5*AB + 0.5 * AC)
161    points.append(A+ 0.1*AB + 0.1 * AC)
162    points.append(A+ 0.9*AB + 0.1 * AC)
163    points.append(A+ 0.1*AB + 0.9 * AC)
164    points.append(A+ 0.9*AB + 0.9 * AC)
165    points.append(A+ 0.5*AB + 0.5 * AC)
166
167    return points
168
169def numeral_nine(A,B,C):
170    '''
171    @private
172    '''
173    AB = B-A
174    AC = C-A
175
176    points = []
177    points.append(A+ 0.9*AB + 0.5 * AC)
178    points.append(A+ 0.1*AB + 0.5 * AC)
179    points.append(A+ 0.1*AB + 0.1 * AC)
180    points.append(A+ 0.9*AB + 0.1 * AC)
181    points.append(A+ 0.9*AB + 0.9 * AC)
182
183    return points
def get_numeral( numeral: int | str, A: torch.Tensor, B: torch.Tensor, C: torch.Tensor) -> list[torch.Tensor]:
 7def get_numeral(numeral:int|str, A:Tensor, B:Tensor, C:Tensor) -> list[Tensor]:
 8    '''
 9    Get positions to draw a given numeral \n
10    :param numeral: The number to generate a path for [1,9] 
11    :param A: top left corner of the box to draw in
12    :param B: bottom left corner of the box to draw in
13    :param C: top right corner of the box to draw in
14    :return: path
15
16    '''
17    if type(A) is not torch.Tensor or type(B) is not torch.Tensor or type(C) is not torch.Tensor:
18        A = torch.Tensor(A)
19        B = torch.Tensor(B)
20        C = torch.Tensor(C)
21    if int(numeral) == 1:
22        return numeral_one(A,B,C)
23    if int(numeral) == 2:
24        return numeral_two(A,B,C)
25    if int(numeral) == 3:
26        return numeral_three(A,B,C)
27    if int(numeral) == 4:
28        return numeral_four(A,B,C)
29    if int(numeral) == 5:
30        return numeral_five(A,B,C)
31    if int(numeral) == 6:
32        return numeral_six(A,B,C)
33    if int(numeral) == 7:
34        return numeral_seven(A,B,C)
35    if int(numeral) == 8:
36        return numeral_eight(A,B,C)
37    if int(numeral) == 9:
38        return numeral_nine(A,B,C)

Get positions to draw a given numeral

Parameters
  • numeral: The number to generate a path for [1,9]
  • A: top left corner of the box to draw in
  • B: bottom left corner of the box to draw in
  • C: top right corner of the box to draw in
Returns

path