geometry: store layer in `usize`, not `u64`

This commit is contained in:
Mikolaj Wielgus 2024-06-14 04:58:52 +02:00
parent 1cca9fe6e1
commit 008dcfeca0
17 changed files with 64 additions and 87 deletions

View File

@ -13,63 +13,36 @@ impl Layers {
pub fn new(board: &Board<impl MesadataTrait>) -> Self {
let layer_count = board.layout().drawing().layer_count();
let visible = std::iter::repeat(true)
.take(layer_count.try_into().unwrap() /* FIXME */)
.take(layer_count)
.collect::<Vec<_>>()
.into_boxed_slice();
let colors = std::iter::repeat(egui::Color32::from_rgb(255, 255, 255))
.enumerate()
.map(|(i, color)| {
if matches!(
board
.layout()
.drawing()
.rules()
.layer_layername(i.try_into().unwrap() /* FIXME */),
Some("F.Cu")
) {
if matches!(board.mesadata().layer_layername(i), Some("F.Cu")) {
egui::Color32::from_rgb(255, 52, 52)
} else if matches!(
board
.layout()
.drawing()
.rules()
.layer_layername(i.try_into().unwrap() /* FIXME */),
Some("B.Cu")
) {
} else if matches!(board.mesadata().layer_layername(i), Some("B.Cu")) {
egui::Color32::from_rgb(52, 52, 255)
} else {
color
}
})
.take(layer_count.try_into().unwrap() /* FIXME */)
.take(layer_count)
.collect::<Vec<_>>()
.into_boxed_slice();
let highlight_colors = std::iter::repeat(egui::Color32::from_rgb(255, 255, 255))
.enumerate()
.map(|(i, color)| {
if matches!(
board
.layout()
.drawing()
.rules()
.layer_layername(i.try_into().unwrap() /* FIXME */),
Some("F.Cu")
) {
if matches!(board.mesadata().layer_layername(i), Some("F.Cu")) {
egui::Color32::from_rgb(255, 100, 100)
} else if matches!(
board
.layout()
.drawing()
.rules()
.layer_layername(i.try_into().unwrap() /* FIXME */),
Some("B.Cu")
) {
} else if matches!(board.mesadata().layer_layername(i), Some("B.Cu")) {
egui::Color32::from_rgb(100, 100, 255)
} else {
color
}
})
.take(layer_count.try_into().unwrap() /* FIXME */)
.take(layer_count)
.collect::<Vec<_>>()
.into_boxed_slice();

View File

@ -26,7 +26,7 @@ use topola::{
pub struct Overlay {
ratsnest: Ratsnest,
selection: Selection,
active_layer: u64,
active_layer: usize,
}
impl Overlay {

View File

@ -179,6 +179,10 @@ impl<M: MesadataTrait> Board<M> {
}
}
pub fn mesadata(&self) -> &M {
self.layout.drawing().rules()
}
pub fn layout(&self) -> &Layout<M> {
&self.layout
}

View File

@ -1,9 +1,9 @@
use crate::drawing::rules::RulesTrait;
pub trait MesadataTrait: RulesTrait {
fn bename_layer(&mut self, layer: u64, layername: String);
fn layer_layername(&self, layer: u64) -> Option<&str>;
fn layername_layer(&self, layername: &str) -> Option<u64>;
fn bename_layer(&mut self, layer: usize, layername: String);
fn layer_layername(&self, layer: usize) -> Option<&str>;
fn layername_layer(&self, layername: &str) -> Option<usize>;
fn bename_net(&mut self, net: usize, netname: String);
fn net_netname(&self, net: usize) -> Option<&str>;

View File

@ -75,7 +75,7 @@ impl BendWeightTrait<PrimitiveWeight> for BendWeight {}
pub struct FixedBendWeight {
pub width: f64,
pub offset: f64,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}
@ -104,7 +104,7 @@ impl GetWidth for FixedBendWeight {
pub struct LooseBendWeight {
pub width: f64,
pub offset: f64,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}

View File

@ -76,7 +76,7 @@ impl DotWeightTrait<PrimitiveWeight> for DotWeight {}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedDotWeight {
pub circle: Circle,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}
@ -104,7 +104,7 @@ impl GetWidth for FixedDotWeight {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LooseDotWeight {
pub circle: Circle,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}

View File

@ -686,7 +686,7 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
})
}
pub fn layer_primitive_nodes(&self, layer: u64) -> impl Iterator<Item = PrimitiveIndex> + '_ {
pub fn layer_primitive_nodes(&self, layer: usize) -> impl Iterator<Item = PrimitiveIndex> + '_ {
self.geometry_with_rtree
.rtree()
.locate_in_envelope_intersecting(&AABB::from_corners(
@ -889,7 +889,7 @@ impl<CW: Copy, R: RulesTrait> Drawing<CW, R> {
Loose::new(index, self)
}
pub fn layer_count(&self) -> u64 {
pub fn layer_count(&self) -> usize {
self.geometry_with_rtree.layer_count()
}

View File

@ -22,7 +22,7 @@ pub trait Retag<PrimitiveIndex> {
#[enum_dispatch]
pub trait GetLayer {
fn layer(&self) -> u64;
fn layer(&self) -> usize;
}
#[enum_dispatch]
@ -47,7 +47,7 @@ macro_rules! impl_weight {
}
impl<'a> GetLayer for $weight_struct {
fn layer(&self) -> u64 {
fn layer(&self) -> usize {
self.layer
}
}

View File

@ -125,7 +125,7 @@ macro_rules! impl_primitive {
}
impl<'a, CW: Copy, R: RulesTrait> GetLayer for $primitive_struct<'a, CW, R> {
fn layer(&self) -> u64 {
fn layer(&self) -> usize {
self.weight().layer()
}
}

View File

@ -80,7 +80,7 @@ impl SegWeightTrait<PrimitiveWeight> for SegWeight {}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedSegWeight {
pub width: f64,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}
@ -96,7 +96,7 @@ impl GetWidth for FixedSegWeight {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LoneLooseSegWeight {
pub width: f64,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}
@ -112,7 +112,7 @@ impl GetWidth for LoneLooseSegWeight {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SeqLooseSegWeight {
pub width: f64,
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}

View File

@ -193,7 +193,7 @@ impl DsnDesign {
(pin.x as f64, pin.y as f64).into(),
pin.rotate.unwrap_or(0.0) as f64,
circle.diameter as f64 / 2.0,
layer as u64,
layer as usize,
*net,
Some(pinname.clone()),
)
@ -215,7 +215,7 @@ impl DsnDesign {
rect.y1 as f64,
rect.x2 as f64,
rect.y2 as f64,
layer as u64,
layer as usize,
*net,
Some(pinname.clone()),
)
@ -235,7 +235,7 @@ impl DsnDesign {
pin.rotate.unwrap_or(0.0) as f64,
&path.coord_vec,
path.width as f64,
layer as u64,
layer as usize,
*net,
Some(pinname.clone()),
)
@ -255,7 +255,7 @@ impl DsnDesign {
pin.rotate.unwrap_or(0.0) as f64,
&polygon.coord_vec,
polygon.width as f64,
layer as u64,
layer as usize,
*net,
Some(pinname.clone()),
)
@ -299,7 +299,7 @@ impl DsnDesign {
(0.0, 0.0).into(),
0.0,
circle.diameter as f64 / 2.0,
layer as u64,
layer as usize,
net,
None,
)
@ -321,7 +321,7 @@ impl DsnDesign {
rect.y1 as f64,
rect.x2 as f64,
rect.y2 as f64,
layer as u64,
layer as usize,
net,
None,
)
@ -341,7 +341,7 @@ impl DsnDesign {
0.0,
&path.coord_vec,
path.width as f64,
layer as u64,
layer as usize,
net,
None,
)
@ -361,7 +361,7 @@ impl DsnDesign {
0.0,
&polygon.coord_vec,
polygon.width as f64,
layer as u64,
layer as usize,
net,
None,
)
@ -392,7 +392,7 @@ impl DsnDesign {
0.0,
&wire.path.coord_vec,
wire.path.width as f64,
layer as u64,
layer,
net,
None,
);
@ -448,7 +448,7 @@ impl DsnDesign {
pin_pos: Point,
pin_rot: f64,
r: f64,
layer: u64,
layer: usize,
net: usize,
maybe_pin: Option<String>,
) {
@ -477,7 +477,7 @@ impl DsnDesign {
y1: f64,
x2: f64,
y2: f64,
layer: u64,
layer: usize,
net: usize,
maybe_pin: Option<String>,
) {
@ -586,7 +586,7 @@ impl DsnDesign {
pin_rot: f64,
coords: &Vec<structure::Point>,
width: f64,
layer: u64,
layer: usize,
net: usize,
maybe_pin: Option<String>,
) {
@ -663,7 +663,7 @@ impl DsnDesign {
pin_rot: f64,
coords: &Vec<structure::Point>,
width: f64,
layer: u64,
layer: usize,
net: usize,
maybe_pin: Option<String>,
) {

View File

@ -30,7 +30,7 @@ pub struct DsnMesadata {
class_rules: HashMap<String, DsnRule>,
// layername <-> layer for Layout
pub layer_layername: BiHashMap<u64, String>,
pub layer_layername: BiHashMap<usize, String>,
// netname <-> net for Layout
pub net_netname: BiHashMap<usize, String>,
@ -45,7 +45,7 @@ impl DsnMesadata {
pcb.structure
.layer_vec
.iter()
.map(|layer| (layer.property.index as u64, layer.name.clone())),
.map(|layer| (layer.property.index, layer.name.clone())),
);
// keeping this as a separate iter pass because it might be moved into a different struct later?
@ -122,15 +122,15 @@ impl RulesTrait for DsnMesadata {
}
impl MesadataTrait for DsnMesadata {
fn bename_layer(&mut self, layer: u64, layername: String) {
fn bename_layer(&mut self, layer: usize, layername: String) {
self.layer_layername.insert(layer, layername);
}
fn layer_layername(&self, layer: u64) -> Option<&str> {
fn layer_layername(&self, layer: usize) -> Option<&str> {
self.layer_layername.get_by_left(&layer).map(|s| s.as_str())
}
fn layername_layer(&self, layername: &str) -> Option<u64> {
fn layername_layer(&self, layername: &str) -> Option<usize> {
self.layer_layername.get_by_right(layername).copied()
}

View File

@ -9,14 +9,14 @@ use crate::{
#[enum_dispatch]
pub trait PrimitiveShapeTrait: ShapeTrait {
fn priority(&self) -> u64;
fn priority(&self) -> usize;
fn inflate(&self, margin: f64) -> PrimitiveShape;
fn intersects(&self, other: &PrimitiveShape) -> bool;
fn envelope(&self, margin: f64) -> AABB<[f64; 2]>;
fn width(&self) -> f64;
fn length(&self) -> f64;
fn envelope_3d(&self, margin: f64, layer: u64) -> AABB<[f64; 3]> {
fn envelope_3d(&self, margin: f64, layer: usize) -> AABB<[f64; 3]> {
let envelope = self.envelope(margin);
AABB::from_corners(
[envelope.lower()[0], envelope.lower()[1], layer as f64],
@ -24,7 +24,7 @@ pub trait PrimitiveShapeTrait: ShapeTrait {
)
}
fn full_height_envelope_3d(&self, margin: f64, layer_count: u64) -> AABB<[f64; 3]> {
fn full_height_envelope_3d(&self, margin: f64, layer_count: usize) -> AABB<[f64; 3]> {
let envelope = self.envelope(margin);
AABB::from_corners(
[envelope.lower()[0], envelope.lower()[1], 0.0],
@ -62,7 +62,7 @@ impl ShapeTrait for DotShape {
}
impl PrimitiveShapeTrait for DotShape {
fn priority(&self) -> u64 {
fn priority(&self) -> usize {
3
}
@ -162,7 +162,7 @@ impl ShapeTrait for SegShape {
}
impl PrimitiveShapeTrait for SegShape {
fn priority(&self) -> u64 {
fn priority(&self) -> usize {
2
}
@ -279,7 +279,7 @@ impl ShapeTrait for BendShape {
}
impl PrimitiveShapeTrait for BendShape {
fn priority(&self) -> u64 {
fn priority(&self) -> usize {
1
}

View File

@ -50,7 +50,7 @@ pub struct GeometryWithRtree<
> {
geometry: Geometry<PW, DW, SW, BW, CW, PI, DI, SI, BI>,
rtree: RTree<BboxedIndex<GenericNode<PI, GenericIndex<CW>>>>,
layer_count: u64,
layer_count: usize,
weight_marker: PhantomData<PW>,
dot_weight_marker: PhantomData<DW>,
seg_weight_marker: PhantomData<SW>,
@ -75,7 +75,7 @@ impl<
BI: GetNodeIndex + Into<PI> + Copy,
> GeometryWithRtree<PW, DW, SW, BW, CW, PI, DI, SI, BI>
{
pub fn new(layer_count: u64) -> Self {
pub fn new(layer_count: usize) -> Self {
Self {
geometry: Geometry::<PW, DW, SW, BW, CW, PI, DI, SI, BI>::new(),
rtree: RTree::new(),
@ -335,7 +335,7 @@ impl<
}
}
fn layer(&self, primitive: PI) -> u64 {
fn layer(&self, primitive: PI) -> usize {
if let Ok(dot) = <PI as TryInto<DI>>::try_into(primitive) {
self.geometry.dot_weight(dot).layer()
} else if let Ok(seg) = <PI as TryInto<SI>>::try_into(primitive) {
@ -347,7 +347,7 @@ impl<
}
}
pub fn layer_count(&self) -> u64 {
pub fn layer_count(&self) -> usize {
self.layer_count
}

View File

@ -240,7 +240,7 @@ impl<R: RulesTrait> Layout<R> {
pub fn layer_zone_nodes(
&self,
layer: u64,
layer: usize,
) -> impl Iterator<Item = GenericIndex<ZoneWeight>> + '_ {
self.drawing
.rtree()

View File

@ -46,8 +46,8 @@ impl<'a, R: RulesTrait> MakePrimitiveShape for Via<'a, R> {
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct ViaWeight {
pub from_layer: u64,
pub to_layer: u64,
pub from_layer: usize,
pub to_layer: usize,
pub circle: Circle,
pub maybe_net: Option<usize>,
}

View File

@ -49,7 +49,7 @@ impl<'a, R: RulesTrait> Zone<'a, R> {
}
impl<'a, R: RulesTrait> GetLayer for Zone<'a, R> {
fn layer(&self) -> u64 {
fn layer(&self) -> usize {
if let CompoundWeight::Zone(weight) =
self.layout.drawing().compound_weight(self.index.into())
{
@ -136,12 +136,12 @@ impl From<GenericIndex<ZoneWeight>> for GenericIndex<CompoundWeight> {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SolidZoneWeight {
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}
impl GetLayer for SolidZoneWeight {
fn layer(&self) -> u64 {
fn layer(&self) -> usize {
self.layer
}
}
@ -160,12 +160,12 @@ impl From<GenericIndex<SolidZoneWeight>> for GenericIndex<CompoundWeight> {
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct PourZoneWeight {
pub layer: u64,
pub layer: usize,
pub maybe_net: Option<usize>,
}
impl<'a> GetLayer for PourZoneWeight {
fn layer(&self) -> u64 {
fn layer(&self) -> usize {
self.layer
}
}