Skip to content

Commit

Permalink
Fixing Lint warnings, mostly spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
galelis committed Mar 28, 2018
1 parent 5556028 commit 0947340
Show file tree
Hide file tree
Showing 8 changed files with 10,358 additions and 237 deletions.
10,124 changes: 10,124 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/Line3.js
Expand Up @@ -130,22 +130,22 @@ class Line3 {
}

intersectLine (line) {
// http://stackoverflow.com/questions/2316490/the-algorithm-to-find-the-point-of-intersection-of-two-3d-line-segment/10288710#10288710
// http://stackoverflow.com/questions/2316490/the-algorithm-to-find-the-point-of-intersection-of-two-3d-line-segment/10288710#10288710
const da = this.end.clone().sub(this.start);
const db = line.end.clone().sub(line.start);
const dc = line.start.clone().sub(this.start);

const daCrossDb = da.clone().cross(db);
const dcCrossDb = dc.clone().cross(db);

// Lines are not coplanar, stop here
if (dc.dot(da) === 0) {
// Lines are not coplanar, stop here
return;
}

const s = dcCrossDb.dot(daCrossDb) / daCrossDb.lengthSq();

// Make sure we have an intersection
// Make sure we have an intersection
if (s > 1.0 || isNaN(s)) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/index.js
@@ -1,9 +1,9 @@
export { default as Line3 } from './Line3.js';
export { default as lineSegment } from './lineSegment.js';
export { clamp,
degToRad,
radToDeg,
sign } from './math.js';
degToRad,
radToDeg,
sign } from './math.js';

export { default as Matrix4 } from './matrix4.js';
export { default as Plane } from './plane.js';
Expand Down
47 changes: 24 additions & 23 deletions src/lineSegment.js
@@ -1,6 +1,6 @@
import { sign } from './math.js';

