using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Psychlops{ public interface Shape : Figure { } public static class ShapeExtention { /* public static void draw(this Shape drawee) { drawee.draw(Color.white); } */ } public class Line : Shape { public Point begin, end; public Line(Point v1, Point v2) { begin = v1; end = v2; } public Figure shift(Point p) { begin += p; end += p; return this; } public Figure centering(Point p) { double h = width, v = height; begin.x = p.x - h / 2.0; begin.y = p.y - v / 2.0; end.x = begin.x + h; end.y = begin.y + v; return this; } public void draw(Color c) { Main.drawable.line(this, c); } public void draw() { Main.drawable.line(this, Color.white); } public double width { get { return Math.abs(begin.x - end.x); } } public double height { get { return Math.abs(begin.y - end.y); } } public static implicit operator System.Windows.Shapes.Line(Line d) { var tmp = new System.Windows.Shapes.Line(); tmp.X1 = d.begin.x; tmp.Y1 = d.begin.y; tmp.X2 = d.end.x; tmp.Y2 = d.end.y; return tmp; } } public class Rectangle : Shape { public Point v1, v2; public Rectangle() { set(0,0); } public Rectangle(double wid, double hei) { set(wid, hei); } public Rectangle set(double wid, double hei) { v1.set(0, 0, 0); v2.set(wid, hei, 0); return this; } public Figure shift(Point p) { v1 += p; v2 += p; return this; } public Figure centering(Point p) { double h = width, v = height; v1.x = p.x - h / 2.0; v1.y = p.y - v / 2.0; v2.x = v1.x + h; v2.y = v1.y + v; return this; } public void draw(Color c) { Main.drawable.rect(this, c); } public void draw() { Main.drawable.rect(this, Color.white); } public double left { get { return v1.x; } } public double top { get { return v1.y; } } public double right { get { return v2.x; } } public double bottom { get { return v2.y; } } public double width { get { return Math.abs(v1.x - v2.x); } } public double height { get { return Math.abs(v1.y - v2.y); } } public static implicit operator System.Windows.Rect(Rectangle d) { return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y); } } public class Ellipse : Shape { public Point datum; public double xdiameter, ydiameter; public Figure shift(Point p) { datum += p; return this; } public Figure centering(Point p) { datum = p; return this; } public void draw(Color c) { Main.drawable.ellipse(this, c); } public void draw() { Main.drawable.ellipse(this, Color.white); } } public class Polygon : Shape { public Point datum; public System.Collections.Generic.List vertices; public Polygon() { vertices = new System.Collections.Generic.List(); } public Polygon append(Point p) { vertices.Add(p); return this; } public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); } public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); } public Figure shift(Point p) { datum += p; return this; } public Figure centering(Point p) { datum = p; return this; } public void draw(Color c) { Main.drawable.polygon(this, c); } public void draw() { Main.drawable.polygon(this, Color.white); } } }