Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14159


Ignore:
Timestamp:
07/21/16 16:42:29 (8 years ago)
Author:
bburlacu
Message:

#2594: Slight improvement of scaling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ChartUtil.cs

    r14156 r14159  
    3737
    3838      // if one of the interval ends is a multiple of 5 or 10, change the other interval end to be a multiple as well
    39       if (decimalRank > 0) {
    40         if (((aMin % 5).IsAlmost(0) || (aMin % 10).IsAlmost(0)) && !((aMax % 5).IsAlmost(0) || (aMax % 10).IsAlmost(0))) {
    41           aMax = Math.Min(aMax + 5 - aMax % 5, aMax + 10 - aMax % 10);
    42         } else if (((aMax % 5).IsAlmost(0) || (aMax % 10).IsAlmost(0)) && !((aMin % 5).IsAlmost(0) || (aMin % 10).IsAlmost(0))) {
    43           aMin = Math.Max(aMin - aMin % 5, aMin - aMin % 10);
    44         }
     39      if ((aMin.Mod(5).IsAlmost(0) || aMin.Mod(10).IsAlmost(0)) && Math.Abs(aMax) >= 5 && !(aMax.Mod(5).IsAlmost(0) || aMax.Mod(10).IsAlmost(0))) {
     40        aMax = Math.Min(aMax + 5 - aMax % 5, aMax + 10 - aMax % 10);
     41      } else if ((aMax.Mod(5).IsAlmost(0) || aMax.Mod(10).IsAlmost(0)) && Math.Abs(aMin) >= 5 && !(aMin.Mod(5).IsAlmost(0) || aMin.Mod(10).IsAlmost(0))) {
     42        aMin = Math.Max(aMin - aMin.Mod(5), aMin - aMin.Mod(10));
    4543      }
    4644
     
    9290        var floor = (int)Math.Floor(value);
    9391        var pow = (int)Math.Pow(10, decimalRank);
    94         var mod = floor % pow;
    95         if (mod < 0) mod += pow;
     92        var mod = Mod(floor, pow);
    9693        return floor - mod;
    9794      }
     
    103100        var ceil = (int)Math.Ceiling(value);
    104101        var pow = (int)Math.Pow(10, decimalRank);
    105         var mod = ceil % pow;
    106         if (mod < 0) mod += pow;
     102        var mod = Mod(ceil, pow);
    107103        return ceil - mod + pow;
    108104      }
     
    135131      return Math.Abs(value - other) < eps;
    136132    }
     133
     134    private static double Mod(this double a, double b) {
     135      return a - b * Math.Floor(a / b);
     136    }
    137137  }
    138138}
Note: See TracChangeset for help on using the changeset viewer.