line-segment-ops
v1.0.1
Published
Set Theory and Topological Relationships on Line Segments
Downloads
3
Readme
line-segment-ops
Set Theory and Topological Relationships on Line Segments
Installation
Install with npm.
npm install --save line-segment-ops
Examples
Create Interval
Interval = require('line-interval-ops')
i = new Interval("1,2") #from string
i = new Interval("1 2") #from string
i = new Interval("1;2") #from string
i = new Interval([1,2]) #from array
i = new Interval from: 1, to:2 #object
i = new Interval start: 1, end:2 #object
i = new Interval a: 1, b:2 #object
i = new Interval(1,2) #from two numbers
##Spatial Relationships
I = require('line-interval-ops')
I(2, 8).within(I(1, 10)) #true
I(2, 8).within(I(1, 10)) #false, endpoints touching
I(1,1) #degenerate => true
I(2, 8).within(I(1, 10)) #disjoint => true
#Set Operations
Union
I(1, 10).union I(6, 13), I(3, 9)
# => I(1, 13)
I(1, 10).union I(12, 15)
# => [I(1, 10), I(12, 15)]
XOR
I(1, 10).xor I(6, 12)
# => [ I(1, 6), I(10, 12)]
API
Class | Summary ------| ------------ Interval | The Interval class represents a line segment on the the number line.
IntervalCLASS
<tr>
<td><code>:: <b>a</b> </code></td>
<td width="8%" align="center"><sub>public</sub></td>
<td width="8%" align="center"><sub>instance</sub></td>
<td width="8%" align="center"><sub><a href="#class-Interval">Interval</a></sub></td>
</tr>
</td>
<tr>
<td><code>:: <b>b</b> </code></td>
<td width="8%" align="center"><sub>public</sub></td>
<td width="8%" align="center"><sub>instance</sub></td>
<td width="8%" align="center"><sub><a href="#class-Interval">Interval</a></sub></td>
</tr>
</td>
<tr>
<td><code>:: <b>degenerate</b> </code></td>
<td width="8%" align="center"><sub>public</sub></td>
<td width="8%" align="center"><sub>instance</sub></td>
<td width="8%" align="center"><sub><a href="#class-Interval">Interval</a></sub></td>
</tr>
</td>
<p>Creates a immutable <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> object</p>
</td>
<p>Checks if this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> contains the other.</p>
<p> <em>Returns</em></p>
</td>
<p>Checks if this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> overlaps another.</p>
<p> <em>Returns</em></p>
</td>
<p>Checks if this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> is fully within another.</p>
<p> <em>Returns</em></p>
</td>
<p>Checks if this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> touches anothe.</p>
<p> <em>Returns</em></p>
</td>
<p>Checks if this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> is <code>disjoint</code> with another.</p>
<p> <em>Returns</em></p>
</td>
<p>Calculates the union of the given `{Intervals}`</p>
<p> <em>Returns</em></p>
</td>
<p>Calculates the intersection, i.e. the points where they concur.</p>
<p> <em>Returns</em></p>
</td>
<p>Calculates the difference between this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a> and another.</p>
<p> <em>Returns</em></p>
</td>
<p>Compute an XOR with the given <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a></p>
<p> <em>Returns</em></p>
</td>
<p>Check if both <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a>s are equal.</p>
<p> <em>Returns</em></p>
</td>
<p>Get a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a> representation of this <a href="https://github.com/venkatperi/line-segment-ops/blob/v1.0.0/lib/Interval.coffee#L20">Interval</a></p>
</td>