Skip to content

Commit 5828311

Browse files
author
Daniel Silva
committed
Merge pull request #5 from danielfdsilva/feature/4_correct_unions
Feature/4 correct unions
2 parents 01e8cc3 + cc52b59 commit 5828311

File tree

7 files changed

+1125
-255
lines changed

7 files changed

+1125
-255
lines changed

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ $interval->inInterval(15.25); // TRUE
4444
```
4545

4646
### Union
47-
> **BUG**: The union method is broken. Do not use. See [issue #4](https://github.com/danielfdsilva/mathInterval/issues/4)
4847

4948
```php
5049
// Create your first interval.
@@ -74,27 +73,43 @@ print $interval; // [17,20]
7473
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```.
7574

7675
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+
7877

7978
```php
8079
// [5,20] ⋃ [10,25]
81-
$interval = new MathInterval('[5,20] or [10,25]');
80+
$interval = new MathIntervalCollection('[5,20] or [10,25]');
8281
print $interval; // [5,25]
8382

8483
// [5,20] ∩ [10,25]
85-
$interval = new MathInterval('[5,20] and [10,25]');
84+
$interval = new MathIntervalCollection('[5,20] and [10,25]');
8685
print $interval; // [10,20]
8786

8887
// You can chain as many values as needed in an expression:
8988
// [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[');
9190
print $interval; // [10,30[
9291

9392
// You can also use these expressions in the union() and intersection() methods.
9493
```
9594
Just like in any mathematical expression, the order of the operators matters and parenthesis can be used to specify the order of the operations.
9695
For example: ```[5,20] ∩ ([10,25] ⋃ [15,30[)``` = ```[5,20] ∩ [10,30[``` = ```[10,20]```
9796

97+
**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])
111+
```
112+
98113
-----
99114

100115
## Contribution

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
### 2.0.0
4+
5+
- Union and intersection methods accept MathInterval objects. ~~Fix #1~~
6+
- Add MathIntervalCollection to support correct union of intervals. ~~Fix #4~~
7+
38
### 1.1.0
49

510
- Add support for expressions.

0 commit comments

Comments
 (0)