OSDN Git Service

hk
[psychlops/silverlight.git] / dev3 / psychlops / core / graphic / shape.cs
index ffefeea..9533e8e 100644 (file)
@@ -14,6 +14,7 @@ namespace Psychlops{
 \r
        public interface Shape : Figure\r
        {\r
+               void draw(Color c);\r
        }\r
        public static class ShapeExtention\r
        {\r
@@ -25,13 +26,30 @@ namespace Psychlops{
                */\r
        }\r
 \r
+       public struct Stroke\r
+       {\r
+\r
+       }\r
 \r
        public class Line : Shape\r
        {\r
                public Point begin, end;\r
 \r
+               public Line(double x1, double y1, double x2, double y2)\r
+               {\r
+                       set(x1, y1, x2, y2);\r
+               }\r
                public Line(Point v1, Point v2)\r
                {\r
+                       set(v1, v2);\r
+               }\r
+               public void set(double x1, double y1, double x2, double y2)\r
+               {\r
+                       begin.set(x1, y1);\r
+                       end.set(x2, y2);\r
+               }\r
+               public void set(Point v1, Point v2)\r
+               {\r
                        begin = v1;\r
                        end   = v2;\r
                }\r
@@ -61,6 +79,10 @@ namespace Psychlops{
                        Main.drawable.line(this, Color.white);\r
                }\r
 \r
+               public double left { get { return begin.x < end.x ? begin.x : end.x; } }\r
+               public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }\r
+               public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }\r
+               public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }\r
                public double width { get { return Math.abs(begin.x - end.x); } }\r
                public double height { get { return Math.abs(begin.y - end.y); } }\r
 \r
@@ -142,6 +164,21 @@ namespace Psychlops{
                public Point datum;\r
                public double xdiameter, ydiameter;\r
 \r
+               public Ellipse()\r
+               {\r
+                       set(0,0);\r
+               }\r
+               public Ellipse(double wid, double hei)\r
+               {\r
+                       set(wid, hei);\r
+               }\r
+\r
+               public Ellipse set(double wid, double hei)\r
+               {\r
+                       xdiameter = wid;\r
+                       ydiameter = hei;\r
+                       return this;\r
+               }\r
                public Figure shift(Point p)\r
                {\r
                        datum += p;\r
@@ -161,6 +198,13 @@ namespace Psychlops{
                {\r
                        Main.drawable.ellipse(this, Color.white);\r
                }\r
+\r
+               public double left { get { return datum.x - xdiameter/2.0; } }\r
+               public double top { get { return datum.y - ydiameter / 2.0; } }\r
+               public double right { get { return datum.x + xdiameter / 2.0; } }\r
+               public double bottom { get { return datum.y + ydiameter / 2.0; } }\r
+               public double width { get { return Math.abs(xdiameter); } }\r
+               public double height { get { return Math.abs(ydiameter); } }\r
        }\r
 \r
 \r
@@ -173,6 +217,24 @@ namespace Psychlops{
                {\r
                        vertices = new System.Collections.Generic.List<Point>();\r
                }\r
+               public Polygon(double[] verts)\r
+               {\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+                       for (int i=0; i < verts.Length; i+=2)\r
+                       {\r
+                               vertices.Add(new Point(verts[i], verts[i+1]));\r
+                       }\r
+\r
+               }\r
+               public Polygon(Point[] verts)\r
+               {\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+                       foreach (Point p in verts)\r
+                       {\r
+                               vertices.Add(p);\r
+                       }\r
+\r
+               }\r
                public Polygon append(Point p) { vertices.Add(p); return this; }\r
                public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }\r
                public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }\r