/// <summary> /// Determine equality between two QSS instances /// </summary> public bool Equals(QSD <T> other) { bool result = base.Equals(other); result &= this.Minuend == null ? other.Minuend == null : this.Minuend.Equals(other.Minuend); result &= this.Subtrahend == null ? other.Subtrahend == null : this.Subtrahend.Equals(other.Subtrahend); return(result); }
/// <summary> /// Normalize /// </summary> public override MARC.Everest.Interfaces.IGraphable Normalize() { QSD <T> retVal = this.Clone() as QSD <T>; if (retVal.Minuend is SXPR <T> ) { retVal.Minuend = (retVal.Minuend as SXPR <T>).TranslateToQSET(); } if (retVal.Subtrahend is SXPR <T> ) { retVal.Subtrahend = (retVal.Subtrahend as SXPR <T>).TranslateToQSET(); } return(retVal); }
/// <summary> /// Translate to a QSET data internally /// </summary> private QSET <T> TranslateToQSETInternal(SetOperator operation, List <SXCM <T> > collectedTerms, QSET <T> context) { // We need to construct the appropriate structure switch (operation) { case SetOperator.Exclusive: // difference { // QSD must be broken into groups of two int iofs = 0; QSD <T> diffSet = null; if (context == null) // Null, then the minuend is our first term { diffSet = new QSD <T>(collectedTerms[0].TranslateToQSETComponent(), null); iofs = 1; } else // Not, then the current QSET is the minuend { diffSet = new QSD <T>(context, null); } for (int i = iofs; i < collectedTerms.Count; i++) { diffSet.Subtrahend = collectedTerms[i].TranslateToQSETComponent(); if (i + 1 < collectedTerms.Count) // We need to make a new QSD where this is the minuend { diffSet = new QSD <T>(diffSet, null); } } context = diffSet; break; } case SetOperator.Inclusive: // union is pretty easy { QSU <T> unionSet = new QSU <T>(); bool isQssCandidate = true; if (context != null) { isQssCandidate &= (context is QSS <T>) && (context as QSS <T>).Count() == 1; unionSet.Add(context); } foreach (var itm in collectedTerms) { var qsuItem = itm.TranslateToQSETComponent(); isQssCandidate &= (qsuItem is QSS <T>) && (qsuItem as QSS <T>).Count() == 1; unionSet.Add(qsuItem); } // Is the union set composed entirely of QSS instances with one item? if (isQssCandidate) { var qssSet = new QSS <T>(); foreach (var itm in unionSet) { qssSet.Add((itm as QSS <T>).First()); } context = qssSet; } else { context = unionSet; } break; } case SetOperator.Intersect: // intersect, also pretty easy { QSI <T> intersectSet = new QSI <T>(); if (context != null) { intersectSet.Add(context); } foreach (var itm in collectedTerms) { intersectSet.Add(itm.TranslateToQSETComponent()); } context = intersectSet; break; } case SetOperator.PeriodicHull: // periodic hull, same as difference { // QSP must be broken into groups of two int iofs = 0; QSP <T> periodSet = null; if (context == null) // Null, then the minuend is our first term { periodSet = new QSP <T>(collectedTerms[0].TranslateToQSETComponent(), null); iofs = 1; } else // Not, then the current QSET is the minuend { periodSet = new QSP <T>(context, null); } for (int i = iofs; i < collectedTerms.Count; i++) { periodSet.High = collectedTerms[i].TranslateToQSETComponent(); if (i + 1 < collectedTerms.Count) // We need to make a new QSD where this is the minuend { periodSet = new QSP <T>(periodSet, null); } } context = periodSet; break; } case SetOperator.Hull: // convex hull { throw new InvalidOperationException("Cannot represent a HULL value"); } } return(context); }
/// <summary> /// Create a new instance of the GTS class with the specified <paramref name="hull"/> /// </summary> /// <param name="hull"></param> public GTS(QSD <TS> hull) : base() { this.Hull = hull; }