Skip to content

Commit

Permalink
Merge pull request #5 from danielfdsilva/feature/4_correct_unions
Browse files Browse the repository at this point in the history
Feature/4 correct unions
  • Loading branch information
Daniel Silva committed Nov 25, 2014
2 parents 01e8cc3 + cc52b59 commit 5828311
Show file tree
Hide file tree
Showing 7 changed files with 1,125 additions and 255 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ $interval->inInterval(15.25); // TRUE
```

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

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

For example:
> **BUG**: The union method is broken. Do not use (or) in the expression. See [issue #4](https://github.com/danielfdsilva/mathInterval/issues/4)


```php
// [5,20] ⋃ [10,25]
$interval = new MathInterval('[5,20] or [10,25]');
$interval = new MathIntervalCollection('[5,20] or [10,25]');
print $interval; // [5,25]

// [5,20] ∩ [10,25]
$interval = new MathInterval('[5,20] and [10,25]');
$interval = new MathIntervalCollection('[5,20] and [10,25]');
print $interval; // [10,20]

// You can chain as many values as needed in an expression:
// [5,20] ∩ [10,25] ⋃ [15,30[
$interval = new MathInterval('[5,20] and [10,25] or [15,30[');
$interval = new MathIntervalCollection('[5,20] and [10,25] or [15,30[');
print $interval; // [10,30[

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

**With complex expressions you must use `MathIntervalCollection`. All the methods available in `MathInterval` like union and intersection are also available here.**

```php
$interval = new MathIntervalCollection('[1,10]');
$interval->union('[16,20]');
// Note that some intervals are not possible to unite therefore they
// will be left as an expression.
print $interval; // [1,10] or [16,20]


$interval = new MathIntervalCollection('[1,10] or [16,20]');
$interval->intersection(']7,9] or [15,18]');
print $interval; // ]7,9] or [16,18]
// This would be the same as ([1,10] or [16,20]) and (]7,9] or [15,18])
```

-----

## Contribution
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

### 2.0.0

- Union and intersection methods accept MathInterval objects. ~~Fix #1~~
- Add MathIntervalCollection to support correct union of intervals. ~~Fix #4~~

### 1.1.0

- Add support for expressions.
Expand Down
Loading

0 comments on commit 5828311

Please sign in to comment.