@@ -15,8 +15,9 @@ class Layer(abc.ABC):
15
15
start_size : float
16
16
c2c_expansion : float
17
17
18
- def __init__ (self , max_length : float ):
19
- self .max_length = max_length
18
+ def __init__ (self , remainder : float ):
19
+ # remaining length of the wire
20
+ self .remainder = remainder
20
21
21
22
@property
22
23
@abc .abstractmethod
@@ -26,7 +27,7 @@ def length(self) -> float:
26
27
@property
27
28
def count (self ) -> int :
28
29
"""Returns cell count in this layer"""
29
- length = min (self .length , self .max_length )
30
+ length = min (self .length , self .remainder )
30
31
return gr .get_count__start_size__c2c_expansion (length , self .start_size , self .c2c_expansion )
31
32
32
33
@property
@@ -41,7 +42,26 @@ def end_size(self) -> float:
41
42
@property
42
43
def is_final (self ) -> bool :
43
44
"""Returns True if this layer is the last (no more space for additional ones)"""
44
- return self .length >= self .max_length
45
+ return self .length >= self .remainder
46
+
47
+ def get_chop (self , total_count : int , invert : bool ) -> Chop :
48
+ """Returns a Chop with either this layer's count or given one,
49
+ whichever is lower"""
50
+ # length ratios will be normalized later
51
+ if invert :
52
+ return Chop (
53
+ length_ratio = self .length ,
54
+ end_size = self .end_size ,
55
+ c2c_expansion = 1 / self .c2c_expansion ,
56
+ count = max (self .count , total_count ),
57
+ )
58
+
59
+ return Chop (
60
+ length_ratio = self .length ,
61
+ start_size = self .start_size ,
62
+ c2c_expansion = self .c2c_expansion ,
63
+ count = max (self .count , total_count ),
64
+ )
45
65
46
66
def __repr__ (self ):
47
67
return f"{ self .length } -{ self .count } "
@@ -57,7 +77,7 @@ def __init__(self, wall_size: float, c2c_expansion: float, thickness_factor: int
57
77
58
78
@property
59
79
def length (self ):
60
- return min (self .max_length , self .start_size * self .thickness_factor )
80
+ return min (self .remainder , self .start_size * self .thickness_factor )
61
81
62
82
63
83
class BufferLayer (Layer ):
@@ -100,17 +120,17 @@ def last_size(self):
100
120
101
121
102
122
class BulkLayer (Layer ):
103
- def __init__ (self , cell_size : float , remaning_length : float ):
123
+ def __init__ (self , cell_size : float , remainder : float ):
104
124
self .start_size = cell_size
105
125
106
126
self .cell_size = cell_size
107
127
self .c2c_expansion = 1
108
128
109
- super ().__init__ (remaning_length )
129
+ super ().__init__ (remainder )
110
130
111
131
@property
112
132
def length (self ):
113
- return self .max_length
133
+ return self .remainder
114
134
115
135
@property
116
136
def last_size (self ):
@@ -145,6 +165,26 @@ def is_done(self) -> bool:
145
165
146
166
return self .remaining_length <= 0
147
167
168
+ def get_chops (self , total_count : int , invert : bool ) -> List [Chop ]:
169
+ chops : List [Chop ] = []
170
+
171
+ for layer in self .layers :
172
+ chop = layer .get_chop (total_count , invert )
173
+ chops .append (chop )
174
+
175
+ total_count -= layer .count
176
+
177
+ if total_count <= 0 :
178
+ break
179
+
180
+ # normalize length_ratios
181
+ ratios = [chop .length_ratio for chop in chops ]
182
+
183
+ for chop in chops :
184
+ chop .length_ratio = chop .length_ratio / sum (ratios )
185
+
186
+ return chops
187
+
148
188
149
189
class InflationGraderParams (SmoothGraderParams ):
150
190
"""See description of InflationGrader"""
@@ -165,6 +205,7 @@ def __init__(
165
205
self .bl_thickness_factor = bl_thickness_factor
166
206
self .buffer_expansion = buffer_expansion
167
207
208
+ # use SmoothGrader's logic for bulk chops
168
209
self .cell_size = self .bulk_cell_size
169
210
170
211
def get_inflation_layer (self , max_length : float ) -> InflationLayer :
@@ -195,6 +236,8 @@ def get_stack(self, length: float) -> LayerStack:
195
236
return stack
196
237
197
238
def get_count (self , length : float , starts_at_wall : bool , ends_at_wall : bool ):
239
+ print (starts_at_wall , ends_at_wall )
240
+
198
241
if not (starts_at_wall or ends_at_wall ):
199
242
return super ().get_count (length , False , False )
200
243
@@ -211,6 +254,8 @@ def is_squeezed(self, count: int, info: WireInfo) -> bool:
211
254
if not (info .starts_at_wall or info .ends_at_wall ):
212
255
return super ().is_squeezed (count , info )
213
256
257
+ # a squeezed wire is one that can't fit all layers
258
+ # or one that can't fit all cells
214
259
stack = self .get_stack (info .length )
215
260
216
261
if len (stack .layers ) == 3 :
@@ -222,4 +267,12 @@ def get_chops(self, count, info: WireInfo) -> List[Chop]:
222
267
if not (info .starts_at_wall or info .ends_at_wall ):
223
268
return super ().get_chops (count , info )
224
269
225
- raise NotImplementedError
270
+ stack = self .get_stack (info .length )
271
+
272
+ if info .starts_at_wall and info .ends_at_wall :
273
+ raise NotImplementedError
274
+
275
+ if info .ends_at_wall :
276
+ return list (reversed (stack .get_chops (count , True )))
277
+
278
+ return stack .get_chops (count , False )
0 commit comments