Cleanup
This commit is contained in:
@@ -7,30 +7,30 @@ using System.Collections.Generic;
|
|||||||
namespace EtchBendLines
|
namespace EtchBendLines
|
||||||
{
|
{
|
||||||
public class Bend
|
public class Bend
|
||||||
{
|
{
|
||||||
public Line Line { get; set; }
|
public Line Line { get; set; }
|
||||||
|
|
||||||
public MText BendNote { get; set; }
|
public MText BendNote { get; set; }
|
||||||
|
|
||||||
public double YIntercept
|
public double YIntercept
|
||||||
{
|
{
|
||||||
get { return Line.YIntercept(); }
|
get { return Line.YIntercept(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public double Slope
|
public double Slope
|
||||||
{
|
{
|
||||||
get { return Line.Slope(); }
|
get { return Line.Slope(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsVertical
|
public bool IsVertical
|
||||||
{
|
{
|
||||||
get { return Line.IsVertical(); }
|
get { return Line.IsVertical(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsHorizontal
|
public bool IsHorizontal
|
||||||
{
|
{
|
||||||
get { return Line.IsHorizontal(); }
|
get { return Line.IsHorizontal(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsParallelTo(Bend bend)
|
public bool IsParallelTo(Bend bend)
|
||||||
{
|
{
|
||||||
@@ -43,119 +43,119 @@ namespace EtchBendLines
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCollinearTo(Bend bend)
|
public bool IsCollinearTo(Bend bend)
|
||||||
{
|
{
|
||||||
if (bend.IsVertical || this.IsVertical)
|
if (bend.IsVertical || this.IsVertical)
|
||||||
return (bend.IsVertical && this.IsVertical && bend.YIntercept == this.YIntercept);
|
return (bend.IsVertical && this.IsVertical && bend.YIntercept == this.YIntercept);
|
||||||
|
|
||||||
if (bend.YIntercept != this.YIntercept)
|
if (bend.YIntercept != this.YIntercept)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return bend.Slope == this.Slope;
|
return bend.Slope == this.Slope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Line> GetEtchLines(double etchLength)
|
public List<Line> GetEtchLines(double etchLength)
|
||||||
{
|
{
|
||||||
var lines = new List<Line>();
|
var lines = new List<Line>();
|
||||||
|
|
||||||
var etchLayer = new Layer("ETCH")
|
var etchLayer = new Layer("ETCH")
|
||||||
{
|
{
|
||||||
Color = AciColor.Green,
|
Color = AciColor.Green,
|
||||||
};
|
};
|
||||||
|
|
||||||
var startPoint = new Vector2(Line.StartPoint.X, Line.StartPoint.Y);
|
var startPoint = new Vector2(Line.StartPoint.X, Line.StartPoint.Y);
|
||||||
var endPoint = new Vector2(Line.EndPoint.X, Line.EndPoint.Y);
|
var endPoint = new Vector2(Line.EndPoint.X, Line.EndPoint.Y);
|
||||||
var bendLength = startPoint.DistanceTo(endPoint);
|
var bendLength = startPoint.DistanceTo(endPoint);
|
||||||
|
|
||||||
if (bendLength < (etchLength * 3.0))
|
if (bendLength < (etchLength * 3.0))
|
||||||
{
|
{
|
||||||
var fullLengthLine = new Line(Line.StartPoint, Line.EndPoint)
|
var fullLengthLine = new Line(Line.StartPoint, Line.EndPoint)
|
||||||
{
|
{
|
||||||
Layer = etchLayer
|
Layer = etchLayer
|
||||||
};
|
};
|
||||||
|
|
||||||
lines.Add(fullLengthLine);
|
lines.Add(fullLengthLine);
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var angle = startPoint.AngleTo(endPoint);
|
var angle = startPoint.AngleTo(endPoint);
|
||||||
|
|
||||||
if (Line.IsVertical())
|
if (Line.IsVertical())
|
||||||
{
|
{
|
||||||
var x = Line.StartPoint.X;
|
var x = Line.StartPoint.X;
|
||||||
|
|
||||||
var bottomY1 = Line.StartPoint.Y < Line.EndPoint.Y ? Line.StartPoint.Y : Line.EndPoint.Y;
|
var bottomY1 = Line.StartPoint.Y < Line.EndPoint.Y ? Line.StartPoint.Y : Line.EndPoint.Y;
|
||||||
var bottomY2 = bottomY1 + etchLength;
|
var bottomY2 = bottomY1 + etchLength;
|
||||||
|
|
||||||
var topY1 = Line.StartPoint.Y > Line.EndPoint.Y ? Line.StartPoint.Y : Line.EndPoint.Y;
|
var topY1 = Line.StartPoint.Y > Line.EndPoint.Y ? Line.StartPoint.Y : Line.EndPoint.Y;
|
||||||
var topY2 = topY1 - etchLength;
|
var topY2 = topY1 - etchLength;
|
||||||
|
|
||||||
var p1 = new Vector2(x, bottomY1);
|
var p1 = new Vector2(x, bottomY1);
|
||||||
var p2 = new Vector2(x, bottomY2);
|
var p2 = new Vector2(x, bottomY2);
|
||||||
|
|
||||||
var p3 = new Vector2(x, topY1);
|
var p3 = new Vector2(x, topY1);
|
||||||
var p4 = new Vector2(x, topY2);
|
var p4 = new Vector2(x, topY2);
|
||||||
|
|
||||||
var bottomPoint = Line.StartPoint.Y < Line.EndPoint.Y ? Line.StartPoint : Line.EndPoint;
|
var bottomPoint = Line.StartPoint.Y < Line.EndPoint.Y ? Line.StartPoint : Line.EndPoint;
|
||||||
var bottomOffsetPoint = new Vector2(bottomPoint.X, bottomPoint.Y + etchLength);
|
var bottomOffsetPoint = new Vector2(bottomPoint.X, bottomPoint.Y + etchLength);
|
||||||
|
|
||||||
var line1 = new Line(p1, p2)
|
var line1 = new Line(p1, p2)
|
||||||
{
|
{
|
||||||
Layer = etchLayer
|
Layer = etchLayer
|
||||||
};
|
};
|
||||||
|
|
||||||
var line2 = new Line(p3, p4)
|
var line2 = new Line(p3, p4)
|
||||||
{
|
{
|
||||||
Layer = etchLayer
|
Layer = etchLayer
|
||||||
};
|
};
|
||||||
|
|
||||||
lines.Add(line1);
|
lines.Add(line1);
|
||||||
lines.Add(line2);
|
lines.Add(line2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var start = Line.StartPoint.ToVector2();
|
var start = Line.StartPoint.ToVector2();
|
||||||
var end = Line.EndPoint.ToVector2();
|
var end = Line.EndPoint.ToVector2();
|
||||||
|
|
||||||
var x1 = Math.Cos(angle);
|
var x1 = Math.Cos(angle);
|
||||||
var y1 = Math.Sin(angle);
|
var y1 = Math.Sin(angle);
|
||||||
|
|
||||||
var p1 = new Vector2(start.X, start.Y);
|
var p1 = new Vector2(start.X, start.Y);
|
||||||
var p2 = new Vector2(start.X + x1, start.Y + y1);
|
var p2 = new Vector2(start.X + x1, start.Y + y1);
|
||||||
|
|
||||||
var p3 = new Vector2(end.X, end.Y);
|
var p3 = new Vector2(end.X, end.Y);
|
||||||
var p4 = new Vector2(end.X - x1, end.Y - y1);
|
var p4 = new Vector2(end.X - x1, end.Y - y1);
|
||||||
|
|
||||||
var line1 = new Line(p1, p2)
|
var line1 = new Line(p1, p2)
|
||||||
{
|
{
|
||||||
Layer = etchLayer
|
Layer = etchLayer
|
||||||
};
|
};
|
||||||
|
|
||||||
var line2 = new Line(p3, p4)
|
var line2 = new Line(p3, p4)
|
||||||
{
|
{
|
||||||
Layer = etchLayer
|
Layer = etchLayer
|
||||||
};
|
};
|
||||||
|
|
||||||
lines.Add(line1);
|
lines.Add(line1);
|
||||||
lines.Add(line2);
|
lines.Add(line2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BendDirection Direction { get; set; }
|
public BendDirection Direction { get; set; }
|
||||||
|
|
||||||
public double Length
|
public double Length
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var x = Line.EndPoint.X - Line.StartPoint.X;
|
var x = Line.EndPoint.X - Line.StartPoint.X;
|
||||||
var y = Line.EndPoint.Y - Line.StartPoint.Y;
|
var y = Line.EndPoint.Y - Line.StartPoint.Y;
|
||||||
return Math.Sqrt(x * x + y * y);
|
return Math.Sqrt(x * x + y * y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double? Radius { get; set; }
|
public double? Radius { get; set; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
namespace EtchBendLines
|
namespace EtchBendLines
|
||||||
{
|
{
|
||||||
public enum BendDirection
|
public enum BendDirection
|
||||||
{
|
{
|
||||||
Up,
|
Up,
|
||||||
Down,
|
Down,
|
||||||
Unknown
|
Unknown
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,58 +28,58 @@ namespace EtchBendLines
|
|||||||
return line.StartPoint.Y == line.EndPoint.Y;
|
return line.StartPoint.Y == line.EndPoint.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double Slope(this Line line)
|
public static double Slope(this Line line)
|
||||||
{
|
{
|
||||||
if (line.IsVertical())
|
if (line.IsVertical())
|
||||||
return double.NaN;
|
return double.NaN;
|
||||||
|
|
||||||
var p1 = line.StartPoint;
|
var p1 = line.StartPoint;
|
||||||
var p2 = line.EndPoint;
|
var p2 = line.EndPoint;
|
||||||
|
|
||||||
return Math.Round((p2.Y - p1.Y) / (p2.X - p1.X), 4);
|
return Math.Round((p2.Y - p1.Y) / (p2.X - p1.X), 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double YIntercept(this Line line)
|
public static double YIntercept(this Line line)
|
||||||
{
|
{
|
||||||
var p1 = line.StartPoint;
|
var p1 = line.StartPoint;
|
||||||
var p2 = line.EndPoint;
|
var p2 = line.EndPoint;
|
||||||
var slope = line.Slope();
|
var slope = line.Slope();
|
||||||
|
|
||||||
// y = mx + b
|
// y = mx + b
|
||||||
|
|
||||||
return Math.Round(p1.Y - slope * p1.X, 4);
|
return Math.Round(p1.Y - slope * p1.X, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 PointPerpendicularTo(this Line line, Vector2 pt)
|
public static Vector2 PointPerpendicularTo(this Line line, Vector2 pt)
|
||||||
{
|
{
|
||||||
var startPoint = line.StartPoint.ToVector2();
|
var startPoint = line.StartPoint.ToVector2();
|
||||||
var endPoint = line.EndPoint.ToVector2();
|
var endPoint = line.EndPoint.ToVector2();
|
||||||
|
|
||||||
var d1 = pt - startPoint;
|
var d1 = pt - startPoint;
|
||||||
var d2 = endPoint - startPoint;
|
var d2 = endPoint - startPoint;
|
||||||
var dotProduct = d1.X * d2.X + d1.Y * d2.Y;
|
var dotProduct = d1.X * d2.X + d1.Y * d2.Y;
|
||||||
var lengthSquared = d2.X * d2.X + d2.Y * d2.Y;
|
var lengthSquared = d2.X * d2.X + d2.Y * d2.Y;
|
||||||
var param = dotProduct / lengthSquared;
|
var param = dotProduct / lengthSquared;
|
||||||
|
|
||||||
if (param < 0)
|
if (param < 0)
|
||||||
return startPoint;
|
return startPoint;
|
||||||
else if (param > 1)
|
else if (param > 1)
|
||||||
return endPoint;
|
return endPoint;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new Vector2(
|
return new Vector2(
|
||||||
startPoint.X + param * d2.X,
|
startPoint.X + param * d2.X,
|
||||||
startPoint.Y + param * d2.Y);
|
startPoint.Y + param * d2.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 MidPoint(this Line line)
|
public static Vector2 MidPoint(this Line line)
|
||||||
{
|
{
|
||||||
var x = (line.StartPoint.X + line.EndPoint.X) * 0.5;
|
var x = (line.StartPoint.X + line.EndPoint.X) * 0.5;
|
||||||
var y = (line.StartPoint.Y + line.EndPoint.Y) * 0.5;
|
var y = (line.StartPoint.Y + line.EndPoint.Y) * 0.5;
|
||||||
|
|
||||||
return new Vector2(x, y);
|
return new Vector2(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double DistanceTo(this Vector2 startPoint, Vector2 endPoint)
|
public static double DistanceTo(this Vector2 startPoint, Vector2 endPoint)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using netDxf;
|
using netDxf;
|
||||||
using netDxf.Entities;
|
|
||||||
using netDxf.Tables;
|
using netDxf.Tables;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -12,18 +11,18 @@ namespace EtchBendLines
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
const double ETCH_LENGTH = 1.0;
|
const double ETCH_LENGTH = 1.0;
|
||||||
|
|
||||||
static Layer BendLayer = new Layer("BEND")
|
static Layer BendLayer = new Layer("BEND")
|
||||||
{
|
{
|
||||||
Color = AciColor.Yellow
|
Color = AciColor.Yellow
|
||||||
};
|
};
|
||||||
|
|
||||||
static Regex bendNoteRegex = new Regex(@"(?<direction>UP|DOWN|DN)\s*(?<angle>\d*(\.\d*)?)°\s*R\s*(?<radius>\d*(\.\d*)?)");
|
static Regex bendNoteRegex = new Regex(@"(?<direction>UP|DOWN|DN)\s*(?<angle>\d*(\.\d*)?)°\s*R\s*(?<radius>\d*(\.\d*)?)");
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
var path = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
var files = Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories);
|
var files = Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories);
|
||||||
|
|
||||||
if (files == null || files.Length == 0)
|
if (files == null || files.Length == 0)
|
||||||
@@ -68,13 +67,13 @@ namespace EtchBendLines
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var bendLine in bendLines)
|
foreach (var bendLine in bendLines)
|
||||||
{
|
{
|
||||||
bendLine.Line.Layer = BendLayer;
|
bendLine.Line.Layer = BendLayer;
|
||||||
bendLine.Line.Color = AciColor.ByLayer;
|
bendLine.Line.Color = AciColor.ByLayer;
|
||||||
bendLine.BendNote.Layer = BendLayer;
|
bendLine.BendNote.Layer = BendLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
var upBends = bendLines.Where(b => b.Direction == BendDirection.Up);
|
var upBends = bendLines.Where(b => b.Direction == BendDirection.Up);
|
||||||
var upBendCount = upBends.Count();
|
var upBendCount = upBends.Count();
|
||||||
var downBendCount = bendLines.Count - upBendCount;
|
var downBendCount = bendLines.Count - upBendCount;
|
||||||
|
|
||||||
@@ -84,7 +83,7 @@ namespace EtchBendLines
|
|||||||
|
|
||||||
foreach (var bendline in upBends)
|
foreach (var bendline in upBends)
|
||||||
{
|
{
|
||||||
var etchLines = bendline.GetEtchLines(ETCH_LENGTH);
|
var etchLines = bendline.GetEtchLines(ETCH_LENGTH);
|
||||||
|
|
||||||
foreach (var etchLine in etchLines)
|
foreach (var etchLine in etchLines)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
|
|||||||
Reference in New Issue
Block a user