ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
//! [`Quad<T>`](Quad): four corners in WINDING ORDER, and the one convention in this house that a
//! test exists to pin rather than to document.

use crate::{
  ColumnEq, ColumnKind, ColumnName, ColumnShape, CompositeFilterMarker, CompositeMarker,
  CursorValue, DefaultMarker, DefaultVecMarker, FieldName, PayloadFilter, QuantifiedMarker,
};

use super::{NormCoord, Point2, Point2Filter};

/// **One leaf, and it is the value** — Quad<T> means its columns in the sequence it declares them, so
/// no term over one ever expands and the word is the whole row.
impl<T> crate::DeclaredLeaves for Quad<T> {}

#[cfg(test)]
mod tests;

/// **A QUADRILATERAL** — four corners, in whatever `T` the declaration measures in.
///
/// ```text
///   top_left ●──────────● top_right
///            │          │
///            │          │
/// bottom_left ●──────────● bottom_right
/// ```
///
/// It is the shape a rectangle stops being able to hold: a document photographed at an angle, a
/// text line on a curled page, a barcode seen off-axis. A [`BoundingBox`](super::BoundingBox) can
/// only be the axis-aligned box AROUND such a thing, which is a different and coarser fact.
///
/// # PERIMETER WINDING ORDER — top-left, top-right, bottom-right, bottom-left
///
/// **The order is not raster order, and reading it as one builds a bow-tie out of every real
/// quadrilateral.** `(TL, TR, BL, BR)` — the order a reader who thinks in rows expects — walks the
/// perimeter as a figure-eight, crossing itself between the second and third corners. That is
/// `avanalyze`'s `DocumentSegment` contract word for word, whose own note says a conformance suite
/// pins it by feeding a well-formed quad in winding order; this house pins it the same way, in
/// `quad/tests.rs`, because a convention that only a doc comment holds is a convention one
/// refactor away from being lost.
///
/// The corner NAMES are what make the order checkable rather than remembered. A positional
/// four-tuple would let two of the four be transposed with no type error and no test failure that
/// named the cause; four [`Point2<T>`](Point2) fields under their own names cannot be.
///
/// # A DUMB GENERIC HOLDER, and the corners are not checked against each other
///
/// [`new`](Self::new) is total and `const`. **Convexity, self-intersection and whether the corner a
/// field calls `top_left` is actually the topmost-leftmost are NOT checked**, and the omission is
/// deliberate rather than deferred: a quadrilateral seen at an angle can have its `top_left` below
/// its `top_right` in the frame, so a check that enforced the names would refuse exactly the
/// observations this type exists to hold. What the names carry is the ORDER a producer emits in,
/// which is the thing a consumer has to agree about.
///
/// # NO `Ord`, and the BOX around a quad is a METHOD rather than a conversion
///
/// Four positions have no order, for [`Point2`]'s reason multiplied. The axis-aligned box around a
/// quad IS a genuine reading and it has landed as [`bounds`](Self::bounds) — bounded on the
/// component's own comparison and subtraction, spelled at the method rather than at the type. It is
/// not a `From`: the projection is LOSSY, so a caller says the word.
///
/// # Examples
///
/// ```
/// use ingraph::{NormCoord, Point2, Quad};
///
/// let corner = |x: f32, y: f32| Point2::try_unit(x, y).unwrap();
/// let page = Quad::new(
///   corner(0.10, 0.12),
///   corner(0.90, 0.10),
///   corner(0.92, 0.88),
///   corner(0.08, 0.90),
/// );
///
/// assert_eq!(page.top_left().x(), NormCoord::new(0.10).unwrap());
/// assert_eq!(page.bottom_left().y(), NormCoord::new(0.90).unwrap());
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Quad<T> {
  top_left: Point2<T>,
  top_right: Point2<T>,
  bottom_right: Point2<T>,
  bottom_left: Point2<T>,
}

impl<T> Quad<T> {
  /// The quadrilateral through these four corners, **in winding order**.
  ///
  /// The parameter order is the winding one and the names say so, which is the whole of this
  /// constructor's contract: see the type's note for what reading it as raster order costs.
  #[inline]
  #[must_use]
  pub const fn new(
    top_left: Point2<T>,
    top_right: Point2<T>,
    bottom_right: Point2<T>,
    bottom_left: Point2<T>,
  ) -> Self {
    Self {
      top_left,
      top_right,
      bottom_right,
      bottom_left,
    }
  }

  /// The first corner in winding order.
  #[inline]
  pub const fn top_left(&self) -> Point2<T>
  where
    T: Copy,
  {
    self.top_left
  }

  /// The second corner in winding order.
  #[inline]
  pub const fn top_right(&self) -> Point2<T>
  where
    T: Copy,
  {
    self.top_right
  }

  /// The third corner in winding order.
  #[inline]
  pub const fn bottom_right(&self) -> Point2<T>
  where
    T: Copy,
  {
    self.bottom_right
  }

  /// The fourth corner in winding order.
  #[inline]
  pub const fn bottom_left(&self) -> Point2<T>
  where
    T: Copy,
  {
    self.bottom_left
  }

  /// The four corners, **in winding order** — the reading a renderer walks a perimeter with.
  ///
  /// An array rather than an iterator, because the arity is the type's and a caller destructuring
  /// four names wants them by position once they have agreed what the positions mean.
  #[inline]
  pub const fn corners(&self) -> [Point2<T>; 4]
  where
    T: Copy,
  {
    [
      self.top_left,
      self.top_right,
      self.bottom_right,
      self.bottom_left,
    ]
  }

  /// **THE TIGHTEST AXIS-ALIGNED RECTANGLE THE FOUR CORNERS SPAN** — derived at the call, stored by
  /// nobody.
  ///
  /// A quad is what a rectangle stops being able to hold, and this is the reduction back: the
  /// smallest `xywh` box containing all four corners. It is what a crop, a thumbnail and an area
  /// filter each want from a photographed page, and it is LOSSY — the angle is gone — which is why
  /// it is a method a caller spells rather than a `From` the compiler applies.
  ///
  /// A stored box beside the corners would have been a fifth value the corners already determine and
  /// an `UPDATE` could put out of step with them. That is
  /// [`BoundingBox`](super::BoundingBox)'s own argument for `xywh` over a second corner, read one
  /// figure up.
  ///
  /// # THE BOUND IS THIS METHOD'S, and the census that picked it
  ///
  /// `T: Copy + PartialOrd + Sub<Output = T>` — the honest minimum for *four comparisons and two
  /// subtractions*, stated at the method exactly as [`corners`](Self::corners) states its own
  /// `T: Copy`. A quad over a component with no arithmetic is still a quad a caller can build, store
  /// and read back; only this reading is unavailable on it.
  ///
  /// **`PartialOrd` rather than `Ord`, and the choice is what admits the floats.** `f32` and `f64`
  /// are the widths every producer of quads measures in and neither publishes `Ord`. The comparison
  /// below is written with `<` so an INCOMPARABLE pair — a `NaN` corner in a component that admits
  /// one — leaves the running extreme where it was rather than panicking inside a reduction.
  ///
  /// # [`NormCoord`](super::NormCoord) IS OUT OF BOUNDS HERE, and it is a census finding
  ///
  /// The unit interval is closed under MULTIPLICATION and not under SUBTRACTION — `0.2 - 0.8` is
  /// `-0.6`, which is no coordinate — so that type publishes a `Mul` and no `Sub`, and this method's
  /// bound is therefore unsatisfied by it. `Quad<f32>` and `Quad<f64>` reach it and
  /// `Quad<NormCoord>` does not.
  ///
  /// That is deliberate rather than an omission. Closing it would mean an operator that saturates,
  /// clamps or panics on the values its own domain excludes, which is the *value quietly minted
  /// around the hole* this house refuses at every other door. What a normalized caller spends
  /// instead is one [`map`](Self::map)-shaped hop into the width it wants to measure the box in —
  /// and the reduction is a fraction of a frame either way.
  ///
  /// # Examples
  ///
  /// ```
  /// use ingraph::{Point2, Quad};
  ///
  /// // A page photographed at an angle: no two corners share a coordinate.
  /// let page = Quad::new(
  ///   Point2::new(0.10_f32, 0.11),
  ///   Point2::new(0.90, 0.12),
  ///   Point2::new(0.91, 0.88),
  ///   Point2::new(0.13, 0.89),
  /// );
  ///
  /// let around = page.bounds();
  /// assert_eq!(around.x(), 0.10);
  /// assert_eq!(around.y(), 0.11);
  /// assert_eq!(around.width(), 0.91 - 0.10);
  /// assert_eq!(around.height(), 0.89 - 0.11);
  /// ```
  #[must_use]
  pub fn bounds(&self) -> super::BoundingBox<T>
  where
    T: Copy + PartialOrd + core::ops::Sub<Output = T>,
  {
    let corners = self.corners();
    let (mut min_x, mut min_y) = (corners[0].x(), corners[0].y());
    let (mut max_x, mut max_y) = (min_x, min_y);

    for corner in &corners[1..] {
      let (x, y) = (corner.x(), corner.y());

      // `<` rather than a `min`/`max` reduction, so an incomparable pair leaves the running
      // extreme where it was instead of reaching a total order the component does not publish.
      if x < min_x {
        min_x = x;
      }
      if max_x < x {
        max_x = x;
      }
      if y < min_y {
        min_y = y;
      }
      if max_y < y {
        max_y = y;
      }
    }

    super::BoundingBox::new(min_x, min_y, max_x - min_x, max_y - min_y)
  }
}

impl Quad<NormCoord> {
  /// **The unit frame's constructor** — eight numbers, four corners, winding order.
  ///
  /// Each pair goes through [`Point2::try_unit`], so the refusal is the COMPONENT's and this
  /// constructor adds no rule of its own. A quad has no sum rule to check —
  /// [`BoundingBox::try_unit`](super::BoundingBox::try_unit) has one because an extent is added to
  /// a corner, and every number here IS a corner.
  ///
  /// # Errors
  ///
  /// [`OutsideTheUnitInterval`](super::OutsideTheUnitInterval) where any of the eight is not a
  /// coordinate.
  ///
  /// # Examples
  ///
  /// ```
  /// use ingraph::Quad;
  ///
  /// assert!(Quad::try_unit((0.1, 0.1), (0.9, 0.1), (0.9, 0.9), (0.1, 0.9)).is_ok());
  /// assert!(Quad::try_unit((0.1, 0.1), (1.9, 0.1), (0.9, 0.9), (0.1, 0.9)).is_err());
  /// ```
  pub fn try_unit(
    top_left: (f32, f32),
    top_right: (f32, f32),
    bottom_right: (f32, f32),
    bottom_left: (f32, f32),
  ) -> Result<Self, super::OutsideTheUnitInterval> {
    let corner = |(x, y): (f32, f32)| Point2::try_unit(x, y);

    Ok(Self::new(
      corner(top_left)?,
      corner(top_right)?,
      corner(bottom_right)?,
      corner(bottom_left)?,
    ))
  }
}

/// The first corner's segment.
pub(super) const TOP_LEFT: &FieldName = FieldName::new("top_left");

/// The second corner's segment.
pub(super) const TOP_RIGHT: &FieldName = FieldName::new("top_right");

/// The third corner's segment.
pub(super) const BOTTOM_RIGHT: &FieldName = FieldName::new("bottom_right");

/// The fourth corner's segment.
pub(super) const BOTTOM_LEFT: &FieldName = FieldName::new("bottom_left");

/// **The EIGHT columns a quadrilateral spans** — four corners, each a nested
/// [`Point2<T>`](Point2), each spending its own two.
///
/// The corners NEST rather than flatten, so a declaration writes `corners_top_left_x` and the frame
/// says which corner a column belongs to. Flattening them would put eight columns called `x`, `y`,
/// `x`, `y`, … in one namespace, which is a collision the renderer would have to invent names
/// around.
///
/// The LEAF GUARD is stated on the COMPONENT rather than on the corner, and that is the honest
/// place: `Point2<T>` is a composite by construction so an assertion about ITS width would always
/// fail, while the fact that decides this type's arity is the one two levels down — a component
/// spanning one column makes a corner two and a quad eight.
///
/// ```compile_fail,E0080
/// use ingraph::{ColumnKind, Quad, TimeRange};
///
/// const _: usize = <Quad<TimeRange> as ColumnKind>::SEGMENTS.len();
/// ```
impl<T: ColumnKind> ColumnKind for Quad<T> {
  const SEGMENTS: &'static [ColumnShape] = {
    assert!(
      T::SEGMENTS.is_empty(),
      "a quad's component spans ONE column: a composite component would make the quad's own width \
       depend on it, and a fixed-arity row cannot state that"
    );
    &[
      ColumnShape::Composite {
        field: Some(ColumnName::of(TOP_LEFT)),
        segments: <Point2<T> as ColumnKind>::SEGMENTS,
      },
      ColumnShape::Composite {
        field: Some(ColumnName::of(TOP_RIGHT)),
        segments: <Point2<T> as ColumnKind>::SEGMENTS,
      },
      ColumnShape::Composite {
        field: Some(ColumnName::of(BOTTOM_RIGHT)),
        segments: <Point2<T> as ColumnKind>::SEGMENTS,
      },
      ColumnShape::Composite {
        field: Some(ColumnName::of(BOTTOM_LEFT)),
        segments: <Point2<T> as ColumnKind>::SEGMENTS,
      },
    ]
  };
}

/// A quadrilateral is one column value when all four of its corners are, in winding order — the
/// same order the columns nest under.
impl<T: ColumnEq> ColumnEq for Quad<T> {
  #[inline]
  fn column_eq(&self, other: &Self) -> bool {
    self.top_left.column_eq(&other.top_left)
      && self.top_right.column_eq(&other.top_right)
      && self.bottom_right.column_eq(&other.bottom_right)
      && self.bottom_left.column_eq(&other.bottom_left)
  }
}

/// **The DECLARED half — EIGHT words**, the component's own, eight times, in the order the segments
/// above state.
impl<Db, T> crate::StoredAs<Db> for Quad<T>
where
  T: crate::StoredAs<Db>,
{
  const WORDS: &'static [&'static str] = &[
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
    <T as crate::StoredAs<Db>>::WORDS[0],
  ];
}

/// **THE ADMISSION**, delegating to the component. `Vec<Quad<NormCoord>>` is every text line on a
/// page, every document in a photograph — the shape a segmentation pass produces.
impl<T: crate::CollectionElement> crate::CollectionElement for Quad<T> {}

/// **EIGHT BINDS OUT**, four corners with three commas between them; each corner writes its own.
#[cfg(feature = "sqlx")]
impl<T, Db> crate::Carrier<Db> for Quad<T>
where
  Db: sqlx::Database,
  T: crate::Carrier<Db>,
{
  fn push_bind(&self, qb: &mut sqlx::QueryBuilder<Db>) {
    <Point2<T> as crate::Carrier<Db>>::push_bind(&self.top_left, qb);
    qb.push(", ");
    <Point2<T> as crate::Carrier<Db>>::push_bind(&self.top_right, qb);
    qb.push(", ");
    <Point2<T> as crate::Carrier<Db>>::push_bind(&self.bottom_right, qb);
    qb.push(", ");
    <Point2<T> as crate::Carrier<Db>>::push_bind(&self.bottom_left, qb);
  }
}

/// **AND THE EIGHT BACK IN**, each corner beneath its own frame.
#[cfg(feature = "sqlx")]
impl<'a, R, T> crate::Assemble<'a, R> for Quad<T>
where
  R: sqlx::Row,
  T: crate::Assemble<'a, R>,
{
  fn assemble(row: &'a R, under: Option<&crate::Path<'_>>) -> sqlx::Result<Self> {
    let top_left: Point2<T> = crate::assembled(row, TOP_LEFT, under)?;
    let top_right: Point2<T> = crate::assembled(row, TOP_RIGHT, under)?;
    let bottom_right: Point2<T> = crate::assembled(row, BOTTOM_RIGHT, under)?;
    let bottom_left: Point2<T> = crate::assembled(row, BOTTOM_LEFT, under)?;

    Ok(Self::new(top_left, top_right, bottom_right, bottom_left))
  }
}

/// **THE KEYSET POSITION** — the four corners in WINDING order, which is the segment order.
///
/// A STORAGE order, for the family's reason: this type publishes no [`Ord`].
impl<T: CursorValue> CursorValue for Quad<T> {
  fn write_cursor(&self, out: &mut Vec<u8>) {
    for corner in [
      &self.top_left,
      &self.top_right,
      &self.bottom_right,
      &self.bottom_left,
    ] {
      CursorValue::write_cursor(corner, out);
    }
  }

  fn read_cursor(bytes: &[u8]) -> Option<Self> {
    let corner = bytes.len() / 4;
    if corner == 0 || corner * 4 != bytes.len() {
      return None;
    }

    let read =
      |nth: usize| <Point2<T> as CursorValue>::read_cursor(&bytes[nth * corner..][..corner]);

    Some(Self::new(read(0)?, read(1)?, read(2)?, read(3)?))
  }
}

/// The COMPOSITE reading, on the family's terms.
impl<T: DefaultMarker> DefaultMarker for Quad<T> {
  type Marker = CompositeMarker<Quad<T>>;
}

/// **A COLLECTION of quadrilaterals is asked through the QUANTIFIERS alone.**
impl<T: DefaultMarker> DefaultVecMarker for Quad<T> {
  type Marker = QuantifiedMarker<Vec<Quad<T>>>;
}

/// What guards a [`Quad<T>`] column — its own filter at both seats, framework-open through
/// [`PayloadFilter<T>`](crate::PayloadFilter).
impl<T> CompositeFilterMarker for Quad<T>
where
  T: DefaultMarker,
{
  type Filter = QuadFilter<PayloadFilter<T>>;
  type ColumnFilter = QuadFilter<PayloadFilter<T>>;
}

/// **FOUR CORNER FACETS, each a whole [`Point2Filter`], and no whole-quad operator.**
///
/// ```text
/// input QuadF32Filter {
///   topLeft: Point2F32Filter      topRight: Point2F32Filter
///   bottomRight: Point2F32Filter  bottomLeft: Point2F32Filter
/// }
/// ```
///
/// The facets NEST rather than publishing eight component slots, which mirrors the columns: a
/// corner is a citizen, so everything a [`Point2Filter`] can answer is answerable one level up
/// without a line of it being restated. That is the recursion
/// [`MediaTimeRangeFilter`](crate::MediaTimeRangeFilter) has over its timebase, one house over.
///
/// The leaf-tuple EQUALITY is the conjunction of the eight leaf facets, and whole-quad ordering is
/// refused STRUCTURALLY — no slot takes a quad-shaped bound. Both arguments are at
/// [`BoundingBoxFilter`](super::BoundingBoxFilter).
///
/// The SPATIAL door here is the widest in the family and the least ready: *this quad contains that
/// point* is a point-in-polygon test, which is a computation rather than a column comparison and
/// belongs to whatever can run one. Nothing about the columns stored here forecloses it.
pub struct QuadFilter<CF> {
  pub(super) top_left: Option<Point2Filter<CF>>,
  pub(super) top_right: Option<Point2Filter<CF>>,
  pub(super) bottom_right: Option<Point2Filter<CF>>,
  pub(super) bottom_left: Option<Point2Filter<CF>>,
}

impl<CF> QuadFilter<CF> {
  /// The empty filter — no corner set, so a column guarded by it is unconstrained.
  #[inline]
  #[must_use]
  pub const fn new() -> Self {
    Self {
      top_left: None,
      top_right: None,
      bottom_right: None,
      bottom_left: None,
    }
  }

  crate::graphql::filter::opt_accessor!(
    top_left: Point2Filter<CF> => with_top_left, set_top_left, maybe_top_left, update_top_left
  );
  crate::graphql::filter::opt_accessor!(
    top_right: Point2Filter<CF> => with_top_right, set_top_right, maybe_top_right, update_top_right
  );
  crate::graphql::filter::opt_accessor!(
    bottom_right: Point2Filter<CF> =>
      with_bottom_right, set_bottom_right, maybe_bottom_right, update_bottom_right
  );
  crate::graphql::filter::opt_accessor!(
    bottom_left: Point2Filter<CF> =>
      with_bottom_left, set_bottom_left, maybe_bottom_left, update_bottom_left
  );
}

impl<CF: crate::GraphqlFilter> QuadFilter<CF> {
  /// True while NO operator slot is set on ANY corner.
  pub fn is_empty(&self) -> bool {
    [
      &self.top_left,
      &self.top_right,
      &self.bottom_right,
      &self.bottom_left,
    ]
    .into_iter()
    .all(|corner| corner.as_ref().is_none_or(crate::GraphqlFilter::is_empty))
  }
}

impl<CF: crate::GraphqlFilter> crate::GraphqlFilter for QuadFilter<CF> {
  #[inline]
  fn is_empty(&self) -> bool {
    Self::is_empty(self)
  }
}

impl<CF> Default for QuadFilter<CF> {
  #[inline]
  fn default() -> Self {
    Self::new()
  }
}

impl<CF: core::fmt::Debug> core::fmt::Debug for QuadFilter<CF> {
  fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    f.debug_struct("QuadFilter")
      .field("top_left", &self.top_left)
      .field("top_right", &self.top_right)
      .field("bottom_right", &self.bottom_right)
      .field("bottom_left", &self.bottom_left)
      .finish()
  }
}

impl<CF: Clone> Clone for QuadFilter<CF> {
  fn clone(&self) -> Self {
    Self {
      top_left: self.top_left.clone(),
      top_right: self.top_right.clone(),
      bottom_right: self.bottom_right.clone(),
      bottom_left: self.bottom_left.clone(),
    }
  }
}

impl<CF: PartialEq> PartialEq for QuadFilter<CF> {
  fn eq(&self, other: &Self) -> bool {
    self.top_left == other.top_left
      && self.top_right == other.top_right
      && self.bottom_right == other.bottom_right
      && self.bottom_left == other.bottom_left
  }
}