diff --git a/mono/Assistance/ActivePoint.cs b/mono/Assistance/ActivePoint.cs index b588f72..155edda 100644 --- a/mono/Assistance/ActivePoint.cs +++ b/mono/Assistance/ActivePoint.cs @@ -5,11 +5,6 @@ using System.Collections.Generic; namespace Assistance { public class ActivePoint { - public enum Mode { - Common = 0, - Active = 1 - } - public enum Type { Circle, CircleFill, @@ -18,8 +13,10 @@ namespace Assistance { public static readonly double radius = 10.0; public static readonly double crossSize = 1.2*radius; - public static readonly Pen[] pens = new Pen[] { Pens.Gray, Pens.Blue }; - public static readonly Brush[] brushes = new Brush[] { Brushes.LightGray, Brushes.LightBlue }; + public static readonly Pen pen = Pens.Gray; + public static readonly Brush brush = Brushes.LightGray; + public static readonly Pen penActive = Pens.Blue; + public static readonly Brush brushActive = Brushes.LightBlue; public readonly Workarea canvas; public readonly Assistant assistant; @@ -47,31 +44,39 @@ namespace Assistance { canvas.points.Add(this); } - private void drawCircle(Graphics g, Mode mode) { - g.DrawEllipse(pens[(int)mode], (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius)); + private Pen getPen(bool active) { + return active ? penActive : pen; + } + + private Brush getBrush(bool active) { + return active ? brushActive : brush; + } + + private void drawCircle(Graphics g, bool active) { + g.DrawEllipse(getPen(active), (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius)); } - private void fillCircle(Graphics g, Mode mode) { - g.FillEllipse(brushes[(int)mode], (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius)); + private void fillCircle(Graphics g, bool active) { + g.FillEllipse(getBrush(active), (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius)); } - private void drawCross(Graphics g, Mode mode) { - g.DrawLine(pens[(int)mode], (float)(position.x - crossSize), (float)position.y, (float)(position.x + crossSize), (float)position.y); - g.DrawLine(pens[(int)mode], (float)position.x, (float)(position.y - crossSize), (float)position.x, (float)(position.y + crossSize)); + private void drawCross(Graphics g, bool active) { + g.DrawLine(getPen(active), (float)(position.x - crossSize), (float)position.y, (float)(position.x + crossSize), (float)position.y); + g.DrawLine(getPen(active), (float)position.x, (float)(position.y - crossSize), (float)position.x, (float)(position.y + crossSize)); } - public void draw(Graphics g, Mode mode) { + public void draw(Graphics g, bool active = false) { switch(type) { case Type.Circle: - drawCircle(g, mode); + drawCircle(g, active); break; case Type.CircleFill: - fillCircle(g, mode); - drawCircle(g, mode); + fillCircle(g, active); + drawCircle(g, active); break; case Type.CircleCross: - drawCircle(g, mode); - drawCross(g, mode); + drawCircle(g, active); + drawCross(g, active); break; } } diff --git a/mono/Assistance/Assistance.csproj b/mono/Assistance/Assistance.csproj index 1519ced..67f810d 100644 --- a/mono/Assistance/Assistance.csproj +++ b/mono/Assistance/Assistance.csproj @@ -36,13 +36,16 @@ - - + + + + + diff --git a/mono/Assistance/Assistant.cs b/mono/Assistance/Assistant.cs index bdc9581..64148d7 100644 --- a/mono/Assistance/Assistant.cs +++ b/mono/Assistance/Assistant.cs @@ -8,7 +8,6 @@ namespace Assistance { public static readonly double maxLen = 1000.0; public static readonly int gridPointsCount = 100; public static readonly Pen pen = Pens.Gray; - public static readonly Pen guidePen = Pens.LightGray; public readonly Workarea canvas; public readonly List points = new List(); @@ -40,24 +39,8 @@ namespace Assistance { point.position = position; } - public virtual Point[] getGridPoints(Point target, bool truncate) { return new Point[0]; } - - public Point[] getGridPoints(Point target) { return getGridPoints(target, false); } - public virtual void draw(Graphics g) { } - public virtual void drawGuidlines(Graphics g, Point target, bool truncate) { } - - public void drawGuidlines(Graphics g, Point target) { - drawGuidlines(g, target, false); - } - - public virtual double calcTrackWeight(Track track) { - return double.PositiveInfinity; - } - - public virtual Track modifyTrack(Track track) { - return new Track(); - } + public virtual void getGuidelines(List outGuidelines, Point target) { } } } diff --git a/mono/Assistance/Grid.cs b/mono/Assistance/Grid.cs deleted file mode 100644 index 15159b7..0000000 --- a/mono/Assistance/Grid.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace Assistance { - public class Grid: Assistant { - public ActivePoint center; - - public Grid(Workarea canvas, Point center): base(canvas) { - this.center = new ActivePoint(this, ActivePoint.Type.CircleCross, center); - } - - public override void draw(System.Drawing.Graphics g) { - foreach(Assistant assistant in canvas.assistants) - foreach(Point p in assistant.getGridPoints(center.position)) - foreach(Assistant a in canvas.assistants) - if (a != assistant) - a.drawGuidlines(g, p); - } - } -} - diff --git a/mono/Assistance/MainWindow.cs b/mono/Assistance/MainWindow.cs index ea4f7e9..570b559 100644 --- a/mono/Assistance/MainWindow.cs +++ b/mono/Assistance/MainWindow.cs @@ -70,10 +70,10 @@ namespace Assistance { public void onKeyDown(Object sender, KeyEventArgs e) { switch(e.KeyCode) { case Keys.D1: - new VanishingPoint(workarea, cursor); + new AssistantVanishingPoint(workarea, cursor); break; case Keys.D2: - new Grid(workarea, cursor); + new AssistantGrid(workarea, cursor); break; case Keys.Delete: if (activePoint != null) diff --git a/mono/Assistance/Point.cs b/mono/Assistance/Point.cs index 6ab9fe6..6a415c9 100644 --- a/mono/Assistance/Point.cs +++ b/mono/Assistance/Point.cs @@ -2,8 +2,6 @@ using System; namespace Assistance { public struct Point { - public static readonly double precision = 0.01; - public double x; public double y; @@ -11,6 +9,10 @@ namespace Assistance { this.x = x; this.y = y; } + public Point(System.Drawing.Point point): + this(point.X, point.Y) { } + public Point(System.Drawing.PointF point): + this(point.X, point.Y) { } public static Point operator+ (Point a, Point b) { return new Point(a.x + b.x, a.y + b.y); @@ -37,7 +39,7 @@ namespace Assistance { } public bool isEqual(Point other) { - return (this - other).lenSqr() <= precision*precision; + return (this - other).lenSqr() <= Geometry.precision*Geometry.precision; } public double lenSqr() { @@ -50,7 +52,7 @@ namespace Assistance { public Point normalize() { double l = len(); - return l > precision*precision*precision ? this/l : this; + return l > Geometry.precision*Geometry.precision ? this/l : this; } public System.Drawing.PointF toFloat() { diff --git a/mono/Assistance/VanishingPoint.cs b/mono/Assistance/VanishingPoint.cs deleted file mode 100644 index 5ec7473..0000000 --- a/mono/Assistance/VanishingPoint.cs +++ /dev/null @@ -1,151 +0,0 @@ -using System; - -namespace Assistance { - public class VanishingPoint: Assistant { - public ActivePoint center; - public ActivePoint a0; - public ActivePoint a1; - public ActivePoint b0; - public ActivePoint b1; - public ActivePoint step; - - public VanishingPoint(Workarea canvas, Point center): base(canvas) { - this.center = new ActivePoint(this, ActivePoint.Type.CircleCross, center); - a0 = new ActivePoint(this, ActivePoint.Type.CircleFill, center + new Point(-100.0, 0.0)); - a1 = new ActivePoint(this, ActivePoint.Type.Circle, center + new Point(-200.0, 0.0)); - b0 = new ActivePoint(this, ActivePoint.Type.CircleFill, center + new Point(100.0, 0.0)); - b1 = new ActivePoint(this, ActivePoint.Type.Circle, center + new Point(200.0, 0.0)); - step = new ActivePoint(this, ActivePoint.Type.Circle, (a0.position + a1.position)/2); - } - - private void fixCenter() { - if (!a0.position.isEqual(a1.position) && !b0.position.isEqual(b1.position)) { - Point a = a0.position; - Point b = b0.position; - Point da = a1.position - a; - Point db = b1.position - b; - Point ab = b - a; - double k = db.x*da.y - db.y*da.x; - if (Math.Abs(k) > 0.00001) { - double lb = (da.x*ab.y - da.y*ab.x)/k; - center.position.x = lb*db.x + b.x; - center.position.y = lb*db.y + b.y; - } - } - } - - private void fixSidePoint(ActivePoint p0, ActivePoint p1, Point previousP0) { - if (!p0.position.isEqual(center.position)) { - Point dp0 = p0.position - center.position; - Point dp1 = p1.position - previousP0; - p1.position = center.position + dp0*(dp0.len() + dp1.len())/dp0.len(); - } - } - - private void fixSidePoint(ActivePoint p0, ActivePoint p1) { - fixSidePoint(p0, p1, p0.position); - } - - public void fixPoints() { - fixSidePoint(a0, a1); - fixSidePoint(a0, step); - fixSidePoint(b0, b1); - fixCenter(); - } - - public override void onMovePoint(ActivePoint point, Point position) { - Point previous = point.position; - point.position = position; - if (point == center) { - a0.position += point.position - previous; - a1.position += point.position - previous; - step.position += point.position - previous; - b0.position += point.position - previous; - b1.position += point.position - previous; - } else - if (point == a0) { - fixSidePoint(a0, a1, previous); - fixSidePoint(a0, step, previous); - fixSidePoint(b0, b1); - } else - if (point == b0) { - fixSidePoint(a0, a1); - fixSidePoint(a0, step); - fixSidePoint(b0, b1, previous); - } else { - fixCenter(); - fixSidePoint(a0, a1); - fixSidePoint(a0, step); - fixSidePoint(b0, b1); - } - } - - public override Point[] getGridPoints(Point target, bool truncate) { - double k = (a0.position - center.position).len(); - if (k < 0.00001) - return new Point[0]; - k = (step.position - center.position).len()/k; - - //if (Math.Abs(k - 1.0) < 0.1) return new Point[0]; - - Point[] points = new Point[truncate ? gridPointsCount + 1 : gridPointsCount*2 + 1]; - Point a = target - center.position; - Point b = a; - points[gridPointsCount] = a + center.position; - for(int i = 1; i <= gridPointsCount; ++i) { - a /= k; - b *= k; - points[gridPointsCount - i] = a + center.position; - if (!truncate) - points[gridPointsCount + i] = b + center.position; - } - return points; - } - - public override void draw(System.Drawing.Graphics g) { - g.DrawLine(pen, center.position.toFloat(), a0.position.toFloat()); - g.DrawLine(pen, center.position.toFloat(), a1.position.toFloat()); - g.DrawLine(pen, center.position.toFloat(), b0.position.toFloat()); - g.DrawLine(pen, center.position.toFloat(), b1.position.toFloat()); - } - - public override void drawGuidlines(System.Drawing.Graphics g, Point target, bool truncate) { - if (truncate) { - g.DrawLine(guidePen, center.position.toFloat(), target.toFloat()); - } else { - Point p = (target - center.position).normalize()*getMaxLen() + center.position; - g.DrawLine(guidePen, center.position.toFloat(), p.toFloat()); - } - } - - public override double calcTrackWeight(Track track) { - if (track.points.Count < 2) - return 0.0; - - Point point = track.points[0]; - Point d = (point - center.position).normalize(); - d = new Point(-d.y, d.x); - double weight = 0.0; - foreach(Point p in track.points) - weight += Math.Abs((p.x - point.x)*d.x + (p.y - point.y)*d.y); - weight /= track.points.Count; - - return weight; - } - - public override Track modifyTrack(Track track) { - Track t = new Track(); - if (track.points.Count < 1) - return t; - - Point point = track.points[0]; - Point d = (point - center.position).normalize(); - foreach(Point p in track.points) { - double l = (p.x - point.x)*d.x + (p.y - point.y)*d.y; - t.points.Add(l*d + point); - } - return t; - } - } -} -