public Boolean CalcSplits() { if (data.ValidExtendedData() == false) { return(false); } double distance = ConvertDistanceToSplitDistanceType(data.Distance); int numberOfSplits = (int)Math.Ceiling(distance / data.SplitDistance); double totalSeconds = ((double)data.Hours * 60 * 60 + data.Minutes * 60) + data.Seconds; double splitDistance = data.SplitDistance; double perSplitSeconds = totalSeconds / (distance / splitDistance); int splitHours = 0; int splitMinutes = 0; double splitSeconds = 0; double accumlativeSplitDistance = 0; double accumlativeSplitTime = 0; // reset the splits data.SplitList.Clear(); for (int splitCount = 0; splitCount < numberOfSplits; splitCount += 1) { accumlativeSplitDistance = splitDistance * (splitCount + 1); if (accumlativeSplitDistance > distance) { accumlativeSplitDistance = distance; } accumlativeSplitTime = perSplitSeconds * (accumlativeSplitDistance / splitDistance); splitHours = (int)(accumlativeSplitTime / (60 * 60)); accumlativeSplitTime = accumlativeSplitTime - (splitHours * 60 * 60); splitMinutes = (int)(accumlativeSplitTime / 60); accumlativeSplitTime = accumlativeSplitTime - (splitMinutes * 60); splitSeconds = accumlativeSplitTime; data.SplitList.Add(new Split(splitHours, splitMinutes, splitSeconds, accumlativeSplitDistance)); } // making this event a bit more thread safe by assigning the // event to a variable. As we are never removing the handler really // isn't necessary but not a bad reminder. SplitChangeHandler omc = onSplitChange; // only update if there is at least one listener active if (omc != null) { omc(this, new SplitEventArgs(data.SplitList)); } return(true); }
public Boolean ClearSplits() { data.SplitList.Clear(); // making this event a bit more thread safe by assigning the // event to a variable. As we are never removing the handler really // isn't necessary but not a bad reminder. SplitChangeHandler omc = onSplitChange; // only update if there is at least one listener active if (omc != null) { omc(this, new SplitEventArgs(data.SplitList)); } return(true); }