use crate::coordinates;
use coordinates::pixel::Pixel;
use ndarray_cg::{ F32x2, F32x3x3, IntoVector as _, Vector };
pub fn from_iter< I, C, F >( iter : I, mesh_producer : F, transform : F32x3x3 ) -> Vec< f32 >
where
I : Iterator< Item = C >,
C : Into< Pixel >,
F : Fn() -> Vec< f32 >,
{
let mesh = mesh_producer(); let mut points = vec![];
for coord in iter
{
let Pixel { data : [ x, y ] } = coord.into();
let y = -y;
for point in mesh.chunks( 2 )
{
let pos = transform * Vector( [ point[ 0 ], point[ 1 ], 1.0 ] );
points.push( x + pos.x() );
points.push( y + pos.y() );
}
}
points
}
pub fn hexagon_triangles() -> Vec< f32 >
{
let points = hexagon_vertices();
let mut positions = vec![];
let first = points.first().expect( "hexagon_vertices should always return 6 points" );
for w in points[ 1.. ].windows( 2 )
{
let point1 = w[ 0 ];
let point2 = w[ 1 ];
positions.push( first[ 0 ] );
positions.push( first[ 1 ] );
positions.push( point1[ 0 ] );
positions.push( point1[ 1 ] );
positions.push( point2[ 0 ] );
positions.push( point2[ 1 ] );
}
positions
}
pub fn hexagon_triangles_with_tranform(transform: F32x3x3) -> Vec<f32> {
let mut points = hexagon_vertices();
for point in &mut points {
let p = transform * Vector([point[0], point[1], 1.0]);
point.0 = [p.x(), p.y()];
}
let mut positions = vec![];
let first = points.first().expect("hexagon_vertices should always return 6 points");
for w in points[1..].windows(2) {
let point1 = w[0];
let point2 = w[1];
positions.push(first[0]);
positions.push(first[1]);
positions.push(point1[0]);
positions.push(point1[1]);
positions.push(point2[0]);
positions.push(point2[1]);
}
positions
}
pub fn hexagon_lines() -> Vec<f32> {
let points = hexagon_vertices();
let mut positions = vec![];
for w in points.windows(2) {
let point1 = w[0];
let point2 = w[1];
positions.push(point1[0]);
positions.push(point1[1]);
positions.push(point2[0]);
positions.push(point2[1]);
}
positions.push(points.last().expect("hexagon_vertices should always return 6 points")[0]);
positions.push(points.last().expect("hexagon_vertices should always return 6 points")[1]);
positions.push(points.first().expect("hexagon_vertices should always return 6 points")[0]);
positions.push(points.first().expect("hexagon_vertices should always return 6 points")[1]);
positions
}
pub fn hexagon_vertices() -> [F32x2; 6] {
let mut points: [F32x2; 6] = Default::default();
for i in 0..6 {
let angle = ((60 * i) as f32).to_radians();
points[i] = (angle.cos(), angle.sin()).into_vector();
}
points
}