Rename Line -> Line2d, Polygon -> Polygon2d
They required clarification now that the sim is 3d
This commit is contained in:
24
src/geom.rs
24
src/geom.rs
@@ -8,22 +8,22 @@ fn real(f: Flt) -> Real {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Default)]
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub struct Line {
|
pub struct Line2d {
|
||||||
from: Vec2,
|
from: Vec2,
|
||||||
to: Vec2,
|
to: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add for Line {
|
impl Add for Line2d {
|
||||||
type Output = Line;
|
type Output = Line2d;
|
||||||
fn add(self, other: Line) -> Line {
|
fn add(self, other: Line2d) -> Line2d {
|
||||||
Line {
|
Line2d {
|
||||||
from: self.from + Vec2::new(0.0, other.y(self.from.x())),
|
from: self.from + Vec2::new(0.0, other.y(self.from.x())),
|
||||||
to: self.to + Vec2::new(0.0, other.y(self.to.x())),
|
to: self.to + Vec2::new(0.0, other.y(self.to.x())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Line {
|
impl Line2d {
|
||||||
pub fn new(from: Vec2, to: Vec2) -> Self {
|
pub fn new(from: Vec2, to: Vec2) -> Self {
|
||||||
Self {
|
Self {
|
||||||
from,
|
from,
|
||||||
@@ -129,8 +129,8 @@ impl Line {
|
|||||||
(real(start_x) + delta_x).into()
|
(real(start_x) + delta_x).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shifted(&self, p: Vec2) -> Line {
|
pub fn shifted(&self, p: Vec2) -> Line2d {
|
||||||
Line {
|
Line2d {
|
||||||
from: self.from + p,
|
from: self.from + p,
|
||||||
to: self.to + p
|
to: self.to + p
|
||||||
}
|
}
|
||||||
@@ -138,22 +138,22 @@ impl Line {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Polygon {
|
pub struct Polygon2d {
|
||||||
points: Vec<Vec2>,
|
points: Vec<Vec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Polygon {
|
impl Polygon2d {
|
||||||
pub fn new(points: Vec<Vec2>) -> Self {
|
pub fn new(points: Vec<Vec2>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
points
|
points
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn segments<'a>(&'a self) -> impl Iterator<Item=Line> + 'a {
|
pub fn segments<'a>(&'a self) -> impl Iterator<Item=Line2d> + 'a {
|
||||||
(0..self.points.len()).into_iter().map(move |i| {
|
(0..self.points.len()).into_iter().map(move |i| {
|
||||||
let from = self.points[i];
|
let from = self.points[i];
|
||||||
let to = *self.points.get(i+1).unwrap_or_else(|| &self.points[0]);
|
let to = *self.points.get(i+1).unwrap_or_else(|| &self.points[0]);
|
||||||
Line { from, to }
|
Line2d { from, to }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
src/mat.rs
10
src/mat.rs
@@ -1,6 +1,6 @@
|
|||||||
use crate::{CellState, consts};
|
use crate::{CellState, consts};
|
||||||
use crate::flt::{Flt, Real};
|
use crate::flt::{Flt, Real};
|
||||||
use crate::geom::{Line, Vec2, Polygon};
|
use crate::geom::{Line2d, Vec2, Polygon2d};
|
||||||
use crate::vec::Vec3;
|
use crate::vec::Vec3;
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use enum_dispatch::enum_dispatch;
|
use enum_dispatch::enum_dispatch;
|
||||||
@@ -54,7 +54,7 @@ impl Material for Static {
|
|||||||
/// M as a function of H
|
/// M as a function of H
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct MHCurve {
|
struct MHCurve {
|
||||||
geom: Polygon,
|
geom: Polygon2d,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MHCurve {
|
impl MHCurve {
|
||||||
@@ -64,7 +64,7 @@ impl MHCurve {
|
|||||||
let full_pts: Vec<Vec2> = points.iter().cloned().chain(points.iter().cloned().map(|p| -p)).collect();
|
let full_pts: Vec<Vec2> = points.iter().cloned().chain(points.iter().cloned().map(|p| -p)).collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
geom: Polygon::new(full_pts)
|
geom: Polygon2d::new(full_pts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Moves (h, m) towards some location in the MH curve where H + M = target_hm.
|
/// Moves (h, m) towards some location in the MH curve where H + M = target_hm.
|
||||||
@@ -93,14 +93,14 @@ impl MHCurve {
|
|||||||
} else {
|
} else {
|
||||||
// need to move the point toward this line
|
// need to move the point toward this line
|
||||||
let h_intercept = line.x(m.into());
|
let h_intercept = line.x(m.into());
|
||||||
break Line::new(Vec2::new(h.into(), m.into()), Vec2::new(h_intercept.into(), m.into()));
|
break Line2d::new(Vec2::new(h.into(), m.into()), Vec2::new(h_intercept.into(), m.into()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
trace!("active segment: {:?}", active_segment);
|
trace!("active segment: {:?}", active_segment);
|
||||||
|
|
||||||
// Find some m(h) on the active_segment such that sum(h) = h + m(h) = target_hm
|
// Find some m(h) on the active_segment such that sum(h) = h + m(h) = target_hm
|
||||||
let sum_h = active_segment + Line::new(Vec2::new(0.0, 0.0), Vec2::new(1.0, 1.0));
|
let sum_h = active_segment + Line2d::new(Vec2::new(0.0, 0.0), Vec2::new(1.0, 1.0));
|
||||||
trace!("sum_h: {:?}", sum_h);
|
trace!("sum_h: {:?}", sum_h);
|
||||||
let new_h = if sum_h.to().y() != sum_h.from().y() {
|
let new_h = if sum_h.to().y() != sum_h.from().y() {
|
||||||
sum_h.move_toward_y_unclamped(h.into(), target_hm.into())
|
sum_h.move_toward_y_unclamped(h.into(), target_hm.into())
|
||||||
|
Reference in New Issue
Block a user