Exemple #1
0
        private bool CheckPointsAreStraight(IEnumerable <PointM> points)
        {
            Angle avgAngle = Angle.FromPoints(points.First().ToVector(), points.Last().ToVector());

            avgAngle.Normalize();

            double tolerance = Layout.ShouldHaveStraightFrets() ? 2.5 : 1;

            //double maxDiff = 0;

            for (int i = 1; i < points.Count() - 1; i++)
            {
                var curAngle = Angle.FromPoints(points.First().ToVector(), points.ElementAt(i).ToVector());
                curAngle.Normalize();
                var angleDiff = MathP.Abs(curAngle.Degrees - avgAngle.Degrees);
                if (angleDiff > tolerance)
                {
                    return(false);
                }
                //if (angleDiff > maxDiff)
                //    maxDiff = angleDiff;
            }

            return(true);

            //if (maxDiff >= 1)
            //    Console.WriteLine(string.Format("max diff for fret {0}: {1}", FretIndex, Angle.FromDegrees(maxDiff)));
            //return maxDiff <= tolerance;
        }
Exemple #2
0
        private bool CheckForHardBreak(/*IEnumerable<PointM> points*/)
        {
            var points = new List <PointM>();

            for (int i = 0; i < Segments.Count; i++)
            {
                if (i == 0)
                {
                    points.Add(Segments[i].P2);
                }

                points.Add(Segments[i].PointOnString);

                if (i == Segments.Count - 1)
                {
                    points.Add(Segments[i].P1);
                }
            }

            int    straightCtr = 0;
            Vector prevDir     = Vector.Empty;
            Angle  prevAngle   = Angle.Empty;

            for (int i = 0; i < points.Count - 1; i++)
            {
                var curDir   = (points[i + 1] - points[i]).Direction;
                var curAngle = Angle.FromPoints(points[i].ToVector(), points[i + 1].ToVector()).Normalized();
                if (!prevAngle.IsEmpty)
                {
                    if (MathP.Abs(curAngle.Degrees - prevAngle.Degrees) > 25)
                    {
                        //hard break
                        SplitFret(i - 1);
                        return(true);
                    }
                }
                if (!prevDir.IsEmpty)
                {
                    if ((prevDir - curDir).Length <= 0.01)
                    {
                        straightCtr++;
                    }
                }
                prevAngle = curAngle;
                prevDir   = curDir;
            }
            return(false);
        }
Exemple #3
0
 public static bool operator ==(Angle a1, Angle a2)
 {
     return(MathP.Abs(a1.Degrees - a2.Degrees) <= double.Epsilon);
 }