Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajisaacs committed Sep 25, 2019
1 parent 68f6035 commit 8764553
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 198 deletions.
254 changes: 127 additions & 127 deletions EtchBendLines/Bend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
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)
{
Expand All @@ -43,119 +43,119 @@ public bool IsPerpendicularTo(Bend bend)
}

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;
}

public List<Line> GetEtchLines(double etchLength)
{
var lines = new List<Line>();

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);

if (bendLength < (etchLength * 3.0))
{
var fullLengthLine = new Line(Line.StartPoint, Line.EndPoint)
{
Layer = etchLayer
};

lines.Add(fullLengthLine);

return lines;
}
else
{
var angle = startPoint.AngleTo(endPoint);

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 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 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 line1 = new Line(p1, p2)
{
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();

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 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 line2 = new Line(p3, p4)
{
Layer = etchLayer
};

lines.Add(line1);
lines.Add(line2);
}
}

return lines;
}

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);
}
}
return bend.Slope == this.Slope;
}

public List<Line> GetEtchLines(double etchLength)
{
var lines = new List<Line>();

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);

if (bendLength < (etchLength * 3.0))
{
var fullLengthLine = new Line(Line.StartPoint, Line.EndPoint)
{
Layer = etchLayer
};

lines.Add(fullLengthLine);

return lines;
}
else
{
var angle = startPoint.AngleTo(endPoint);

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 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 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 line1 = new Line(p1, p2)
{
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();

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 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 line2 = new Line(p3, p4)
{
Layer = etchLayer
};

lines.Add(line1);
lines.Add(line2);
}
}

return lines;
}

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? Radius { get; set; }

Expand Down
10 changes: 5 additions & 5 deletions EtchBendLines/BendDirection.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace EtchBendLines
{
public enum BendDirection
{
Up,
Down,
Unknown
}
{
Up,
Down,
Unknown
}
}
Loading

0 comments on commit 8764553

Please sign in to comment.