Changeset 12694 for branches/HeuristicLab.Problems.Orienteering/HeuristicLab.MainForm.WindowsForms/3.3/Dialogs/DefineArithmeticProgressionDialog.cs
- Timestamp:
- 07/09/15 13:07:30 (9 years ago)
- Location:
- branches/HeuristicLab.Problems.Orienteering
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.Orienteering
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
-
branches/HeuristicLab.Problems.Orienteering/HeuristicLab.MainForm.WindowsForms/3.3/Dialogs/DefineArithmeticProgressionDialog.cs
r11185 r12694 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using System.ComponentModel; 24 24 using System.Globalization; 25 using System.Linq;26 25 using System.Windows.Forms; 27 26 using HeuristicLab.Common; … … 31 30 private bool allowOnlyInteger; 32 31 33 public d oubleMinimum { get; private set; }34 public d oubleMaximum { get; private set; }35 public d oubleStep { get; private set; }32 public decimal Minimum { get; private set; } 33 public decimal Maximum { get; private set; } 34 public decimal Step { get; private set; } 36 35 37 public IEnumerable<d ouble> Values {38 get { return EnumerateProgression().Reverse(); }36 public IEnumerable<decimal> Values { 37 get { return SequenceGenerator.GenerateSteps(Minimum, Maximum, Step, includeEnd: true); } 39 38 } 40 39 … … 48 47 this.allowOnlyInteger = allowOnlyInteger; 49 48 } 50 public DefineArithmeticProgressionDialog(bool allowOnlyInteger, d ouble minimum, double maximum, doublestep)49 public DefineArithmeticProgressionDialog(bool allowOnlyInteger, decimal minimum, decimal maximum, decimal step) 51 50 : this(allowOnlyInteger) { 52 51 Minimum = minimum; … … 63 62 private void textBox_Validating(object sender, CancelEventArgs e) { 64 63 var textBox = (TextBox)sender; 65 d oublevalue = 0;64 decimal value = 0; 66 65 if (allowOnlyInteger) { 67 66 int intValue; … … 75 74 } 76 75 } else { 77 if (!d ouble.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) {76 if (!decimal.TryParse(textBox.Text, NumberStyles.Float, CultureInfo.CurrentCulture.NumberFormat, out value)) { 78 77 errorProvider.SetError(textBox, "Please enter a valid double value."); 79 78 e.Cancel = true; … … 90 89 return Minimum <= Maximum && Step >= 0; 91 90 } 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 minimum104 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 }115 91 } 116 92 }
Note: See TracChangeset
for help on using the changeset viewer.