-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A better way to avoid aliasing issues is to ensure that during pre-quantization, the fine quantization grid is aligned with the ultimate post-quantization grid.
- Loading branch information
Showing
7 changed files
with
119 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
module.exports = function(bbox, Q) { | ||
var x0 = isFinite(bbox[0]) ? bbox[0] : 0, | ||
y0 = isFinite(bbox[1]) ? bbox[1] : 0, | ||
x1 = isFinite(bbox[2]) ? bbox[2] : 0, | ||
y1 = isFinite(bbox[3]) ? bbox[3] : 0, | ||
kx = x1 - x0 ? (Q - 1) / (x1 - x0) : 1, | ||
ky = y1 - y0 ? (Q - 1) / (y1 - y0) : 1; | ||
module.exports = function(dx, dy, kx, ky) { | ||
|
||
return { | ||
point: function(coordinates) { | ||
coordinates[0] = Math.floor((coordinates[0] - x0) * kx); | ||
coordinates[1] = Math.floor((coordinates[1] - y0) * ky); | ||
}, | ||
line: function(coordinates) { | ||
var i = 0, | ||
j = 1, | ||
n = coordinates.length, | ||
pi = coordinates[0], | ||
pj, | ||
px = pi[0] = Math.floor((pi[0] - x0) * kx), | ||
py = pi[1] = Math.floor((pi[1] - y0) * ky), | ||
x, | ||
y; | ||
function quantizePoint(coordinates) { | ||
coordinates[0] = Math.round((coordinates[0] + dx) * kx); | ||
coordinates[1] = Math.round((coordinates[1] + dy) * ky); | ||
return coordinates; | ||
} | ||
|
||
function quantizeLine(coordinates) { | ||
var i = 0, | ||
j = 1, | ||
n = coordinates.length, | ||
pi = quantizePoint(coordinates[0]), | ||
pj, | ||
px = pi[0], | ||
py = pi[1], | ||
x, | ||
y; | ||
|
||
while (++i < n) { | ||
pi = coordinates[i]; | ||
x = Math.floor((pi[0] - x0) * kx); | ||
y = Math.floor((pi[1] - y0) * ky); | ||
if (x !== px || y !== py) { // skip coincident points | ||
pj = coordinates[j++]; | ||
pj[0] = px = x; | ||
pj[1] = py = y; | ||
} | ||
while (++i < n) { | ||
pi = quantizePoint(coordinates[i]); | ||
x = pi[0]; | ||
y = pi[1]; | ||
if (x !== px || y !== py) { // skip coincident points | ||
pj = coordinates[j++]; | ||
pj[0] = px = x; | ||
pj[1] = py = y; | ||
} | ||
} | ||
|
||
coordinates.length = j; | ||
}, | ||
coordinates.length = j; | ||
} | ||
|
||
return { | ||
point: quantizePoint, | ||
line: quantizeLine, | ||
transform: { | ||
scale: [1 / kx, 1 / ky], | ||
translate: [x0, y0] | ||
translate: [-dx, -dy] | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module.exports = function(dx, dy, kx, ky) { | ||
return { | ||
point: function(coordinates) { | ||
coordinates[0] = Math.floor((coordinates[0] + dx) * kx); | ||
coordinates[1] = Math.floor((coordinates[1] + dy) * ky); | ||
}, | ||
line: function(coordinates) { | ||
var i = 0, | ||
j = 1, | ||
n = coordinates.length, | ||
pi = coordinates[0], | ||
pj, | ||
px = pi[0] = Math.floor((pi[0] + dx) * kx), | ||
py = pi[1] = Math.floor((pi[1] + dy) * ky), | ||
x, | ||
y; | ||
|
||
while (++i < n) { | ||
pi = coordinates[i]; | ||
x = Math.floor((pi[0] + dx) * kx); | ||
y = Math.floor((pi[1] + dy) * ky); | ||
if (x !== px || y !== py) { // skip coincident points | ||
pj = coordinates[j++]; | ||
pj[0] = px = x; | ||
pj[1] = py = y; | ||
} | ||
} | ||
|
||
coordinates.length = j; | ||
}, | ||
transform: { | ||
scale: [1 / kx, 1 / ky], | ||
translate: [x0, y0] | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters