use fj_math::Point;
use pretty_assertions::assert_eq;
use crate::stores::{Handle, Stores};
use super::{Curve, Surface};
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct Vertex {
position: Point<1>,
curve: Handle<Curve>,
surface_form: SurfaceVertex,
}
impl Vertex {
pub fn new(
position: impl Into<Point<1>>,
curve: Handle<Curve>,
surface_form: SurfaceVertex,
) -> Self {
let position = position.into();
assert_eq!(
curve.surface().id(),
surface_form.surface().id(),
"Surface form of vertex must be defined on same surface as curve",
);
Self {
position,
curve,
surface_form,
}
}
pub fn position(&self) -> Point<1> {
self.position
}
pub fn curve(&self) -> &Handle<Curve> {
&self.curve
}
pub fn surface_form(&self) -> &SurfaceVertex {
&self.surface_form
}
pub fn global_form(&self) -> &Handle<GlobalVertex> {
self.surface_form.global_form()
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct SurfaceVertex {
position: Point<2>,
surface: Handle<Surface>,
global_form: Handle<GlobalVertex>,
}
impl SurfaceVertex {
pub fn new(
position: impl Into<Point<2>>,
surface: Handle<Surface>,
global_form: Handle<GlobalVertex>,
) -> Self {
let position = position.into();
Self {
position,
surface,
global_form,
}
}
pub fn position(&self) -> Point<2> {
self.position
}
pub fn surface(&self) -> &Handle<Surface> {
&self.surface
}
pub fn global_form(&self) -> &Handle<GlobalVertex> {
&self.global_form
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub struct GlobalVertex {
position: Point<3>,
}
impl GlobalVertex {
pub fn from_position(
position: impl Into<Point<3>>,
stores: &Stores,
) -> Handle<Self> {
let position = position.into();
stores.global_vertices.insert(Self { position })
}
pub fn position(&self) -> Point<3> {
self.position
}
}