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