@djuleayo/intv
v0.0.4
Published
intervals/segments like in mathematics
Downloads
2
Readme
Intv
intervals like in mathematics - closed, open or half and half
Useful for Date
s or any other kind of fun you are making!
How to use
//disjuncted dist 0
const a = i`(1, 0)`
const b = i`(1, 2)`
console.log(`${a} ∩ ${b} = ${a.intersect(b)}`) // undefined
//intersect of pow 0
const a1 = i`(0, 1]`
const b1 = i`[1, 2)`
console.log(`${a1} ∩ ${b1} = ${a1.intersect(b1)}`) // 1
//and non edge-case intersects
const a2 = i`(0, 2]`
const b2 = i`[1, 2)`
console.log(`${a2} ∩ ${b2} = ${a2.intersect(b2)}`) // i`[1, 2)`
Alergic to strings ?
const intv = i(0, 1, true, false);
Features
- intersections
- minus
- visitor pattern
- heavily tested
Incoming
- union
- RSS - Real subset
type Basic =
| undefined
| number
| [number, number, boolean, boolean]
;
type RSS =
| Basic
| Basic[]
;
Test
Test was written as brute force of input combinations. One interval can be open and closed in 4 ways. 16 ways for both. Take one interval as pivot and the limits of other can be
- lower than min
- same as min
- inside lower point
- inside higher point
- same as max
- higher than max
For each combination of positions and each combination of open/closed - TEST for each operation This should give you trust to not loose your own eyes taking care for EVERY character of this kind of code!