use sophus_autodiff::linalg::SVec;
use crate::{
prelude::*,
renderables::color::Color,
};
#[derive(Clone, Debug)]
pub enum PixelRenderable {
Line(LineSegments2),
Point(PointCloud2),
}
pub fn named_line2(name: impl ToString, segments: Vec<LineSegment2>) -> PixelRenderable {
PixelRenderable::Line(LineSegments2 {
name: name.to_string(),
segments,
})
}
pub fn named_point2(name: impl ToString, points: Vec<Point2>) -> PixelRenderable {
PixelRenderable::Point(PointCloud2 {
name: name.to_string(),
points,
})
}
pub fn make_line2(
name: impl ToString,
arr: &[[impl HasToVec2F32; 2]],
color: &Color,
line_width: f32,
) -> PixelRenderable {
let mut line_segments = LineSegments2 {
name: name.to_string(),
segments: vec![],
};
for tuple in arr {
line_segments.segments.push(LineSegment2 {
p0: tuple[0].to_vec2(),
p1: tuple[1].to_vec2(),
color: *color,
line_width,
});
}
PixelRenderable::Line(line_segments)
}
pub fn make_point2(
name: impl ToString,
arr: &[impl HasToVec2F32],
color: &Color,
point_size: f32,
) -> PixelRenderable {
let mut cloud = PointCloud2 {
name: name.to_string(),
points: vec![],
};
for p in arr {
cloud.points.push(Point2 {
p: p.to_vec2(),
color: *color,
point_size,
});
}
PixelRenderable::Point(cloud)
}
pub trait HasToVec2F32 {
fn to_vec2(&self) -> SVec<f32, 2>;
}
impl HasToVec2F32 for [f32; 2] {
fn to_vec2(&self) -> SVec<f32, 2> {
SVec::<f32, 2>::new(self[0], self[1])
}
}
impl HasToVec2F32 for &[f32; 2] {
fn to_vec2(&self) -> SVec<f32, 2> {
SVec::<f32, 2>::new(self[0], self[1])
}
}
impl HasToVec2F32 for SVec<f32, 2> {
fn to_vec2(&self) -> SVec<f32, 2> {
*self
}
}
#[derive(Clone, Debug)]
pub struct LineSegment2 {
pub p0: SVec<f32, 2>,
pub p1: SVec<f32, 2>,
pub color: Color,
pub line_width: f32,
}
#[derive(Clone, Debug)]
pub struct Point2 {
pub p: SVec<f32, 2>,
pub color: Color,
pub point_size: f32,
}
#[derive(Clone, Debug)]
pub struct LineSegments2 {
pub name: String,
pub segments: Vec<LineSegment2>,
}
#[derive(Clone, Debug)]
pub struct PointCloud2 {
pub name: String,
pub points: Vec<Point2>,
}