OSDN Git Service

.0
[psychlops/silverlight.git] / dev3 / psychlops / core / graphic / shape.cs
index f92e989..82f19b7 100644 (file)
@@ -60,6 +60,11 @@ namespace Psychlops{
        public partial class Line : Shape\r
        {\r
                public Point begin, end;\r
+               public Point datum\r
+               {\r
+                       get { return begin; }\r
+                       set { begin = value; }\r
+               }\r
 \r
                public Line(double x1, double y1, double x2, double y2)\r
                {\r
@@ -107,6 +112,12 @@ namespace Psychlops{
                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
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
 \r
                public Color fill { get; set; }\r
                public Stroke stroke { get; set; }\r
@@ -125,13 +136,53 @@ namespace Psychlops{
                {\r
                        set(wid, hei);\r
                }\r
-               \r
+               public Rectangle(Rectangle another)\r
+               {\r
+                       v1 = another.v1;\r
+                       v2 = another.v2;\r
+               }\r
                public Rectangle set(double wid, double hei)\r
                {\r
                        v1.set(0, 0, 0);\r
                        v2.set(wid, hei, 0);\r
                        return this;\r
                }\r
+               Rectangle set(Point po1, Point po2) {\r
+                       v1 = po1;\r
+                       v2 = po2;\r
+                       return this;\r
+               }\r
+               public Rectangle set(double l, double t, double r, double b)\r
+               {\r
+                       v1.set(l, t, 0);\r
+                       v2.set(r, b, 0);\r
+                       return this;\r
+               }\r
+               public Rectangle set(Rectangle another)\r
+               {\r
+                       v1 = another.v1;\r
+                       v2 = another.v2;\r
+                       return this;\r
+               }\r
+\r
+               public Rectangle resize(double width, double height)\r
+               {\r
+                       Point po = center;\r
+                       set(width, height);\r
+                       centering(po);\r
+                       return this;\r
+               }\r
+\r
+\r
+               public Point datum\r
+               {\r
+                       get { return v1; }\r
+                       set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }\r
+               }\r
+               public Rectangle move_to(Point p) { datum = p; return this; }\r
+               public Rectangle move_to(double x, double y, double z) { datum = new Point(x, y, z); return this; }\r
+               public Rectangle locate(Point p) { datum = p; return this; }\r
+               public Rectangle locate(double x, double y, double z) { datum = new Point(x, y, z); return this; }\r
 \r
                public Figure shift(Point p)\r
                {\r
@@ -153,6 +204,55 @@ namespace Psychlops{
                {\r
                        Main.drawable.rect(this);\r
                }\r
+               public bool include(double x, double y)\r
+               {\r
+                       return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);\r
+               }\r
+               public bool include(Point p)\r
+               {\r
+                       return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);\r
+               }\r
+               public bool include(Rectangle rect)\r
+               {\r
+                       return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);\r
+               }\r
+\r
+               public Rectangle alignLeft(double lef)\r
+               {\r
+                       return move_to(lef, getTop(), datum.z);\r
+               }\r
+               public Rectangle alignTop(double to_)\r
+               {\r
+                       return move_to(getLeft(), to_, datum.z);\r
+               }\r
+               public Rectangle alignRight(double rig)\r
+               {\r
+                       return move_to(rig - getWidth(), getTop(), datum.z);\r
+               }\r
+               public Rectangle alignBottom(double bot)\r
+               {\r
+                       return move_to(getLeft(), bot - getHeight(), datum.z);\r
+               }\r
+\r
+               public void clipped_by(Rectangle source)\r
+               {\r
+                       double t = top, l = left, b = bottom, r = right;\r
+                       if (top < source.top) { t = source.top; }\r
+                       if (left < source.left) { l = source.left; }\r
+                       if (bottom > source.bottom) { b = source.bottom; }\r
+                       if (right > source.right) { r = source.right; }\r
+                       set(l, t, r, b);\r
+               }\r
+               public void clip(Rectangle target)\r
+               {\r
+                       double t = top, l = left, b = bottom, r = right;\r
+                       if (top < target.top) { t = target.top; }\r
+                       if (left < target.left) { l = target.left; }\r
+                       if (bottom > target.bottom) { b = target.bottom; }\r
+                       if (right > target.right) { r = target.right; }\r
+                       set(l, t, r, b);\r
+               }\r
+\r
 \r
                public double left   { get { return v1.x; } }\r
                public double top    { get { return v1.y; } }\r
@@ -160,6 +260,18 @@ namespace Psychlops{
                public double bottom { get { return v2.y; } }\r
                public double width { get { return Math.abs(v1.x - v2.x); } }\r
                public double height { get { return Math.abs(v1.y - v2.y); } }\r
+               public Point center {\r
+                       get { return new Point((left + right) / 2, (top + bottom) / 2); }\r
+                       set { centering(value); }\r
+               }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public Point getCenter() { return center; }\r
+\r
 \r
 \r
                public Color fill { get; set; }\r
@@ -174,7 +286,7 @@ namespace Psychlops{
 \r
        public partial class Ellipse : Shape\r
        {\r
-               public Point datum;\r
+               public Point datum { get; set; }\r
                public double xdiameter, ydiameter;\r
 \r
                public Ellipse()\r
@@ -214,6 +326,18 @@ namespace Psychlops{
                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
+               public Point center\r
+               {\r
+                       get { return new Point((left + right) / 2, (top + bottom) / 2); }\r
+                       set { centering(value); }\r
+               }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public Point getCenter() { return center; }\r
 \r
                public Color fill { get; set; }\r
                public Stroke stroke { get; set; }\r
@@ -222,7 +346,7 @@ namespace Psychlops{
 \r
        public partial class Polygon : Shape\r
        {\r
-               public Point datum;\r
+               public Point datum { get; set; }\r
                public System.Collections.Generic.List<Point> vertices;\r
 \r
                public Polygon()\r
@@ -254,7 +378,7 @@ namespace Psychlops{
 \r
                public Figure shift(Point p)\r
                {\r
-                       datum += p;\r
+                       datum = datum + p;\r
                        return this;\r
                }\r
                public Figure centering(Point p)\r