mesh v2 at /v2/mesh
This commit is contained in:
parent
aee9fd6ed7
commit
6566c45f9a
85 changed files with 138198 additions and 1 deletions
56
src2/geo/line.js
Normal file
56
src2/geo/line.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/** Copyright Stewart Allen <sa@grid.space> -- All Rights Reserved */
|
||||
|
||||
export class Line {
|
||||
constructor(p1, p2, key) {
|
||||
if (!key) key = [p1.key, p2.key].join(';');
|
||||
this.p1 = p1;
|
||||
this.p2 = p2;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
length() {
|
||||
return Math.sqrt(this.length2());
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {number} square of length
|
||||
*/
|
||||
length2() {
|
||||
return this.p1.distToSq2D(this.p2);
|
||||
}
|
||||
|
||||
slope() {
|
||||
return base.newSlope(this.p1.slopeTo(this.p2));
|
||||
}
|
||||
|
||||
reverse() {
|
||||
let t = this.p1;
|
||||
this.p1 = this.p2;
|
||||
this.p2 = t;
|
||||
return this;
|
||||
}
|
||||
|
||||
midpoint() {
|
||||
return this.p1.midPointTo(this.p2);
|
||||
}
|
||||
|
||||
isCollinear(line) {
|
||||
let p1 = this.p1,
|
||||
p2 = this.p2,
|
||||
p3 = line.p1,
|
||||
p4 = line.p2,
|
||||
d1x = (p2.x - p1.x),
|
||||
d1y = (p2.y - p1.y),
|
||||
d2x = (p4.x - p3.x),
|
||||
d2y = (p4.y - p3.y);
|
||||
return Math.abs( (d2y * d1x) - (d2x * d1y) ) < 0.0001;
|
||||
}
|
||||
}
|
||||
|
||||
export function newLine(p1, p2, key) {
|
||||
return new Line(p1, p2, key);
|
||||
}
|
||||
|
||||
export function newOrderedLine(p1, p2, key) {
|
||||
return p1.key < p2.key ? newLine(p1,p2,key) : newLine(p2,p1,key);
|
||||
}
|
||||
Loading…
Reference in a new issue