@eturnity/eturnity_maths
Advanced tools
Comparing version 7.42.1 to 7.42.2
{ | ||
"name": "@eturnity/eturnity_maths", | ||
"version": "7.42.1", | ||
"version": "7.42.2", | ||
"author": "Eturnity Team", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -80,2 +80,6 @@ import { mmTolerance, polygonCloseTolerance } from './config' | ||
} | ||
export function getAngleInDegFrom2DENUVector(v) { | ||
const angle = Math.atan2(v.y, -v.x) | ||
return ((angle * 180) / Math.PI + 90 + 360) % 360 | ||
} | ||
export function getAngleInDegFromCanvasVector(v) { | ||
@@ -82,0 +86,0 @@ const angle = Math.atan2(v.y, v.x) |
@@ -12,1 +12,2 @@ export * from './coords' | ||
export * from './stats' | ||
export * from './spherical' |
@@ -1,75 +0,86 @@ | ||
import { getNormalVectortoEdgeTowardPolygon} from '../../index' | ||
import { getNormalVectortoEdgeTowardPolygon } from '../../index' | ||
function toBeCloseToVector(received, expected, tolerance = 0.01) { | ||
const recPoint = received | ||
const expPoint = expected | ||
const recPoint = received | ||
const expPoint = expected | ||
if ( | ||
Math.abs(recPoint.x - expPoint.x) > tolerance || | ||
Math.abs(recPoint.y - expPoint.y) > tolerance || | ||
Math.abs(recPoint.z - expPoint.z) > tolerance | ||
) { | ||
return { | ||
message: () => | ||
`Expected points at index ${i} to be close, but found ${JSON.stringify(recPoint)} and ${JSON.stringify(expPoint)}`, | ||
pass: false, | ||
}; | ||
} | ||
if ( | ||
Math.abs(recPoint.x - expPoint.x) > tolerance || | ||
Math.abs(recPoint.y - expPoint.y) > tolerance || | ||
Math.abs(recPoint.z - expPoint.z) > tolerance | ||
) { | ||
return { | ||
message: () => | ||
`Expected points to be close, but found ${JSON.stringify( | ||
recPoint | ||
)} and ${JSON.stringify(expPoint)}`, | ||
pass: false, | ||
} | ||
} | ||
return { | ||
message: () => `Points are close within the given tolerance`, | ||
pass: true, | ||
}; | ||
return { | ||
message: () => `Points are close within the given tolerance`, | ||
pass: true, | ||
} | ||
} | ||
expect.extend({ toBeCloseToVector }) | ||
const A = {x:0,y:0,z:0} | ||
const B = {x:10,y:0,z:0} | ||
const C = {x:10,y:10,z:0} | ||
const D = {x:0,y:10,z:0} | ||
const E = {x:5,y:5,z:0} | ||
const F = {x:2,y:0,z:0} | ||
const G = {x:3,y:-10,z:0} | ||
const H = {x:4,y:0,z:0} | ||
const A = { x: 0, y: 0, z: 0 } | ||
const B = { x: 10, y: 0, z: 0 } | ||
const C = { x: 10, y: 10, z: 0 } | ||
const D = { x: 0, y: 10, z: 0 } | ||
const E = { x: 5, y: 5, z: 0 } | ||
const F = { x: 2, y: 0, z: 0 } | ||
const G = { x: 3, y: -10, z: 0 } | ||
const H = { x: 4, y: 0, z: 0 } | ||
describe('getNormalVectortoEdgeTowardPolygon function', () => { | ||
test('anti-clockwise outline ABCD', () => { | ||
const outline = [A,B,C,D] | ||
const expectedNormalVector={x:0,y:1,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(0,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, B, C, D] | ||
const expectedNormalVector = { x: 0, y: 1, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(0, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
test('clockwise outline', () => { | ||
const outline = [A,D,C,B] | ||
const expectedNormalVector={x:1,y:0,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(0,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, D, C, B] | ||
const expectedNormalVector = { x: 1, y: 0, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(0, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
test('anti clockwise concave outline', () => { | ||
const outline = [A,E,D,C,B] | ||
const expectedNormalVector={x:0,y:-1,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(2,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, E, D, C, B] | ||
const expectedNormalVector = { x: 0, y: -1, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(2, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
test('clockwise concave outline', () => { | ||
const outline = [A,E,B,C,D] | ||
const expectedNormalVector={x:-1,y:0,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(2,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, E, B, C, D] | ||
const expectedNormalVector = { x: -1, y: 0, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(2, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
test('anti-clockwise concave outline', () => { | ||
const outline = [A,E,B,C,D] | ||
const expectedNormalVector={x:-1,y:0,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(2,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, E, B, C, D] | ||
const expectedNormalVector = { x: -1, y: 0, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(2, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
test('clockwise concave outline', () => { | ||
const outline = [A,E,B,C,D] | ||
const expectedNormalVector={x:1,y:0,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(4,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, E, B, C, D] | ||
const expectedNormalVector = { x: 1, y: 0, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(4, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
test('anti-clockwise concave on first outline', () => { | ||
const outline = [A,F,G,B,C,D] | ||
const expectedNormalVector={x:0,y:1,z:0} | ||
expect(getNormalVectortoEdgeTowardPolygon(0,outline)).toBeCloseToVector(expectedNormalVector) | ||
const outline = [A, F, G, B, C, D] | ||
const expectedNormalVector = { x: 0, y: 1, z: 0 } | ||
expect(getNormalVectortoEdgeTowardPolygon(0, outline)).toBeCloseToVector( | ||
expectedNormalVector | ||
) | ||
}) | ||
}); | ||
}) |
195683
45
6547