Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I haven't heard of any, but you can easily do without them if you represent the constraints as intervals:</p> <p>x > 1000 becomes (1000, double.Infinity)<br> x == 1000 becomes [1000, 1000]</p> <p>etc.</p> <p>This way you need only one class</p> <pre><code>class Constraint { double Lower; bool isLowerStrict; double Upper; bool isUpperStrict; bool isIn(double d) { return (isLowerStrict ? Lower &lt; d : Lower &lt;= d) &amp;&amp; (isUpperStrict ? Upper &gt; d : Upper &gt;= d); } Constraint intersect(Constraint other) { Constraint result = new Constraint(); if (Lower &gt; other.Lower) { result.Lower = Lower; result.isLowerStrict = isLowerStrict; } else if (Lower &lt; other.Lower) { result.Lower = other.Lower; result.isLowerStrict = other.isLowerStrict; } else { result.Lower = Lower; result.IsLowerStrict = isLowerStrict || other.isLowerStrict; } // the same for upper return result; } public bool isEmpty() { if (Lower &gt; Upper) return true; if (Lower == Upper &amp;&amp; (isLowerStrict || isUpperStrict)) return true; return false; } public bool Equals(Constraint other) { if (isEmpty()) return other.isEmpty(); return (Lower == other.Lower) &amp;&amp; (Upper = other.Upper) &amp;&amp; (isLowerStrict == other.IsLowerStrict) &amp;&amp; (isUpperStrict == other.isUpperStrict); } // construction: static Constraint GreaterThan(double d) { return new Constraint() { Lower = d, isLowerStrict = true, Upper = double.PositiveInfinity, isUpperStrict = false }; } static Constraint IsEqualTo(double d) { return new Constraint() { Lower = d, isLowerStrict = false, Upper = d, isUpperStrict = false }; } // etc. } </code></pre> <p>With this code, you can answer the questions:</p> <p>1) overlap: <code>a.Intersect(b).isEmpty()</code></p> <p>2) intersect: <code>a.Intersect(b)</code></p> <p>3) constrain: <code>a.Intersect(b).Equals(a)</code></p> <hr> <p>EDIT:<br> As @CodeInChaos suggests, you should consider replacing double with decimal. Mind that decimal lacks infinite values, so you should use decimal.MaxValue and decimal.MinValue instead.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload