New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bedard/math

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedard/math - npm Package Compare versions

Comparing version 0.7.0 to 0.8.0

src/functions/rotateMatrix.spec.ts

5

CHANGELOG.md
# Changelog
## 0.8.0
- [`rotateMatrix`](https://github.com/scottbedard/math#rotateMatrix)
- `rotate` -> [`rotateVector`](https://github.com/scottbedard/math#rotateVector)
## 0.7.0

@@ -4,0 +9,0 @@

10

dist/index.bundle.d.ts

@@ -114,5 +114,9 @@ /**

/**
* Rotate a square matrix.
*/
declare function rotateMatrix<T>(matrix: T[], rotations: number): T[];
/**
* Rotate a vector counter-clockwise around the origin.
*/
declare function rotate([x, y]: Vector2, degrees: number): Vector2;
declare function rotateVector([x, y]: Vector2, degrees: number): Vector2;
/**

@@ -140,3 +144,3 @@ * Chunk a matrix into rows.

declare function slope(v1: Vector2, v2: Vector2): number;
declare const version = "0.7.0";
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotate, rows, slope, Vector2, Line2, version };
declare const version = "0.8.0";
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotateMatrix, rotateVector, rows, slope, Vector2, Line2, version };

@@ -1,2 +0,2 @@

var BedardMath=function(n){"use strict";function t(n){return n*Math.PI/180}function r(n,t,r){return n*(1-r)+t*r}function e(n){return n[0].map(((t,r)=>n.map((n=>n[r]))))}function o(n){const t=Math.sqrt(n.length);return new Array(t).fill(0).map(((r,e)=>{const o=e*t;return n.slice(o,o+t)}))}function u(n){return n.reduce(((n,t)=>n.concat(t)),[])}function i(n,t){return t?[n,t]:n}function c(n,t){const[[r,e],[o,u]]=i(n,t);return(u-e)/(o-r)}function s([n,r],e){const o=t(e),u=Math.cos(o),i=Math.sin(o);return[n*u-r*i,n*i+r*u]}return n.angleFrom=function([n,r],e,o){const u=t(e);return[o*Math.cos(u)+n,o*Math.sin(u)+r]},n.bilerp=function([n,t],[e,o],u){return[r(n,e,u),r(t,o,u)]},n.cols=function(n){return e(o(n))},n.degreesToRadians=t,n.flattenCols=function(n){return u(e(n))},n.flattenRows=u,n.flip=e,n.intersect=function([n,t],[r,e]){const[o,u]=n,[i,s]=r,a=c(n,t),f=c(r,e);if(a===f)return;const l=s-f*i;if(!isFinite(a))return[o,f*o+l];const h=u-a*o;if(!isFinite(f))return[i,a*i+h];const p=(l-h)/(a-f);return[p,a*p+h]},n.isEven=function(n){return n%2==0},n.lerp=r,n.measure=function(n,t){const[[r,e],[o,u]]=i(n,t);return Math.sqrt(Math.pow(r-o,2)+Math.pow(e-u,2))},n.polygon=function(n,t=1){return new Array(n).fill(null).map(((r,e)=>s([0,t],360/n*e)))},n.radiansToDegrees=function(n){return 180*n/Math.PI},n.rotate=s,n.rows=o,n.slope=c,n.version="0.7.0",Object.defineProperty(n,"__esModule",{value:!0}),n}({});
var BedardMath=function(n){"use strict";function t(n){return n*Math.PI/180}function r(n,t,r){return n*(1-r)+t*r}function e(n){return n[0].map(((t,r)=>n.map((n=>n[r]))))}function o(n){const t=Math.sqrt(n.length);return new Array(t).fill(0).map(((r,e)=>{const o=e*t;return n.slice(o,o+t)}))}function u(n){return e(o(n))}function i(n){return n.reduce(((n,t)=>n.concat(t)),[])}function c(n){return i(e(n))}function s(n,t){return t?[n,t]:n}function a(n,t){const[[r,e],[o,u]]=s(n,t);return(u-e)/(o-r)}function f([n,r],e){const o=t(e),u=Math.cos(o),i=Math.sin(o);return[n*u-r*i,n*i+r*u]}return n.angleFrom=function([n,r],e,o){const u=t(e);return[o*Math.cos(u)+n,o*Math.sin(u)+r]},n.bilerp=function([n,t],[e,o],u){return[r(n,e,u),r(t,o,u)]},n.cols=u,n.degreesToRadians=t,n.flattenCols=c,n.flattenRows=i,n.flip=e,n.intersect=function([n,t],[r,e]){const[o,u]=n,[i,c]=r,s=a(n,t),f=a(r,e);if(s===f)return;const l=c-f*i;if(!isFinite(s))return[o,f*o+l];const M=u-s*o;if(!isFinite(f))return[i,s*i+M];const h=(l-M)/(s-f);return[h,s*h+M]},n.isEven=function(n){return n%2==0},n.lerp=r,n.measure=function(n,t){const[[r,e],[o,u]]=s(n,t);return Math.sqrt(Math.pow(r-o,2)+Math.pow(e-u,2))},n.polygon=function(n,t=1){return new Array(n).fill(null).map(((r,e)=>f([0,t],360/n*e)))},n.radiansToDegrees=function(n){return 180*n/Math.PI},n.rotateMatrix=function(n,t){const r=(t+4)%4;return 1===r?c(o(n).slice().reverse()):2===r?n.slice().reverse():3===r?i(u(n).slice().reverse()):n.slice()},n.rotateVector=f,n.rows=o,n.slope=a,n.version="0.8.0",Object.defineProperty(n,"__esModule",{value:!0}),n}({});
//# sourceMappingURL=index.bundle.js.map

@@ -114,5 +114,9 @@ /**

/**
* Rotate a square matrix.
*/
declare function rotateMatrix<T>(matrix: T[], rotations: number): T[];
/**
* Rotate a vector counter-clockwise around the origin.
*/
declare function rotate([x, y]: Vector2, degrees: number): Vector2;
declare function rotateVector([x, y]: Vector2, degrees: number): Vector2;
/**

@@ -140,3 +144,3 @@ * Chunk a matrix into rows.

declare function slope(v1: Vector2, v2: Vector2): number;
declare const version = "0.7.0";
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotate, rows, slope, Vector2, Line2, version };
declare const version = "0.8.0";
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotateMatrix, rotateVector, rows, slope, Vector2, Line2, version };

@@ -114,5 +114,9 @@ /**

/**
* Rotate a square matrix.
*/
declare function rotateMatrix<T>(matrix: T[], rotations: number): T[];
/**
* Rotate a vector counter-clockwise around the origin.
*/
declare function rotate([x, y]: Vector2, degrees: number): Vector2;
declare function rotateVector([x, y]: Vector2, degrees: number): Vector2;
/**

@@ -140,3 +144,3 @@ * Chunk a matrix into rows.

declare function slope(v1: Vector2, v2: Vector2): number;
declare const version = "0.7.0";
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotate, rows, slope, Vector2, Line2, version };
declare const version = "0.8.0";
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotateMatrix, rotateVector, rows, slope, Vector2, Line2, version };

@@ -175,3 +175,3 @@ /**

*/
function rotate([x, y], degrees) {
function rotateVector([x, y], degrees) {
const radians = degreesToRadians(degrees);

@@ -188,3 +188,3 @@ const cos = Math.cos(radians);

return new Array(sides).fill(null).map((n, i) => {
return rotate([0, circumradius], (360 / sides) * i);
return rotateVector([0, circumradius], (360 / sides) * i);
});

@@ -200,4 +200,21 @@ }

const version = '0.7.0';
/**
* Rotate a square matrix.
*/
function rotateMatrix(matrix, rotations) {
const rotation = (rotations + 4) % 4;
if (rotation === 1) {
return flattenCols(rows(matrix).slice().reverse());
}
if (rotation === 2) {
return matrix.slice().reverse();
}
if (rotation === 3) {
return flattenRows(cols(matrix).slice().reverse());
}
return matrix.slice();
}
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotate, rows, slope, version };
const version = '0.8.0';
export { angleFrom, bilerp, cols, degreesToRadians, flattenCols, flattenRows, flip, intersect, isEven, lerp, measure, polygon, radiansToDegrees, rotateMatrix, rotateVector, rows, slope, version };

@@ -179,3 +179,3 @@ 'use strict';

*/
function rotate([x, y], degrees) {
function rotateVector([x, y], degrees) {
const radians = degreesToRadians(degrees);

@@ -192,3 +192,3 @@ const cos = Math.cos(radians);

return new Array(sides).fill(null).map((n, i) => {
return rotate([0, circumradius], (360 / sides) * i);
return rotateVector([0, circumradius], (360 / sides) * i);
});

@@ -204,4 +204,21 @@ }

const version = '0.7.0';
/**
* Rotate a square matrix.
*/
function rotateMatrix(matrix, rotations) {
const rotation = (rotations + 4) % 4;
if (rotation === 1) {
return flattenCols(rows(matrix).slice().reverse());
}
if (rotation === 2) {
return matrix.slice().reverse();
}
if (rotation === 3) {
return flattenRows(cols(matrix).slice().reverse());
}
return matrix.slice();
}
const version = '0.8.0';
exports.angleFrom = angleFrom;

@@ -220,5 +237,6 @@ exports.bilerp = bilerp;

exports.radiansToDegrees = radiansToDegrees;
exports.rotate = rotate;
exports.rotateMatrix = rotateMatrix;
exports.rotateVector = rotateVector;
exports.rows = rows;
exports.slope = slope;
exports.version = version;

@@ -39,3 +39,3 @@ {

"unpkg": "dist/index.bundle.js",
"version": "0.7.0"
"version": "0.8.0"
}

@@ -42,3 +42,4 @@ # `@bedard/math`

- [`radiansToDegrees`](#radiansToDegrees)
- [`rotate`](#rotate)
- [`rotateMatrix`](#rotateMatrix)
- [`rotateVector`](#rotateVector)
- [`rows`](#rows)

@@ -197,10 +198,24 @@ - [`slope`](#slope)

### `rotate`
### `rotateMatrix`
Rotate a square matrix. Positive values apply clockwise rotations.
```js
import { rotateMatrix } from '@bedard/math'
rotateMatrix([
0, 1, 2,
3, 4, 5,
6, 7, 8,
], 1) // [6, 3, 0, 7, 4, 1, 8, 5, 2]
```
### `rotateVector`
Rotate a vector counter-clockwise around the origin.
```js
import { rotate } from '@bedard/math'
import { rotateVector } from '@bedard/math'
rotate([0, 1], 90) // [-1, 0] (approximate)
rotateVector([0, 1], 90) // [-1, 0] (approximate)
```

@@ -207,0 +222,0 @@

@@ -1,2 +0,2 @@

import { rotate } from './rotate'
import { rotateVector } from './rotateVector'
import { Vector2 } from '..'

@@ -9,4 +9,4 @@

return new Array(sides).fill(null).map((n, i) => {
return rotate([0, circumradius], (360 / sides) * i)
return rotateVector([0, circumradius], (360 / sides) * i)
})
}

@@ -14,3 +14,4 @@ export { angleFrom } from './functions/angleFrom'

export { radiansToDegrees } from './functions/radiansToDegrees'
export { rotate } from './functions/rotate'
export { rotateMatrix } from './functions/rotateMatrix'
export { rotateVector } from './functions/rotateVector'
export { rows } from './functions/rows'

@@ -20,2 +21,2 @@ export { slope } from './functions/slope'

export const version = '0.7.0'
export const version = '0.8.0'

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc