Skip to main content

klayout_core/
query.rs

1//! Iteration and spatial-query traits. The core ships naive linear-scan
2//! impls on `Library`/`Cell`; `klayout-geom` will layer R-trees underneath
3//! without changing this surface.
4
5use crate::cell::{Cell, CellId};
6use crate::coord::{Bbox, Trans};
7use crate::instance::Instance;
8use crate::layer::LayerIndex;
9use crate::shape::Shape;
10
11pub struct ShapeRef<'a> {
12    pub cell: CellId,
13    pub layer: LayerIndex,
14    pub index: usize,
15    pub shape: &'a Shape,
16}
17
18pub struct InstanceRef<'a> {
19    pub parent: CellId,
20    pub index: usize,
21    pub instance: &'a Instance,
22}
23
24pub trait LayoutQuery {
25    fn shapes_in<'a>(
26        &'a self,
27        cell: CellId,
28        layer: LayerIndex,
29        bbox: Bbox,
30    ) -> Box<dyn Iterator<Item = ShapeRef<'a>> + 'a>;
31
32    fn instances_in<'a>(
33        &'a self,
34        cell: CellId,
35        bbox: Bbox,
36    ) -> Box<dyn Iterator<Item = InstanceRef<'a>> + 'a>;
37}
38
39pub trait HierarchyVisitor {
40    fn enter_cell(&mut self, _cell: &Cell, _trans: Trans) {}
41    fn exit_cell(&mut self, _cell: &Cell, _trans: Trans) {}
42    fn visit_shape(&mut self, _layer: LayerIndex, _shape: &Shape, _trans: Trans) {}
43    fn visit_instance(&mut self, _instance: &Instance, _trans: Trans) {}
44}
45
46pub trait Visit {
47    fn walk<V: HierarchyVisitor>(&self, root: CellId, visitor: &mut V);
48}