layout: encapsulate weight geometrical datas in new "geodata" structs

This commit is contained in:
Mikolaj Wielgus 2024-02-26 23:39:10 +00:00
parent 7f69ffddf9
commit a3ba8c9ba9
7 changed files with 83 additions and 51 deletions

View File

@ -5,13 +5,13 @@ use thiserror::Error;
use crate::{ use crate::{
geometry::GetWidth, geometry::GetWidth,
layout::{ layout::{
bend::{BendIndex, LooseBendWeight}, bend::{BendGeodata, BendIndex, LooseBendWeight},
dot::{DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight}, dot::{DotGeodata, DotIndex, FixedDotIndex, LooseDotIndex, LooseDotWeight},
graph::{GetBandIndex, MakePrimitive}, graph::{GetBandIndex, MakePrimitive},
guide::{Guide, Head, HeadTrait, SegbendHead}, guide::{Guide, Head, HeadTrait, SegbendHead},
primitive::GetOtherJoint, primitive::GetOtherJoint,
rules::RulesTrait, rules::RulesTrait,
seg::{LoneLooseSegWeight, SeqLooseSegWeight}, seg::{LoneLooseSegWeight, SegGeodata, SeqLooseSegWeight},
Infringement, Layout, LayoutException, Infringement, Layout, LayoutException,
}, },
math::{Circle, NoTangents}, math::{Circle, NoTangents},
@ -67,7 +67,9 @@ impl<'a, R: RulesTrait> Draw<'a, R> {
into.into(), into.into(),
LoneLooseSegWeight { LoneLooseSegWeight {
band: head.band(), band: head.band(),
width: self.layout.band(head.band()).width(), geodata: SegGeodata {
width: self.layout.band(head.band()).width(),
},
}, },
) )
.map_err(|err| DrawException::CannotFinishIn(into, err.into()))?; .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?;
@ -79,7 +81,9 @@ impl<'a, R: RulesTrait> Draw<'a, R> {
dot, dot,
SeqLooseSegWeight { SeqLooseSegWeight {
band: head.band(), band: head.band(),
width: self.layout.band(head.band()).width(), geodata: SegGeodata {
width: self.layout.band(head.band()).width(),
},
}, },
) )
.map_err(|err| DrawException::CannotFinishIn(into, err.into()))?; .map_err(|err| DrawException::CannotFinishIn(into, err.into()))?;
@ -220,19 +224,20 @@ impl<'a, R: RulesTrait> Draw<'a, R> {
around, around,
LooseDotWeight { LooseDotWeight {
band: head.band(), band: head.band(),
circle: Circle { geodata: DotGeodata {
pos: to, circle: Circle {
r: width / 2.0, pos: to,
r: width / 2.0,
},
}, },
}, },
SeqLooseSegWeight { SeqLooseSegWeight {
band: head.band(), band: head.band(),
width, geodata: SegGeodata { width },
}, },
LooseBendWeight { LooseBendWeight {
band: head.band(), band: head.band(),
width, geodata: BendGeodata { width, offset },
offset,
}, },
cw, cw,
)?; )?;

View File

@ -1,7 +1,11 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::{ use crate::{
layout::{dot::FixedDotWeight, seg::FixedSegWeight, Layout}, layout::{
dot::{DotGeodata, FixedDotWeight},
seg::{FixedSegWeight, SegGeodata},
Layout,
},
math::Circle, math::Circle,
}; };
@ -80,7 +84,7 @@ impl DsnDesign {
layout layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
continent: continent100, continent: continent100,
circle, geodata: DotGeodata { circle },
}) })
.unwrap(); .unwrap();
} }
@ -115,7 +119,10 @@ impl DsnDesign {
}; };
layout layout
.add_fixed_dot(FixedDotWeight { continent, circle }) .add_fixed_dot(FixedDotWeight {
continent,
geodata: DotGeodata { circle },
})
.unwrap() .unwrap()
}) })
.collect(); .collect();
@ -128,13 +135,15 @@ impl DsnDesign {
let mut prev_index = layout let mut prev_index = layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
continent, continent,
circle: Circle { geodata: DotGeodata {
pos: ( circle: Circle {
wire.path.coords[0].x as f64 / 100.0, pos: (
-wire.path.coords[0].y as f64 / 100.0, wire.path.coords[0].x as f64 / 100.0,
) -wire.path.coords[0].y as f64 / 100.0,
.into(), )
r: wire.path.width as f64 / 100.0, .into(),
r: wire.path.width as f64 / 100.0,
},
}, },
}) })
.unwrap(); .unwrap();
@ -144,9 +153,11 @@ impl DsnDesign {
let index = layout let index = layout
.add_fixed_dot(FixedDotWeight { .add_fixed_dot(FixedDotWeight {
continent, continent,
circle: Circle { geodata: DotGeodata {
pos: (coord.x as f64 / 100.0, -coord.y as f64 / 100.0).into(), circle: Circle {
r: wire.path.width as f64 / 100.0, pos: (coord.x as f64 / 100.0, -coord.y as f64 / 100.0).into(),
r: wire.path.width as f64 / 100.0,
},
}, },
}) })
.unwrap(); .unwrap();
@ -158,7 +169,9 @@ impl DsnDesign {
index, index,
FixedSegWeight { FixedSegWeight {
continent, continent,
width: wire.path.width as f64 / 100.0, geodata: SegGeodata {
width: wire.path.width as f64 / 100.0,
},
}, },
) )
.unwrap(); .unwrap();

View File

@ -45,6 +45,12 @@ impl TryFrom<GeometryIndex> for BendIndex {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BendGeodata {
pub width: f64,
pub offset: f64,
}
#[enum_dispatch(GetOffset, SetOffset, GetWidth)] #[enum_dispatch(GetOffset, SetOffset, GetWidth)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum BendWeight { pub enum BendWeight {
@ -78,8 +84,7 @@ impl BendWeightTrait<GeometryWeight> for BendWeight {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedBendWeight { pub struct FixedBendWeight {
pub continent: ContinentIndex, pub continent: ContinentIndex,
pub width: f64, pub geodata: BendGeodata,
pub offset: f64,
} }
impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex); impl_fixed_weight!(FixedBendWeight, FixedBend, FixedBendIndex);
@ -87,44 +92,43 @@ impl BendWeightTrait<GeometryWeight> for FixedBendWeight {}
impl GetOffset for FixedBendWeight { impl GetOffset for FixedBendWeight {
fn offset(&self) -> f64 { fn offset(&self) -> f64 {
self.offset self.geodata.offset
} }
} }
impl SetOffset for FixedBendWeight { impl SetOffset for FixedBendWeight {
fn set_offset(&mut self, offset: f64) { fn set_offset(&mut self, offset: f64) {
self.offset = offset self.geodata.offset = offset
} }
} }
impl GetWidth for FixedBendWeight { impl GetWidth for FixedBendWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.width self.geodata.width
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct LooseBendWeight { pub struct LooseBendWeight {
pub band: BandIndex, pub band: BandIndex,
pub width: f64, pub geodata: BendGeodata,
pub offset: f64,
} }
impl GetOffset for LooseBendWeight { impl GetOffset for LooseBendWeight {
fn offset(&self) -> f64 { fn offset(&self) -> f64 {
self.offset self.geodata.offset
} }
} }
impl SetOffset for LooseBendWeight { impl SetOffset for LooseBendWeight {
fn set_offset(&mut self, offset: f64) { fn set_offset(&mut self, offset: f64) {
self.offset = offset self.geodata.offset = offset
} }
} }
impl GetWidth for LooseBendWeight { impl GetWidth for LooseBendWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.width self.geodata.width
} }
} }

View File

@ -47,6 +47,11 @@ impl TryFrom<GeometryIndex> for DotIndex {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct DotGeodata {
pub circle: Circle,
}
#[enum_dispatch(GetPos, SetPos, GetWidth)] #[enum_dispatch(GetPos, SetPos, GetWidth)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum DotWeight { pub enum DotWeight {
@ -80,7 +85,7 @@ impl DotWeightTrait<GeometryWeight> for DotWeight {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedDotWeight { pub struct FixedDotWeight {
pub continent: ContinentIndex, pub continent: ContinentIndex,
pub circle: Circle, pub geodata: DotGeodata,
} }
impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex); impl_fixed_weight!(FixedDotWeight, FixedDot, FixedDotIndex);
@ -88,26 +93,26 @@ impl DotWeightTrait<GeometryWeight> for FixedDotWeight {}
impl GetPos for FixedDotWeight { impl GetPos for FixedDotWeight {
fn pos(&self) -> Point { fn pos(&self) -> Point {
self.circle.pos self.geodata.circle.pos
} }
} }
impl SetPos for FixedDotWeight { impl SetPos for FixedDotWeight {
fn set_pos(&mut self, pos: Point) { fn set_pos(&mut self, pos: Point) {
self.circle.pos = pos self.geodata.circle.pos = pos
} }
} }
impl GetWidth for FixedDotWeight { impl GetWidth for FixedDotWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.circle.r * 2.0 self.geodata.circle.r * 2.0
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct LooseDotWeight { pub struct LooseDotWeight {
pub band: BandIndex, pub band: BandIndex,
pub circle: Circle, pub geodata: DotGeodata,
} }
impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex); impl_loose_weight!(LooseDotWeight, LooseDot, LooseDotIndex);
@ -115,18 +120,18 @@ impl DotWeightTrait<GeometryWeight> for LooseDotWeight {}
impl GetPos for LooseDotWeight { impl GetPos for LooseDotWeight {
fn pos(&self) -> Point { fn pos(&self) -> Point {
self.circle.pos self.geodata.circle.pos
} }
} }
impl SetPos for LooseDotWeight { impl SetPos for LooseDotWeight {
fn set_pos(&mut self, pos: Point) { fn set_pos(&mut self, pos: Point) {
self.circle.pos = pos self.geodata.circle.pos = pos
} }
} }
impl GetWidth for LooseDotWeight { impl GetWidth for LooseDotWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.circle.r * 2.0 self.geodata.circle.r * 2.0
} }
} }

View File

@ -85,7 +85,7 @@ impl<'a, R: RulesTrait> Guide<'a, R> {
) -> Result<Line, NoTangents> { ) -> Result<Line, NoTangents> {
let from_circle = self.head_circle(head, width); let from_circle = self.head_circle(head, width);
let to_circle = Circle { let to_circle = Circle {
pos: self.layout.primitive(into).weight().circle.pos, pos: self.layout.primitive(into).weight().geodata.circle.pos,
r: 0.0, r: 0.0,
}; };

View File

@ -474,7 +474,7 @@ impl<'a, R: RulesTrait> GetLimbs for LooseBend<'a, R> {}
impl<'a, R: RulesTrait> GetOffset for LooseBend<'a, R> { impl<'a, R: RulesTrait> GetOffset for LooseBend<'a, R> {
fn offset(&self) -> f64 { fn offset(&self) -> f64 {
self.weight().offset self.weight().offset()
} }
} }

View File

@ -48,6 +48,11 @@ impl TryFrom<GeometryIndex> for SegIndex {
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SegGeodata {
pub width: f64,
}
#[enum_dispatch(GetWidth)] #[enum_dispatch(GetWidth)]
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub enum SegWeight { pub enum SegWeight {
@ -84,7 +89,7 @@ impl SegWeightTrait<GeometryWeight> for SegWeight {}
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct FixedSegWeight { pub struct FixedSegWeight {
pub continent: ContinentIndex, pub continent: ContinentIndex,
pub width: f64, pub geodata: SegGeodata,
} }
impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex); impl_fixed_weight!(FixedSegWeight, FixedSeg, FixedSegIndex);
@ -92,14 +97,14 @@ impl SegWeightTrait<GeometryWeight> for FixedSegWeight {}
impl GetWidth for FixedSegWeight { impl GetWidth for FixedSegWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.width self.geodata.width
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct LoneLooseSegWeight { pub struct LoneLooseSegWeight {
pub band: BandIndex, pub band: BandIndex,
pub width: f64, pub geodata: SegGeodata,
} }
impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex); impl_loose_weight!(LoneLooseSegWeight, LoneLooseSeg, LoneLooseSegIndex);
@ -107,14 +112,14 @@ impl SegWeightTrait<GeometryWeight> for LoneLooseSegWeight {}
impl GetWidth for LoneLooseSegWeight { impl GetWidth for LoneLooseSegWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.width self.geodata.width
} }
} }
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq)]
pub struct SeqLooseSegWeight { pub struct SeqLooseSegWeight {
pub band: BandIndex, pub band: BandIndex,
pub width: f64, pub geodata: SegGeodata,
} }
impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex); impl_loose_weight!(SeqLooseSegWeight, SeqLooseSeg, SeqLooseSegIndex);
@ -122,6 +127,6 @@ impl SegWeightTrait<GeometryWeight> for SeqLooseSegWeight {}
impl GetWidth for SeqLooseSegWeight { impl GetWidth for SeqLooseSegWeight {
fn width(&self) -> f64 { fn width(&self) -> f64 {
self.width self.geodata.width
} }
} }