// Based on http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
// Based on http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
function sqr (x) {
return x * x;
}
Expand Down Expand Up @@ -51,61 +51,62 @@ function intersectLine (lineSegment1, lineSegment2) {
x4 = lineSegment2.end.x,
y4 = lineSegment2.end.y;

let a1, a2, b1, b2, c1, c2; // Coefficients of line equations
let r1, r2, r3, r4; // Sign values
// Coefficients of line equations
let a1, a2, b1, b2, c1, c2;
// Sign values
let r1, r2, r3, r4;

let denom, num; // Intermediate values
// Intermediate values
let denom, num;

// Compute a1, b1, c1, where line joining points 1 and 2 is "a1 x + b1 y + c1 = 0"
// Compute a1, b1, c1, where line joining points 1 and 2 is "a1 x + b1 y + c1 = 0"
a1 = y2 - y1;
b1 = x1 - x2;
c1 = x2 * y1 - x1 * y2;

// Compute r3 and r4
// Compute r3 and r4
r3 = a1 * x3 + b1 * y3 + c1;
r4 = a1 * x4 + b1 * y4 + c1;

/* Check signs of r3 and r4. If both point 3 and point 4 lie on
* same side of line 1, the line segments do not intersect.
*/
/* Check signs of r3 and r4. If both point 3 and point 4 lie on
* same side of line 1, the line segments do not intersect.
*/

if (r3 !== 0 &&
r4 !== 0 &&
sign(r3) === sign(r4)) {
return;
}

/* Compute a2, b2, c2 */

// Compute a2, b2, c2
a2 = y4 - y3;
b2 = x3 - x4;
c2 = x4 * y3 - x3 * y4;

/* Compute r1 and r2 */

// Compute r1 and r2
r1 = a2 * x1 + b2 * y1 + c2;
r2 = a2 * x2 + b2 * y2 + c2;

/* Check signs of r1 and r2. If both point 1 and point 2 lie
* on same side of second line segment, the line segments do
* not intersect.
*/
/* Check signs of r1 and r2. If both point 1 and point 2 lie
* on same side of second line segment, the line segments do
* not intersect.
*/

if (r1 !== 0 &&
r2 !== 0 &&
sign(r1) === sign(r2)) {
return;
}

/* Line segments intersect: compute intersection point.
*/
/* Line segments intersect: compute intersection point.
*/

denom = (a1 * b2) - (a2 * b1);

/* The denom/2 is to get rounding instead of truncating. It
* is added or subtracted to the numerator, depending upon the
* sign of the numerator.
*/
/* The denom/2 is to get rounding instead of truncating. It
* is added or subtracted to the numerator, depending upon the
* sign of the numerator.
*/

num = (b1 * c2) - (b2 * c1);
const x = parseFloat(num / denom);
Expand Down
34 changes: 15 additions & 19 deletions src/matrix4.js
Expand Up @@ -4,8 +4,8 @@ import Vector3 from './vector3.js';
const Matrix4 = function Matrix4 (n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) {
this.elements = new Float32Array(16);

// TODO: if n11 is undefined, then just set to identity, otherwise copy all other values into matrix
// We should not support semi specification of Matrix4, it is just weird.
// TODO: if n11 is undefined, then just set to identity, otherwise copy all other values into matrix
// We should not support semi specification of Matrix4, it is just weird.

const te = this.elements;

Expand Down Expand Up @@ -47,12 +47,12 @@ Matrix4.prototype.makeRotationFromQuaternion = function (q) {
te[6] = yz + wx;
te[10] = 1 - (xx + yy);

// Last column
// Last column
te[3] = 0;
te[7] = 0;
te[11] = 0;

// Bottom row
// Bottom row
te[12] = 0;
te[13] = 0;
te[14] = 0;
Expand Down Expand Up @@ -137,7 +137,7 @@ Matrix4.prototype.multiply = function (m, n) {

Matrix4.prototype.getInverse = function (m, throwOnInvertible) {

// Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
// Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
const te = this.elements;
const me = m.elements;

Expand Down Expand Up @@ -238,13 +238,11 @@ Matrix4.prototype.applyToVector3Array = function () {
Matrix4.prototype.makeTranslation = function (x, y, z) {

this.set(

1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1

);
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1
);

return this;

Expand Down Expand Up @@ -277,13 +275,11 @@ Matrix4.prototype.set = function (n11, n12, n13, n14, n21, n22, n23, n24, n31, n
Matrix4.prototype.makeScale = function (x, y, z) {

this.set(

x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1

);
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1
);

return this;

Expand Down
18 changes: 9 additions & 9 deletions src/plane.js
Expand Up @@ -37,7 +37,8 @@ Plane.prototype = {
setFromNormalAndCoplanarPoint (normal, point) {

this.normal.copy(normal);
this.constant = -point.dot(this.normal); // Must be this.normal, not normal, as this.normal is normalized
// Must be this.normal, not normal, as this.normal is normalized
this.constant = -point.dot(this.normal);

return this;

Expand All @@ -52,7 +53,7 @@ Plane.prototype = {

const normal = v1.subVectors(c, b).cross(v2.subVectors(a, b)).normalize();

// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?

this.setFromNormalAndCoplanarPoint(normal, a);

Expand All @@ -74,7 +75,7 @@ Plane.prototype = {

normalize () {

// Note: will lead to a divide by zero if the plane is invalid.
// Note: will lead to a divide by zero if the plane is invalid.

const inverseNormalLength = 1.0 / this.normal.length();

Expand Down Expand Up @@ -125,7 +126,7 @@ Plane.prototype = {

isIntersectionLine (line) {

// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.

const startSign = this.distanceToPoint(line.start);
const endSign = this.distanceToPoint(line.end);
Expand All @@ -148,14 +149,14 @@ Plane.prototype = {

if (denominator === 0) {

// Line is coplanar, return origin
// Line is coplanar, return origin
if (this.distanceToPoint(line.start) === 0) {

return result.copy(line.start);

}

// Unsure if this is the correct method to handle this case.
// Unsure if this is the correct method to handle this case.
return undefined;

}
Expand All @@ -175,16 +176,15 @@ Plane.prototype = {
})(),

intersectPlane (targetPlane) {
// Returns the intersection line between two planes
// Returns the intersection line between two planes
const direction = this.normal.clone().cross(targetPlane.normal);
const origin = new Vector3();
const intersectionData = {
origin,
direction
};

// If the planes are parallel, return an empty vector for the
// Intersection line
// If the planes are parallel, return an empty vector for the intersection line
if (this.normal.clone().cross(targetPlane.normal).length < 1e-10) {
intersectionData.direction = new Vector3();

Expand Down

0 comments on commit 0947340

Please sign in to comment.