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