use super::{
Colour,
graphics::{
ShapeObject,
SimpleVertex2D,
PrimitiveType,
ElementIndexType,
},
};
#[derive(Clone)]
pub struct Quadrilateral{
pub vertices:[SimpleVertex2D;4],
pub colour:Colour,
}
impl Quadrilateral{
pub fn new(vertices:[SimpleVertex2D;4],colour:Colour)->Quadrilateral{
Self{
vertices,
colour
}
}
}
impl ShapeObject<SimpleVertex2D,ElementIndexType> for Quadrilateral{
type Vertices=[SimpleVertex2D;4];
type Indices=[ElementIndexType;0];
fn vertices(&self)->[SimpleVertex2D;4]{
self.vertices.clone()
}
fn indices(&self)->[ElementIndexType;0]{
[]
}
fn primitive_type(&self)->PrimitiveType{
PrimitiveType::TriangleStrip
}
}
#[derive(Clone)]
pub struct Rectangle{
pub x1:f32,
pub y1:f32,
pub x2:f32,
pub y2:f32,
pub colour:Colour,
}
impl Rectangle{
pub fn new(rect:[f32;4],colour:Colour)->Rectangle{
Self{
x1:rect[0],
y1:rect[1],
x2:rect[0]+rect[2],
y2:rect[1]+rect[3],
colour
}
}
pub const fn raw(rect:[f32;4],colour:Colour)->Rectangle{
Self{
x1:rect[0],
y1:rect[1],
x2:rect[2],
y2:rect[3],
colour
}
}
pub fn triangles(&self)->[SimpleVertex2D;6]{
[
SimpleVertex2D::new([self.x1,self.y1],self.colour),
SimpleVertex2D::new([self.x1,self.y2],self.colour),
SimpleVertex2D::new([self.x2,self.y1],self.colour),
SimpleVertex2D::new([self.x1,self.y2],self.colour),
SimpleVertex2D::new([self.x2,self.y1],self.colour),
SimpleVertex2D::new([self.x2,self.y2],self.colour),
]
}
}
impl ShapeObject<SimpleVertex2D,ElementIndexType> for Rectangle{
type Vertices=[SimpleVertex2D;4];
type Indices=[ElementIndexType;0];
fn vertices(&self)->[SimpleVertex2D;4]{
[
SimpleVertex2D::new([self.x1,self.y1],self.colour),
SimpleVertex2D::new([self.x1,self.y2],self.colour),
SimpleVertex2D::new([self.x2,self.y1],self.colour),
SimpleVertex2D::new([self.x2,self.y2],self.colour),
]
}
fn indices(&self)->[ElementIndexType;0]{
[]
}
fn primitive_type(&self)->PrimitiveType{
PrimitiveType::TriangleStrip
}
}
#[derive(Clone)]
pub struct RectangleBorder{
pub x1:f32,
pub y1:f32,
pub x2:f32,
pub y2:f32,
pub colour:Colour,
}
impl RectangleBorder{
pub const fn raw(rect:[f32;4],colour:Colour)->RectangleBorder{
Self{
x1:rect[0],
y1:rect[1],
x2:rect[2],
y2:rect[3],
colour
}
}
pub fn from_rectangle(rect:Rectangle)->RectangleBorder{
Self{
x1:rect.x1,
y1:rect.y1,
x2:rect.x2,
y2:rect.y2,
colour:rect.colour
}
}
pub fn rectangle_base(rect:Rectangle,colour:Colour)->RectangleBorder{
Self{
x1:rect.x1,
y1:rect.y1,
x2:rect.x2,
y2:rect.y2,
colour
}
}
}
impl ShapeObject<SimpleVertex2D,ElementIndexType> for RectangleBorder{
type Vertices=[SimpleVertex2D;4];
type Indices=[ElementIndexType;0];
fn vertices(&self)->[SimpleVertex2D;4]{
[
SimpleVertex2D::new([self.x1,self.y1],self.colour),
SimpleVertex2D::new([self.x1,self.y2],self.colour),
SimpleVertex2D::new([self.x2,self.y2],self.colour),
SimpleVertex2D::new([self.x2,self.y1],self.colour),
]
}
fn indices(&self)->[ElementIndexType;0]{
[]
}
fn primitive_type(&self)->PrimitiveType{
PrimitiveType::LineLoop
}
}
pub struct Line{
pub x1:f32,
pub y1:f32,
pub x2:f32,
pub y2:f32,
pub colour:Colour,
}
impl Line{
pub const fn new(rect:[f32;4],colour:Colour)->Line{
Self{
x1:rect[0],
y1:rect[1],
x2:rect[2],
y2:rect[3],
colour,
}
}
pub fn position(&self)->[f32;4]{
[
self.x1,
self.y1,
self.x2,
self.y2,
]
}
pub fn set_position(&mut self,[x1,y1,x2,y2]:[f32;4]){
self.x1=x1;
self.y1=y1;
self.x2=x2;
self.y2=y2;
}
pub fn shift_y(&mut self,dy:f32){
self.y1+=dy;
self.y2+=dy;
}
}
impl <'o> ShapeObject<SimpleVertex2D,ElementIndexType> for Line{
type Vertices=[SimpleVertex2D;2];
type Indices=[ElementIndexType;0];
fn vertices(&self)->[SimpleVertex2D;2]{
[
SimpleVertex2D::new([self.x1,self.y1],self.colour),
SimpleVertex2D::new([self.x2,self.y2],self.colour)
]
}
fn indices(&self)->[ElementIndexType;0]{
[]
}
fn primitive_type(&self)->PrimitiveType{
PrimitiveType::Lines
}
}