zoom-image-data
Advanced tools
Comparing version 1.0.0 to 2.0.0
interface param { | ||
/** Input Data */ | ||
inData: Uint8Array | Uint8ClampedArray; | ||
inData: ArrayBuffer; | ||
/** Width of input data */ | ||
@@ -9,3 +9,3 @@ inw: number; | ||
/** Output Data */ | ||
outData: Uint8Array | Uint8ClampedArray; | ||
outData: ArrayBuffer; | ||
/** Width of output data */ | ||
@@ -88,4 +88,12 @@ outw: number; | ||
*/ | ||
updateMatrix(scale: number, dx: number, dy: number, silent?: boolean): void; | ||
/** | ||
* Update the transformation matrix. | ||
*/ | ||
updateInvMatrix(): void; | ||
inCoorIsIn(x: number, y: number): boolean; | ||
outCoorIsIn(x: number, y: number): boolean; | ||
transInToOut(coors: number[]): number[]; | ||
transOutToIn(coors: number[]): number[]; | ||
} | ||
export { ZoomImageData }; |
@@ -16,5 +16,5 @@ (function (factory) { | ||
const { inData, inw, inh, outData, outw, outh, cellRatio } = param; | ||
this.inData = new Uint32Array(inData.buffer); | ||
this.inData = new Uint32Array(inData); | ||
this.inw = inw; | ||
this.outData = new Uint32Array(outData.buffer); | ||
this.outData = new Uint32Array(outData); | ||
this.inh = inh; | ||
@@ -68,6 +68,3 @@ this.outw = outw; | ||
translate(dx, dy, silent) { | ||
this.dx += dx; | ||
this.dy += dy; | ||
this.updateInvMatrix(); | ||
silent || this.update(); | ||
this.updateMatrix(this.scale, this.dx + dx, this.dy + dy, silent); | ||
} | ||
@@ -83,7 +80,3 @@ /** | ||
const { dx, dy, scale } = this; | ||
this.dx = (dx - cx) * ratio + cx; | ||
this.dy = (dy - cy) * ratio + cy; | ||
this.scale = scale * ratio; | ||
this.updateInvMatrix(); | ||
silent || this.update(); | ||
this.updateMatrix(scale * ratio, (dx - cx) * ratio + cx, (dy - cy) * ratio + cy, silent); | ||
} | ||
@@ -106,5 +99,11 @@ /** | ||
} | ||
this.updateMatrix(scale, (outw - zoomw * scale) / 2, (outh - zoomh * scale) / 2, silent); | ||
} | ||
/** | ||
* Update the transformation matrix. | ||
*/ | ||
updateMatrix(scale, dx, dy, silent) { | ||
this.scale = scale; | ||
this.dx = (outw - zoomw * scale) / 2; | ||
this.dy = (outh - zoomh * scale) / 2; | ||
this.dx = dx; | ||
this.dy = dy; | ||
this.updateInvMatrix(); | ||
@@ -121,4 +120,29 @@ silent || this.update(); | ||
} | ||
inCoorIsIn(x, y) { | ||
const { inw, inh } = this; | ||
return x >= 0 && x < inw && y >= 0 && y < inh; | ||
} | ||
outCoorIsIn(x, y) { | ||
const { outw, outh } = this; | ||
return x >= 0 && x < outw && y >= 0 && y < outh; | ||
} | ||
transInToOut(coors) { | ||
const { scale, dx, dy, cellW, cellH } = this; | ||
const result = []; | ||
for (let i = 1; i < coors.length; i = i + 2) { | ||
// Center | ||
result.push(~~((coors[i - 1] - 0.5) * cellW * scale + dx), ~~((coors[i] - 0.5) * cellH * scale + dy)); | ||
} | ||
return result; | ||
} | ||
transOutToIn(coors) { | ||
const { invScale, invDx, invDy, cellW, cellH } = this; | ||
const result = []; | ||
for (let i = 1; i < coors.length; i = i + 2) { | ||
result.push(~~((coors[i - 1] * invScale + invDx) / cellW), ~~((coors[i] * invScale + invDy) / cellH)); | ||
} | ||
return result; | ||
} | ||
} | ||
exports.ZoomImageData = ZoomImageData; | ||
}); |
{ | ||
"name": "zoom-image-data", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "zoom-image-data", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
8069
240