Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/11/15 19:44:35 (9 years ago)
Author:
abeham
Message:

#2301: merged 12292,12293 to stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.MainForm.WindowsForms/3.3/Dialogs/DefineArithmeticProgressionDialog.cs

    r12009 r12740  
    2323using System.ComponentModel;
    2424using System.Globalization;
    25 using System.Linq;
    2625using System.Windows.Forms;
    2726using HeuristicLab.Common;
     
    3130    private bool allowOnlyInteger;
    3231
    33     public double Minimum { get; private set; }
    34     public double Maximum { get; private set; }
    35     public double Step { get; private set; }
     32    public decimal Minimum { get; private set; }
     33    public decimal Maximum { get; private set; }
     34    public decimal Step { get; private set; }
    3635
    37     public IEnumerable<double> Values {
    38       get { return EnumerateProgression().Reverse(); }
     36    public IEnumerable<decimal> Values {
     37      get { return SequenceGenerator.GenerateSteps(Minimum, Maximum, Step, includeEnd: true); }
    3938    }
    4039
     
    4847      this.allowOnlyInteger = allowOnlyInteger;
    4948    }
    50     public DefineArithmeticProgressionDialog(bool allowOnlyInteger, double minimum, double maximum, double step)
     49    public DefineArithmeticProgressionDialog(bool allowOnlyInteger, decimal minimum, decimal maximum, decimal step)
    5150      : this(allowOnlyInteger) {
    5251      Minimum = minimum;
     
    6362    private void textBox_Validating(object sender, CancelEventArgs e) {
    6463      var textBox = (TextBox)sender;
    65       double value = 0;
     64      decimal value = 0;
    6665      if (allowOnlyInteger) {
    6766        int intValue;
     
    7574        }
    7675      } else {
    77         if (!double.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {
     76        if (!decimal.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {
    7877          errorProvider.SetError(textBox, "Please enter a valid double value.");
    7978          e.Cancel = true;
     
    9089      return Minimum <= Maximum && Step >= 0;
    9190    }
    92 
    93     private IEnumerable<double> EnumerateProgression() {
    94       double value = Maximum;
    95       bool minimumIncluded = false;
    96       int i = 1;
    97       while (value >= Minimum) {
    98         if (value.IsAlmost(Minimum)) {
    99           yield return Minimum;
    100           minimumIncluded = true;
    101         } else yield return value;
    102 
    103         if (Step == 0) break; // a step size of 0 will only output maximum and minimum
    104         if (allowOnlyInteger) {
    105           value = (int)Maximum - i * (int)Step;
    106         } else {
    107           value = Maximum - i * Step;
    108         }
    109         i++;
    110       }
    111       if (!minimumIncluded) {
    112         yield return Minimum;
    113       }
    114     }
    11591  }
    11692}
Note: See TracChangeset for help on using the changeset viewer.