Skip to content

Commit cc52b59

Browse files
committed
Update documentation and version bump.
1 parent bf8b1cc commit cc52b59

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
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.

src/MathInterval.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
/**
33
* @file MathInterval.php
4-
* Contains the MathInterval Library.
54
*
65
* @author Daniel da Silva
76
* @package MathInterval
8-
* @version 1.1.0
7+
* @version 2.0.0
98
*/
109

1110
// Match: [1,2].
@@ -24,7 +23,7 @@ class MathInterval {
2423
/**
2524
* MathInterval version.
2625
*/
27-
const VERSION = '1.1.0';
26+
const VERSION = '2.0.0';
2827

2928
/**
3029
* Whether the beginning of the interval is closed.

src/MathIntervalCollection.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
require 'MathInterval.php';
33

44
/**
5-
* @file MathInterval.php
6-
* Contains the MathInterval Library.
5+
* @file MathIntervalCollection.php
76
*
87
* @author Daniel da Silva
98
* @package MathInterval
10-
* @version 1.1.0
9+
* @version 2.0.0
1110
*/
1211

1312
// In class constants you can't define constants with concatenation

0 commit comments

Comments
 (0)