Example #1
0
        private double HandleCoordinates(int[] coordinates)
        {
            // return positive distance or -1 to stop growing the branch

            // stop growing grid if limits reached
            if (_limits.rationalCount != -1 && _rationalCounter >= _limits.rationalCount)
            {
                return(-1);                                                                          // stop the branch
            }
            if (_limits.dimensionCount != -1 && coordinates.Length > _limits.dimensionCount)
            {
                return(-1);                         // stop the branch
            }
            Rational r = MakeRational(coordinates); // e.g. by customBasis
            double   d = _harmonicity.GetDistance(r);

            if (_limits.distance >= 0 && d > _limits.distance)
            {
                return(-1);                     // stop the branch -- !!! can we be sure there are no closer distance rationals in this branch?
            }
            int result = _handleRational(r, d); // 1, 0, -1

            if (result == -1)
            {
                return(-1);              // stop this branch
            }
            if (result == 1)
            {
                _rationalCounter++;              // node accepted
            }
            return(d);
        }
Example #2
0
        public static   Partial[] MakePartials(IHarmonicity harmonicity, Rational[] subgroup, int partialCount)
        {
            // subgroup
            Vectors.Matrix matrix = new Vectors.Matrix(subgroup, makeDiagonal: true);
            // partials
            var partials = new List <Partial>();

            for (int i = 1; i < 200; ++i)
            {
                var r = new Rational(i);
                if (matrix.FindCoordinates(r) == null)
                {
                    continue;                                    // skip if out of subgroup
                }
                partials.Add(new Partial {
                    rational    = r,
                    harmonicity = harmonicity.GetDistance(r),
                });
                if (partials.Count == partialCount)
                {
                    break;
                }
            }
            return(partials.ToArray());
        }
Example #3
0
 public HarmonicityNormalizer(IHarmonicity harmonicity, Rational sample = default(Rational))
 {
     _harmonicity = harmonicity;
     if (sample.IsDefault())
     {
         sample = _defaultSample;
     }
     _distanceFactor = 1.0 / _harmonicity.GetDistance(sample);
 }
Example #4
0
 public override double GetDistance(Rational r)
 {
     return(_harmonicity.GetDistance(r) * _distanceFactor);
 }