Fixed a mix-up on horizontal and vertical bends.

This commit is contained in:
aj
2017-10-16 22:00:14 -04:00
parent def7c380ee
commit 0dbdd4d978

View File

@@ -672,32 +672,10 @@ namespace ExportDXF.Forms
if (up.Count == 0) if (up.Count == 0)
return true; return true;
if (down.Count == up.Count) var bend = ClosestToBounds(bounds, bends);
{
var hBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Horizontal).ToList();
var vBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Vertical).ToList();
if (hBends.Count == vBends.Count) return bend.Direction == BendDirection.Down;
{ }
var r1 = bounds.Width / hBends.Count;
var r2 = bounds.Height / vBends.Count;
return r2 > r1;
}
else if (hBends.Count > vBends.Count)
{
var x = SmallestYCoordinate(hBends);
return x.Direction == BendDirection.Down;
}
else
{
var x = SmallestXCoordinate(vBends);
return x.Direction == BendDirection.Down;
}
}
return down.Count > up.Count;
}
private static Bounds GetBounds(SolidWorks.Interop.sldworks.View view) private static Bounds GetBounds(SolidWorks.Interop.sldworks.View view)
{ {
@@ -725,25 +703,25 @@ namespace ExportDXF.Forms
var hBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Horizontal).ToList(); var hBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Horizontal).ToList();
var vBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Vertical).ToList(); var vBends = bends.Where(b => GetAngleOrientation(b.ParallelBendAngle) == BendOrientation.Vertical).ToList();
Bend minHBend = null; Bend minVBend = null;
double minHBendDist = double.MaxValue; double minVBendDist = double.MaxValue;
foreach (var bend in hBends) foreach (var bend in vBends)
{ {
double distFromLft = Math.Abs(bend.X - bounds.Left); double distFromLft = Math.Abs(bend.X - bounds.Left);
double distFromRgt = Math.Abs(bounds.Right - bend.X); double distFromRgt = Math.Abs(bounds.Right - bend.X);
double minDist = Math.Min(distFromLft, distFromRgt); double minDist = Math.Min(distFromLft, distFromRgt);
if (minDist < minHBendDist) if (minDist < minVBendDist)
{ {
minHBendDist = minDist; minVBendDist = minDist;
minHBend = bend; minVBend = bend;
} }
} }
Bend minVBend = null; Bend minHBend = null;
double minVBendDist = double.MaxValue; double minHBendDist = double.MaxValue;
foreach (var bend in hBends) foreach (var bend in hBends)
{ {
@@ -754,12 +732,12 @@ namespace ExportDXF.Forms
if (minDist < minHBendDist) if (minDist < minHBendDist)
{ {
minVBendDist = minDist; minHBendDist = minDist;
minVBend = bend; minHBend = bend;
} }
} }
return minVBendDist < minHBendDist ? minVBend : minHBend; return minHBendDist < minVBendDist ? minHBend : minVBend;
} }
private static Bend SmallestYCoordinate(IList<Bend> bends) private static Bend SmallestYCoordinate(IList<Bend> bends)
@@ -792,7 +770,7 @@ namespace ExportDXF.Forms
if (bend.X < dist) if (bend.X < dist)
{ {
dist = bend.Y; dist = bend.X;
index = i; index = i;
} }
} }