public static Bend GetBendClosestToBounds(Bounds bounds, IList <Bend> bends) { var hBends = bends.Where(b => GetAngleOrientation(b.BendLineAngle) == BendOrientation.Horizontal).ToList(); var vBends = bends.Where(b => GetAngleOrientation(b.BendLineAngle) == BendOrientation.Vertical).ToList(); Bend minVBend = null; double minVBendDist = double.MaxValue; foreach (var bend in vBends) { double distFromLft = Math.Abs(bend.X - bounds.Left); double distFromRgt = Math.Abs(bounds.Right - bend.X); double minDist = Math.Min(distFromLft, distFromRgt); if (minDist < minVBendDist) { minVBendDist = minDist; minVBend = bend; } } Bend minHBend = null; double minHBendDist = double.MaxValue; foreach (var bend in hBends) { double distFromBtm = Math.Abs(bend.Y - bounds.Bottom); double distFromTop = Math.Abs(bounds.Top - bend.Y); double minDist = Math.Min(distFromBtm, distFromTop); if (minDist < minHBendDist) { minHBendDist = minDist; minHBend = bend; } } return(minHBendDist < minVBendDist ? minHBend : minVBend); }
public static List <Bend> GetBends(View view) { var bends = new List <Bend>(); var notes = GetBendNotes(view); const string pattern = @"(?<DIRECTION>(UP|DOWN))\s*(?<ANGLE>(\d+(.\d*)?))°"; foreach (var note in notes) { var pos = note.GetTextPoint2() as double[]; var x = pos[0] / 0.0254; var y = pos[1] / 0.0254; var text = note.GetText(); var match = Regex.Match(text, pattern, RegexOptions.IgnoreCase); if (!match.Success) { continue; } var angle = double.Parse(match.Groups["ANGLE"].Value); var direection = match.Groups["DIRECTION"].Value; var bend = new Bend { BendLineAngle = RadiansToDegrees(note.Angle), Angle = angle, Direction = direection == "UP" ? BendDirection.Up : BendDirection.Down, X = x, Y = y }; bends.Add(bend); } return(bends); }