1use std::slice;
2use std::vec::IntoIter;
3
4use crate::idx::Idx;
5use crate::moc::{
6 cellcellrange::{CellOrCellRangeMOC, CellOrCellRangeMocIter, CellOrCellRangeRefMocIter},
7 CellOrCellRangeMOCIntoIterator, NonOverlapping, ZSorted,
8};
9use crate::moc2d::{
10 CellOrCellRangeMOC2ElemIt, CellOrCellRangeMOC2IntoIterator, CellOrCellRangeMOC2Iterator,
11 HasTwoMaxDepth, MOC2Properties,
12};
13use crate::qty::MocQty;
14
15pub struct CellOrCellRangeMOC2Elem<T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>> {
22 moc_l: CellOrCellRangeMOC<T, Q>, moc_r: CellOrCellRangeMOC<U, R>, }
25impl<T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>> CellOrCellRangeMOC2Elem<T, Q, U, R> {
26 pub fn new(moc_l: CellOrCellRangeMOC<T, Q>, moc_r: CellOrCellRangeMOC<U, R>) -> Self {
27 Self { moc_l, moc_r }
28 }
29
30 pub fn mocs(self) -> (CellOrCellRangeMOC<T, Q>, CellOrCellRangeMOC<U, R>) {
31 (self.moc_l, self.moc_r)
32 }
33}
34impl<T, Q, U, R> CellOrCellRangeMOC2ElemIt<T, Q, U, R> for CellOrCellRangeMOC2Elem<T, Q, U, R>
35where
36 T: Idx,
37 Q: MocQty<T>,
38 U: Idx,
39 R: MocQty<U>,
40{
41 type It1 = CellOrCellRangeMocIter<T, Q>;
42 type It2 = CellOrCellRangeMocIter<U, R>;
43 fn cellcellrange_mocs_it(self) -> (Self::It1, Self::It2) {
44 (
45 self.moc_l.into_cellcellrange_moc_iter(),
46 self.moc_r.into_cellcellrange_moc_iter(),
47 )
48 }
49}
50impl<'a, T, Q, U, R> CellOrCellRangeMOC2ElemIt<T, Q, U, R>
51 for &'a CellOrCellRangeMOC2Elem<T, Q, U, R>
52where
53 T: Idx,
54 Q: MocQty<T>,
55 U: Idx,
56 R: MocQty<U>,
57{
58 type It1 = CellOrCellRangeRefMocIter<'a, T, Q>;
59 type It2 = CellOrCellRangeRefMocIter<'a, U, R>;
60 fn cellcellrange_mocs_it(self) -> (Self::It1, Self::It2) {
61 (
62 (&self.moc_l).into_cellcellrange_moc_iter(),
63 (&self.moc_r).into_cellcellrange_moc_iter(),
64 )
65 }
66}
67
68pub struct CellOrCellRangeMOC2<T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>> {
70 depth_max_l: u8,
71 depth_max_r: u8, elems: Vec<CellOrCellRangeMOC2Elem<T, Q, U, R>>,
73}
74impl<T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>> CellOrCellRangeMOC2<T, Q, U, R> {
75 pub fn new(
76 depth_max_l: u8,
77 depth_max_r: u8,
78 elems: Vec<CellOrCellRangeMOC2Elem<T, Q, U, R>>,
79 ) -> Self {
80 Self {
81 depth_max_l,
82 depth_max_r,
83 elems,
84 }
85 }
86 pub fn is_empty(&self) -> bool {
87 self.elems.is_empty()
88 }
89}
90impl<T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>> HasTwoMaxDepth
91 for CellOrCellRangeMOC2<T, Q, U, R>
92{
93 fn depth_max_1(&self) -> u8 {
94 self.depth_max_l
95 }
96 fn depth_max_2(&self) -> u8 {
97 self.depth_max_r
98 }
99}
100
101pub struct CellOrCellRangeMoc2Iter<T, Q, U, R>
103where
104 T: Idx,
105 Q: MocQty<T>,
106 U: Idx,
107 R: MocQty<U>,
108{
109 depth_max_l: u8,
110 depth_max_r: u8,
111 iter: IntoIter<CellOrCellRangeMOC2Elem<T, Q, U, R>>,
112}
113impl<T, Q, U, R> HasTwoMaxDepth for CellOrCellRangeMoc2Iter<T, Q, U, R>
114where
115 T: Idx,
116 Q: MocQty<T>,
117 U: Idx,
118 R: MocQty<U>,
119{
120 fn depth_max_1(&self) -> u8 {
121 self.depth_max_l
122 }
123 fn depth_max_2(&self) -> u8 {
124 self.depth_max_r
125 }
126}
127impl<T, Q, U, R> ZSorted for CellOrCellRangeMoc2Iter<T, Q, U, R>
128where
129 T: Idx,
130 Q: MocQty<T>,
131 U: Idx,
132 R: MocQty<U>,
133{
134}
135impl<T, Q, U, R> NonOverlapping for CellOrCellRangeMoc2Iter<T, Q, U, R>
136where
137 T: Idx,
138 Q: MocQty<T>,
139 U: Idx,
140 R: MocQty<U>,
141{
142}
143impl<T, Q, U, R> MOC2Properties for CellOrCellRangeMoc2Iter<T, Q, U, R>
144where
145 T: Idx,
146 Q: MocQty<T>,
147 U: Idx,
148 R: MocQty<U>,
149{
150}
151impl<T, Q, U, R> Iterator for CellOrCellRangeMoc2Iter<T, Q, U, R>
152where
153 T: Idx,
154 Q: MocQty<T>,
155 U: Idx,
156 R: MocQty<U>,
157{
158 type Item = CellOrCellRangeMOC2Elem<T, Q, U, R>;
159 fn next(&mut self) -> Option<Self::Item> {
160 self.iter.next()
161 }
162}
163impl<T, Q, U, R>
164 CellOrCellRangeMOC2Iterator<
165 T,
166 Q,
167 CellOrCellRangeMocIter<T, Q>,
168 U,
169 R,
170 CellOrCellRangeMocIter<U, R>,
171 CellOrCellRangeMOC2Elem<T, Q, U, R>,
172 > for CellOrCellRangeMoc2Iter<T, Q, U, R>
173where
174 T: Idx,
175 Q: MocQty<T>,
176 U: Idx,
177 R: MocQty<U>,
178{
179}
180
181impl<T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>>
182 CellOrCellRangeMOC2IntoIterator<
183 T,
184 Q,
185 CellOrCellRangeMocIter<T, Q>,
186 U,
187 R,
188 CellOrCellRangeMocIter<U, R>,
189 CellOrCellRangeMOC2Elem<T, Q, U, R>,
190 > for CellOrCellRangeMOC2<T, Q, U, R>
191{
192 type IntoCellOrCellRangeMOC2Iter = CellOrCellRangeMoc2Iter<T, Q, U, R>;
193
194 fn into_cellcellrange_moc2_iter(self) -> Self::IntoCellOrCellRangeMOC2Iter {
195 CellOrCellRangeMoc2Iter {
196 depth_max_l: self.depth_max_l,
197 depth_max_r: self.depth_max_r,
198 iter: self.elems.into_iter(),
199 }
200 }
201}
202
203pub struct CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
205where
206 T: Idx,
207 Q: MocQty<T>,
208 U: Idx,
209 R: MocQty<U>,
210{
211 depth_max_l: u8,
212 depth_max_r: u8,
213 iter: slice::Iter<'a, CellOrCellRangeMOC2Elem<T, Q, U, R>>,
214}
215impl<'a, T, Q, U, R> HasTwoMaxDepth for CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
216where
217 T: Idx,
218 Q: MocQty<T>,
219 U: Idx,
220 R: MocQty<U>,
221{
222 fn depth_max_1(&self) -> u8 {
223 self.depth_max_l
224 }
225 fn depth_max_2(&self) -> u8 {
226 self.depth_max_r
227 }
228}
229impl<'a, T, Q, U, R> ZSorted for CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
230where
231 T: Idx,
232 Q: MocQty<T>,
233 U: Idx,
234 R: MocQty<U>,
235{
236}
237impl<'a, T, Q, U, R> NonOverlapping for CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
238where
239 T: Idx,
240 Q: MocQty<T>,
241 U: Idx,
242 R: MocQty<U>,
243{
244}
245impl<'a, T, Q, U, R> MOC2Properties for CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
246where
247 T: Idx,
248 Q: MocQty<T>,
249 U: Idx,
250 R: MocQty<U>,
251{
252}
253impl<'a, T, Q, U, R> Iterator for CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
254where
255 T: Idx,
256 Q: MocQty<T>,
257 U: Idx,
258 R: MocQty<U>,
259{
260 type Item = &'a CellOrCellRangeMOC2Elem<T, Q, U, R>;
261 fn next(&mut self) -> Option<Self::Item> {
262 self.iter.next()
263 }
264}
265impl<'a, T, Q, U, R>
266 CellOrCellRangeMOC2Iterator<
267 T,
268 Q,
269 CellOrCellRangeRefMocIter<'a, T, Q>,
270 U,
271 R,
272 CellOrCellRangeRefMocIter<'a, U, R>,
273 &'a CellOrCellRangeMOC2Elem<T, Q, U, R>,
274 > for CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>
275where
276 T: Idx,
277 Q: MocQty<T>,
278 U: Idx,
279 R: MocQty<U>,
280{
281}
282impl<'a, T: Idx, Q: MocQty<T>, U: Idx, R: MocQty<U>>
283 CellOrCellRangeMOC2IntoIterator<
284 T,
285 Q,
286 CellOrCellRangeRefMocIter<'a, T, Q>,
287 U,
288 R,
289 CellOrCellRangeRefMocIter<'a, U, R>,
290 &'a CellOrCellRangeMOC2Elem<T, Q, U, R>,
291 > for &'a CellOrCellRangeMOC2<T, Q, U, R>
292{
293 type IntoCellOrCellRangeMOC2Iter = CellOrCellRangeRefMoc2Iter<'a, T, Q, U, R>;
294
295 fn into_cellcellrange_moc2_iter(self) -> Self::IntoCellOrCellRangeMOC2Iter {
296 CellOrCellRangeRefMoc2Iter {
297 depth_max_l: self.depth_max_l,
298 depth_max_r: self.depth_max_r,
299 iter: self.elems.iter(),
300 }
301 }
302}