/// <summary> /// Checks whether the interval is disjunct with the current one. /// </summary> /// <param name="interval">Interval to check</param> /// <returns>Whether the checked interval is disjunct with the current one</returns> public bool IntervalIsDisjunct(Interval interval1) { bool special = false; float intervalUpperBound; float intervalLowerBound; float thisUpperBound; float thisLowerBound; if (interval1.intervalType == IntervalType.Long) { intervalUpperBound = interval1.upperBound; intervalUpperBound = (int)intervalUpperBound; intervalLowerBound = interval1.lowerBound; intervalLowerBound = (int)intervalLowerBound; thisUpperBound = this.upperBound; thisUpperBound = (int)thisUpperBound; thisLowerBound = this.lowerBound; thisLowerBound = (int)thisLowerBound; } else { if (interval1.intervalType == IntervalType.Float) { intervalUpperBound = interval1.upperBoundFl; intervalLowerBound = interval1.lowerBoundFl; thisLowerBound = this.lowerBoundFl; thisUpperBound = this.upperBoundFl; } else { return true; } } if (interval1.upperBoundType != IntervalBoundType.Infinity) { if (interval1.upperBoundType == IntervalBoundType.Sharp) { if (this.IsInInterval(intervalUpperBound)) { return false; } } else { special = true; } } else { if (this.upperBoundType != IntervalBoundType.Infinity) { if (this.upperBoundType == IntervalBoundType.Sharp) { if (interval1.IsInInterval(thisUpperBound)) { return false; } } else { special = true; } } else { //both upper bounds are infinite, cannot be disjunct return false; } } if (interval1.lowerBoundType != IntervalBoundType.Infinity) { if (interval1.lowerBoundType == IntervalBoundType.Sharp) { if (this.IsInInterval(intervalLowerBound)) { return false; } } else { special = true; } } else { if (this.lowerBoundType != IntervalBoundType.Infinity) { if (this.lowerBoundType == IntervalBoundType.Sharp) { if (interval1.IsInInterval(thisLowerBound)) { return false; } } else { special = true; } } else { //both lower bounds are minus infinity, cannot be disjunct return false; } } if (special) { if (this.upperBoundType == IntervalBoundType.Sharp) { if (interval1.IsInInterval(thisUpperBound)) { return false; } } if (this.lowerBoundType == IntervalBoundType.Sharp) { if (interval1.IsInInterval(thisLowerBound)) { return false; } } if (interval1.upperBoundType == IntervalBoundType.Infinity) { if (interval1.lowerBoundType == IntervalBoundType.Round) { if (interval1.IsInInterval(thisUpperBound)) { return false; } } if (interval1.lowerBoundType == IntervalBoundType.Sharp) { if (thisUpperBound != intervalLowerBound) { if (interval1.IsInInterval(thisUpperBound)) { return false; } } else { return false; } } } if (interval1.lowerBoundType == IntervalBoundType.Infinity) { if (interval1.upperBoundType == IntervalBoundType.Round) { if (interval1.IsInInterval(thisLowerBound)) { return false; } } if (interval1.upperBoundType == IntervalBoundType.Sharp) { if (thisLowerBound != intervalUpperBound) { if (interval1.IsInInterval(thisLowerBound)) { return false; } } else { return false; } } } if (this.upperBoundType == IntervalBoundType.Infinity) { if (this.lowerBoundType == IntervalBoundType.Round) { if (this.IsInInterval(intervalUpperBound)) { return false; } } if (this.lowerBoundType == IntervalBoundType.Sharp) { if (intervalUpperBound != thisLowerBound) { if (this.IsInInterval(intervalUpperBound)) { return false; } } else { return false; } } } if (this.lowerBoundType == IntervalBoundType.Infinity) { if (this.upperBoundType == IntervalBoundType.Round) { if (this.IsInInterval(intervalLowerBound)) { return false; } } if (this.upperBoundType == IntervalBoundType.Sharp) { if (intervalLowerBound != thisUpperBound) { if (this.IsInInterval(intervalLowerBound)) { return false; } } else { return false; } } } if ((thisLowerBound > intervalLowerBound) && (thisLowerBound < intervalUpperBound)) { return false; } if ((thisUpperBound > intervalLowerBound) && (thisUpperBound < intervalUpperBound)) { return false; } if ((intervalLowerBound > thisLowerBound) && (intervalLowerBound < thisUpperBound)) { return false; } if ((intervalUpperBound > thisLowerBound) && (intervalUpperBound < thisUpperBound)) { return false; } if ((intervalLowerBound == thisLowerBound) && (intervalUpperBound == thisUpperBound)) { return false; } } return true; }
/// <summary> /// Method to check whether any of the enum values are in interval /// </summary> /// <param name="interval"></param> /// <returns></returns> public bool IntervalDisjunctWithCurrentEnums(Interval interval) { foreach (object value in this.Set.Values) { switch (interval.intervalType) { case IntervalType.Float: try { float temp = 0; temp = (float)Convert.ToDouble(value); if (interval.IsInInterval(temp)) return false; } catch { break; } break; case IntervalType.Long: try { int temp = 0; temp = Convert.ToInt32(value); if (interval.IsInInterval(temp)) return false; } catch { break; } break; default: throw new Exception("Switch branch not implemented"); } } return true; }