You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> **BUG**: The union method is broken. Do not use. See [issue #4](https://github.com/danielfdsilva/mathInterval/issues/4)
48
47
49
48
```php
50
49
// Create your first interval.
@@ -74,27 +73,43 @@ print $interval; // [17,20]
74
73
MathInterval also allows you to use expressions to initialize and compute intervals. The official symbols for intersections and union are ∩ and ⋃, but, since these are hard to type, MathInterval uses ```and``` and ```or```.
75
74
76
75
For example:
77
-
> **BUG**: The union method is broken. Do not use (or) in the expression. See [issue #4](https://github.com/danielfdsilva/mathInterval/issues/4)
76
+
78
77
79
78
```php
80
79
// [5,20] ⋃ [10,25]
81
-
$interval = new MathInterval('[5,20] or [10,25]');
80
+
$interval = new MathIntervalCollection('[5,20] or [10,25]');
82
81
print $interval; // [5,25]
83
82
84
83
// [5,20] ∩ [10,25]
85
-
$interval = new MathInterval('[5,20] and [10,25]');
84
+
$interval = new MathIntervalCollection('[5,20] and [10,25]');
86
85
print $interval; // [10,20]
87
86
88
87
// You can chain as many values as needed in an expression:
89
88
// [5,20] ∩ [10,25] ⋃ [15,30[
90
-
$interval = new MathInterval('[5,20] and [10,25] or [15,30[');
89
+
$interval = new MathIntervalCollection('[5,20] and [10,25] or [15,30[');
91
90
print $interval; // [10,30[
92
91
93
92
// You can also use these expressions in the union() and intersection() methods.
94
93
```
95
94
Just like in any mathematical expression, the order of the operators matters and parenthesis can be used to specify the order of the operations.
**With complex expressions you must use `MathIntervalCollection`. All the methods available in `MathInterval` like union and intersection are also available here.**
98
+
99
+
```php
100
+
$interval = new MathIntervalCollection('[1,10]');
101
+
$interval->union('[16,20]');
102
+
// Note that some intervals are not possible to unite therefore they
103
+
// will be left as an expression.
104
+
print $interval; // [1,10] or [16,20]
105
+
106
+
107
+
$interval = new MathIntervalCollection('[1,10] or [16,20]');
108
+
$interval->intersection(']7,9] or [15,18]');
109
+
print $interval; // ]7,9] or [16,18]
110
+
// This would be the same as ([1,10] or [16,20]) and (]7,9] or [15,18])
0 commit comments