|
|
cfceb0 |
using System;
|
|
|
cfceb0 |
using System.Drawing;
|
|
|
cfceb0 |
using System.Drawing.Imaging;
|
|
|
cfceb0 |
using System.Collections.Generic;
|
|
|
cfceb0 |
|
|
|
cfceb0 |
namespace Assistance {
|
|
|
cfceb0 |
public class AssistantVanishingPoint: Assistant {
|
|
|
cfceb0 |
public ActivePoint center;
|
|
|
cfceb0 |
public ActivePoint a0;
|
|
|
cfceb0 |
public ActivePoint a1;
|
|
|
cfceb0 |
public ActivePoint b0;
|
|
|
cfceb0 |
public ActivePoint b1;
|
|
|
cfceb0 |
public ActivePoint step;
|
|
|
cfceb0 |
|
|
|
72b17c |
public AssistantVanishingPoint(Workarea workarea, Point center): base(workarea) {
|
|
|
cfceb0 |
this.center = new ActivePoint(this, ActivePoint.Type.CircleCross, center);
|
|
|
cfceb0 |
a0 = new ActivePoint(this, ActivePoint.Type.CircleFill, center + new Point(-100.0, 0.0));
|
|
|
cfceb0 |
a1 = new ActivePoint(this, ActivePoint.Type.Circle, center + new Point(-200.0, 0.0));
|
|
|
cfceb0 |
b0 = new ActivePoint(this, ActivePoint.Type.CircleFill, center + new Point(100.0, 0.0));
|
|
|
cfceb0 |
b1 = new ActivePoint(this, ActivePoint.Type.Circle, center + new Point(200.0, 0.0));
|
|
|
cfceb0 |
step = new ActivePoint(this, ActivePoint.Type.Circle, (a0.position + a1.position)/2);
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
private void fixCenter() {
|
|
|
cfceb0 |
if (!a0.position.isEqual(a1.position) && !b0.position.isEqual(b1.position)) {
|
|
|
cfceb0 |
Point a = a0.position;
|
|
|
cfceb0 |
Point b = b0.position;
|
|
|
cfceb0 |
Point da = a1.position - a;
|
|
|
cfceb0 |
Point db = b1.position - b;
|
|
|
cfceb0 |
Point ab = b - a;
|
|
|
cfceb0 |
double k = db.x*da.y - db.y*da.x;
|
|
|
cfceb0 |
if (Math.Abs(k) > 0.00001) {
|
|
|
cfceb0 |
double lb = (da.x*ab.y - da.y*ab.x)/k;
|
|
|
cfceb0 |
center.position.x = lb*db.x + b.x;
|
|
|
cfceb0 |
center.position.y = lb*db.y + b.y;
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
private void fixSidePoint(ActivePoint p0, ActivePoint p1, Point previousP0) {
|
|
|
cfceb0 |
if (!p0.position.isEqual(center.position)) {
|
|
|
cfceb0 |
Point dp0 = p0.position - center.position;
|
|
|
cfceb0 |
Point dp1 = p1.position - previousP0;
|
|
|
cfceb0 |
p1.position = center.position + dp0*(dp0.len() + dp1.len())/dp0.len();
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
private void fixSidePoint(ActivePoint p0, ActivePoint p1) {
|
|
|
cfceb0 |
fixSidePoint(p0, p1, p0.position);
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
public void fixPoints() {
|
|
|
cfceb0 |
fixSidePoint(a0, a1);
|
|
|
cfceb0 |
fixSidePoint(a0, step);
|
|
|
cfceb0 |
fixSidePoint(b0, b1);
|
|
|
cfceb0 |
fixCenter();
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
public override void onMovePoint(ActivePoint point, Point position) {
|
|
|
cfceb0 |
Point previous = point.position;
|
|
|
cfceb0 |
point.position = position;
|
|
|
cfceb0 |
if (point == center) {
|
|
|
cfceb0 |
a0.position += point.position - previous;
|
|
|
cfceb0 |
a1.position += point.position - previous;
|
|
|
cfceb0 |
step.position += point.position - previous;
|
|
|
cfceb0 |
b0.position += point.position - previous;
|
|
|
cfceb0 |
b1.position += point.position - previous;
|
|
|
cfceb0 |
} else
|
|
|
cfceb0 |
if (point == a0) {
|
|
|
cfceb0 |
fixSidePoint(a0, a1, previous);
|
|
|
cfceb0 |
fixSidePoint(a0, step, previous);
|
|
|
cfceb0 |
fixSidePoint(b0, b1);
|
|
|
cfceb0 |
} else
|
|
|
cfceb0 |
if (point == b0) {
|
|
|
cfceb0 |
fixSidePoint(a0, a1);
|
|
|
cfceb0 |
fixSidePoint(a0, step);
|
|
|
cfceb0 |
fixSidePoint(b0, b1, previous);
|
|
|
cfceb0 |
} else {
|
|
|
cfceb0 |
fixCenter();
|
|
|
cfceb0 |
fixSidePoint(a0, a1);
|
|
|
cfceb0 |
fixSidePoint(a0, step);
|
|
|
cfceb0 |
fixSidePoint(b0, b1);
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
/*
|
|
|
cfceb0 |
public override Point[] getGridPoints(Point target, bool truncate) {
|
|
|
cfceb0 |
double k = (a0.position - center.position).len();
|
|
|
cfceb0 |
if (k < 0.00001)
|
|
|
cfceb0 |
return new Point[0];
|
|
|
cfceb0 |
k = (step.position - center.position).len()/k;
|
|
|
cfceb0 |
|
|
|
cfceb0 |
//if (Math.Abs(k - 1.0) < 0.1) return new Point[0];
|
|
|
cfceb0 |
|
|
|
cfceb0 |
Point[] points = new Point[truncate ? gridPointsCount + 1 : gridPointsCount*2 + 1];
|
|
|
cfceb0 |
Point a = target - center.position;
|
|
|
cfceb0 |
Point b = a;
|
|
|
cfceb0 |
points[gridPointsCount] = a + center.position;
|
|
|
cfceb0 |
for(int i = 1; i <= gridPointsCount; ++i) {
|
|
|
cfceb0 |
a /= k;
|
|
|
cfceb0 |
b *= k;
|
|
|
cfceb0 |
points[gridPointsCount - i] = a + center.position;
|
|
|
cfceb0 |
if (!truncate)
|
|
|
cfceb0 |
points[gridPointsCount + i] = b + center.position;
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
return points;
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
*/
|
|
|
cfceb0 |
|
|
|
cfceb0 |
public override void draw(System.Drawing.Graphics g) {
|
|
|
cfceb0 |
g.DrawLine(pen, center.position.toFloat(), a0.position.toFloat());
|
|
|
cfceb0 |
g.DrawLine(pen, center.position.toFloat(), a1.position.toFloat());
|
|
|
cfceb0 |
g.DrawLine(pen, center.position.toFloat(), b0.position.toFloat());
|
|
|
cfceb0 |
g.DrawLine(pen, center.position.toFloat(), b1.position.toFloat());
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|
|
|
cfceb0 |
public override void getGuidelines(List<guideline> outGuidelines, Point target) {</guideline>
|
|
|
cfceb0 |
if (!target.isEqual(center.position))
|
|
|
cfceb0 |
outGuidelines.Add(new GuidelineLine(target, center.position));
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
}
|
|
|
cfceb0 |
|