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
The Interval class represents a line segment on the the number line.
An interval is a connected portion of the real line.
Also see A Small Set of Formal Topological Relationships Suitable for End User Interaction
A couple of definitions:
- The boundary of an Interval is set of its two endpoints.
- The interior of an Interval is the set of all points in the Interval less its boundary (endpoints).
<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>
<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>
<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>
Properties |
|||
Number The start/left endpoint of this Interval
|
|||
Number The end/right endpoint of this Interval
|
|||
Boolean True if this `{Instance}` has the same start and end points
|
|||
Methods |
|||
:: constructor( arg1[, arg2] ) |
public | instance | Interval |
|
|||
:: contains( other ) |
public | instance | Interval |
|
|||
:: overlaps( other ) |
public | instance | Interval |
For two Intervals to overlap they must have some points but not all points.
|
|||
:: within( other ) |
public | instance | Interval |
Interval X is said to be within another Interval Y if X is completely within Y and neither of their endpoints touch.
|
|||
:: touches( other ) |
public | instance | Interval |
Two line segments touch, if:
|
|||
:: disjoint( other ) |
public | instance | Interval |
Two Intervals are disjoint if they have no points in common, i.e. if their intersection is the empty set.
|
|||
:: union( others ) |
public | instance | Interval |
A union of intervals can result in an array of unconnected parts.
|
|||
:: intersection( other ) |
public | instance | Interval |
|
|||
:: difference( other ) |
public | instance | Interval |
The difference between Interval X and Y is all of the points in X which are not in Y.
|
|||
:: xor( other ) |
public | instance | Interval |
The set of elements belonging to one but not both of two given sets. It is therefore the union of the complement of A with respect to B and B with respect to A, and corresponds to the XOR operation in Boolean logic.
|
|||
:: equals( other ) |
public | instance | Interval |
Two intervals are equal if their line segments are equal, i.e same start and end points.
|
|||
:: toString( ) |
public | instance | Interval |
Return String
|
Markdown generated by [atomdoc-md](https://github.com/venkatperi/atomdoc-md).