1 module polyplex.core.render.shapes;
2 import polyplex.math;
3 import std.stdio;
4 
5 public abstract class Shape {
6 	public abstract float[][] GetVertices();
7 }
8 
9 class Square : Shape {
10 	private float[][] verts;
11 	public @property float[][] Vertices() { return verts; }
12 	
13 	this(Rectangle rect) {
14 		Vector2[] vecs = new Vector2[4];
15 		vecs[0] = Vector2(rect.X, rect.Height);
16 		vecs[1] = Vector2(rect.X, rect.Y);
17 		vecs[2] = Vector2(rect.Width, rect.Y);
18 		vecs[3] = Vector2(rect.Width, rect.Height);
19 		Polygon pg = new Polygon(vecs);
20 		writeln(this.verts);
21 		this.verts = pg.Vertices;
22 	}
23 
24 	public override float[][] GetVertices() {
25 		return this.verts;
26 	}
27 }
28 
29 class FSquare : Shape {
30 	private float[][] verts;
31 	public @property float[][] Vertices() { return verts; }
32 	
33 	this(Vector4 rect) {
34 		Vector2[] vecs = new Vector2[4];
35 		vecs[0] = Vector2(rect.X, rect.W);
36 		vecs[1] = Vector2(rect.X, rect.Y);
37 		vecs[2] = Vector2(rect.Z, rect.W);
38 		vecs[3] = Vector2(rect.Z, rect.Y);
39 		Polygon pg = new Polygon(vecs);
40 		this.verts = pg.Vertices;
41 	}
42 
43 	public override float[][] GetVertices() {
44 		return this.verts;
45 	}
46 }
47 
48 class Polygon : Shape {
49 	private float[][] verts;
50 	public @property float[][] Vertices() { return verts; }
51 	this(Vector2[] points) {
52 		verts.length = points.length;
53 		for (int i = 0; i < points.length; i++) {
54 			verts[i].length = 2;
55 			verts[i][0] = points[i].X;
56 			verts[i][1] = points[i].Y;
57 		}
58 	}
59 
60 	public override float[][] GetVertices() {
61 		return Vertices;
62 	}
63 }