Comparing version 0.0.2 to 0.0.3
64
index.js
@@ -22,5 +22,21 @@ void function(){ | ||
function meet_of_lines(a, b){ | ||
if ( ! intersecting(a,b) ) return undefined | ||
if ( equal(a.base, b.base) ) return a.base | ||
var m = a.base.map(function(P1, i){ | ||
return [ | ||
a.vector[i] | ||
, ZERO.sub(b.vector[i]) | ||
] | ||
}) | ||
var inv = M.pinv(m) | ||
//console.log('inv\n', M.drawMatrix(inv)) | ||
var c = a.base.map(function(p1, i){ return b.base[i].sub(p1) }) | ||
//console.log('c\n', c+'') | ||
var p = M.mm(inv, c) | ||
//console.log('p\n', p+'') | ||
var r = a.base.map(function(p1,i){ | ||
return p1.add(p[0].times(a.vector[i])) | ||
}) | ||
return null | ||
return r | ||
} | ||
@@ -38,28 +54,32 @@ | ||
function has(line, point){ | ||
var q = line_from_points(line.base, point) | ||
, d = q.vector.map(function(coeff, idx){ | ||
return coeff.div(line.vector[idx]) | ||
}) | ||
if ( equal(point, line.base) ) return true | ||
var v = vector_from_points(point, line.base) | ||
return S_between_vectors(v, line.vector) == ZERO | ||
} | ||
return same_direction(d) === false ? false : true | ||
function identical(a, b){ | ||
return has(a, b.base) ? same_direction(a,b) : false | ||
} | ||
function same_direction(d){ | ||
return d.reduce(function(c,v){ | ||
return v == INF || v == ORG ? c | ||
: c == undefined ? v | ||
: v != c ? false | ||
: c | ||
}, undefined) | ||
function same_direction(a, b){ | ||
return S_between_vectors(a.vector, b.vector) == ZERO | ||
} | ||
function parallels(a, b){ | ||
var d = a.vector.map(function(coeff, idx){ | ||
return coeff.div(b.vector[idx]) | ||
}) | ||
return same_direction(a, b) ? ! has(a, b.base): false | ||
} | ||
function skew(a, b){ | ||
var v = V.sub(a.base, b.base) | ||
var d = M.mrr([a.vector, b.vector, v]) | ||
return same_direction(d) === false ? false : true | ||
return S_between_vectors(a.vector, b.vector) == ZERO ? false : M.isIdentity(d[0]) | ||
} | ||
function intersecting(a, b){ | ||
if ( a.vector.length < 3 && b.vector.length < 3 ) return true | ||
var v = vector_from_points(a.base, b.base) | ||
var d = M.mrr([a.vector, b.vector, v]) | ||
return S_between_vectors(a.vector, b.vector) == ZERO ? false : ! M.linearlyDependent(d[0]) | ||
} | ||
function perpendiculars(a, b){ | ||
@@ -87,5 +107,9 @@ return V.dot(a.vector, b.vector) == ZERO | ||
, has: u.enslave(has) | ||
, parallelTo: u.enslave(parallels) | ||
, parallel: u.enslave(parallels) | ||
, identical: u.enslave(identical) | ||
, skewing: u.enslave(skew) | ||
, perpendicularTo: u.enslave(perpendiculars) | ||
, intersecting: u.enslave(intersecting) | ||
, toString: u.enslave(lineToString) | ||
}) | ||
@@ -95,3 +119,3 @@ | ||
line: function(){ return line.make.apply(line, arguments) } | ||
, joinLines: line_from_points | ||
, joinPoints: line_from_points | ||
, meetLines: meet_of_lines | ||
@@ -98,0 +122,0 @@ , meetLinePlane: meet_of_line_with_plane |
{ | ||
"name": "mertan", | ||
"description": "geometrical operations", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "index.js", | ||
@@ -16,8 +16,9 @@ "scripts": { | ||
"momentum": "~0.1.3", | ||
"deep-equal": "0.0.0", | ||
"vatrix": "0.0.3" | ||
"deep-equal": "~0.0.0", | ||
"vatrix": "~0.0.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"expect.js": "*" | ||
"expect.js": "*", | ||
"better-stack-traces": "~1.0.0" | ||
}, | ||
@@ -24,0 +25,0 @@ "repository": { |
@@ -0,1 +1,2 @@ | ||
require('better-stack-traces') | ||
var gm = require('../') | ||
@@ -23,6 +24,12 @@ , expect = require('expect.js') | ||
, line3D_1 = gm.line(V([3,6,1]),V([3,-4,-1])) | ||
, line3D_2 = gm.line(V([3,6,1]),V([9,-12,-3])) | ||
, line3D_2 = gm.line(V([-6,18,4]),V([9,-12,-3])) | ||
, line3D_3 = gm.line(V([-1,2,-3]),V([5,-1,2])) | ||
, line3D_4 = gm.line(V([6,-5,4]),V([3,-11,-13])) | ||
, line3D_5 = gm.joinPoints(V([1,4,-2]),V([3,8,6])) | ||
, line3D_6 = gm.joinPoints(V([0,4,8]),V([6,10,-10])) | ||
, line4D_1 = gm.line(V([1,2,-3,-4]),V([35,42,-49,-56])) | ||
, line4D_2 = gm.line(V([9,10,11,12]),V([-13,-14,-7,-8])) | ||
it('checks if point lies on line', function() { | ||
@@ -47,7 +54,6 @@ // check for data mismatch ? | ||
// check for data mismatch ? | ||
expect(line2D_1.parallelTo(line2D_2)).to.be(false) | ||
expect(line2D_3.parallelTo(line2D_4)).to.be(true) | ||
expect(line3D_1.parallelTo(line3D_2)).to.be(true) | ||
expect(line2D_1.parallel(line2D_2)).to.be(false) | ||
expect(line2D_3.parallel(line2D_4)).to.be(true) | ||
expect(gm.line([R(3),R(-2)],[R(4),R(-3)]) | ||
.parallelTo(gm.line([R(0),R(-5,8)],[R(-5,6),R(5,8)]))) | ||
.parallel(gm.line([R(0),R(-5,8)],[R(-5,6),R(5,8)]))) | ||
.to.be(true) | ||
@@ -77,2 +83,25 @@ }) | ||
}) | ||
it('check if lines are identical', function(){ | ||
expect(line3D_1.identical(line3D_2)).to.be(true) | ||
expect(line2D_1.identical(line2D_2)).to.be(false) | ||
}) | ||
it('check if lines are skew', function(){ | ||
expect(line3D_1.skewing(line3D_3)).to.be(true) | ||
expect(line3D_1.skewing(line3D_2)).to.be(false) | ||
}) | ||
it('check if lines are intersecting', function(){ | ||
expect(line2D_1.intersecting(line2D_2)).to.be(true) | ||
expect(line3D_5.intersecting(line3D_6)).to.be(true) | ||
expect(line3D_1.intersecting(line3D_4)).to.be(false) | ||
}) | ||
it('returns meet of two lines', function(){ | ||
expect(gm.meetLines(line2D_1,line2D_2)).to.eql([R(5,2),R(1,4)]) | ||
expect(gm.meetLines(gm.line(V([3,0]),V([1,0])),gm.line(V([0,-3]),V([0,1])))).to.eql([R(0),R(0)]) | ||
expect(gm.meetLines(line3D_5,line3D_6)).to.eql(V([2,6,2])) | ||
expect(gm.meetLines(line4D_1,line4D_2)).to.eql(V([-4,-4,4,4])) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11749
6
205
3
+ Addedvatrix@0.0.6(transitive)
- Removedvatrix@0.0.3(transitive)
Updateddeep-equal@~0.0.0
Updatedvatrix@~0.0.3