Algorithmix.MatchData.CompareShred C# (CSharp) Method

CompareShred() public static method

Given two shreds, calculate the offset value at which the two shreds are most similar
public static CompareShred ( Shred first, Shred second, Direction directionA, Orientation orientationA, Direction directionB, Orientation orientationB ) : MatchData
first Shred The first shred staged for comparison
second Shred The other shred staged for comparison
directionA Direction Direction of this shred to be compared
orientationA Orientation Orientation of this shred to be compared
directionB Direction Direction of the other shred to be compared
orientationB Orientation Orientiation of the other shred to be compared
return MatchData
        public static MatchData CompareShred(Shred first,
                                             Shred second,
                                             Direction directionA,
                                             Orientation orientationA,
                                             Direction directionB,
                                             Orientation orientationB)
        {
            Side sideA = new Side(first, directionA, orientationA);
            Side sideB = new Side(second, directionB, orientationB);
            double penalty = 1.0;

            if (ORIENTATION_PENALTY)
            {
                if (first.TrueOrienation != null && second.TrueOrienation != null)
                {
                    if (!(
                        (first.TrueOrienation == orientationA && second.TrueOrienation == orientationB) ||
                        (first.TrueOrienation == Enumeration.Opposite(orientationA) && second.TrueOrienation == Enumeration.Opposite(orientationB))))
                    {
                        penalty = 0.15;
                    }
                }
            }

            if (NORMALIZATION_ENABLED)
            {
                double max = Chamfer.NormalizedSimilarity(
                    first.GetChamfer(directionA, orientationA),
                    second.GetChamfer(directionB, orientationB));
                double[] scan = new double[1];

                return new MatchData(max*penalty, 0, scan, sideA, sideB);
            }
            else
            {
                double[] scan = Chamfer.ScanSimilarity(
                    first.GetChamfer(directionA, orientationA),
                    second.GetChamfer(directionB, orientationB));

                Tuple<double, int> maxData = Utility.Max(scan);
                double max = maxData.Item1;
                int best = maxData.Item2;
                return new MatchData(max*penalty, best, scan, sideA, sideB);
            }
        }