Skip to content

Commit

Permalink
Fix silhouette sampling math
Browse files Browse the repository at this point in the history
  • Loading branch information
adroitwhiz committed Jul 10, 2019
1 parent 69f1eea commit aea28a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/Silhouette.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class Silhouette {
colorAtNearest (vec, dst) {
return getColor4b(
this,
Math.floor(vec[0] * (this._width - 1)),
Math.floor(vec[1] * (this._height - 1)),
Math.round(vec[0] * this._width),
Math.round(vec[1] * this._height),
dst
);
}
Expand All @@ -140,8 +140,8 @@ class Silhouette {
* @returns {Uint8ClampedArray} dst
*/
colorAtLinear (vec, dst) {
const x = vec[0] * (this._width - 1);
const y = vec[1] * (this._height - 1);
const x = vec[0] * this._width;
const y = vec[1] * this._height;

const x1D = x % 1;
const y1D = y % 1;
Expand Down Expand Up @@ -173,8 +173,8 @@ class Silhouette {
if (!this._colorData) return;
return getPoint(
this,
Math.floor(vec[0] * (this._width - 1)),
Math.floor(vec[1] * (this._height - 1))
Math.round(vec[0] * this._width),
Math.round(vec[1] * this._height)
) > 0;
}

Expand All @@ -186,8 +186,8 @@ class Silhouette {
*/
isTouchingLinear (vec) {
if (!this._colorData) return;
const x = Math.floor(vec[0] * (this._width - 1));
const y = Math.floor(vec[1] * (this._height - 1));
const x = Math.round(vec[0] * this._width);
const y = Math.round(vec[1] * this._height);
return getPoint(this, x, y) > 0 ||
getPoint(this, x + 1, y) > 0 ||
getPoint(this, x, y + 1) > 0 ||
Expand Down
3 changes: 2 additions & 1 deletion src/playground/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const canvas = document.getElementById('scratch-stage');
let fudge = 90;
const renderer = new ScratchRender(canvas);
renderer.setLayerGroupOrdering(['group1']);
window.renderer = renderer;

const drawableID = renderer.createDrawable('group1');
renderer.updateDrawableProperties(drawableID, {
Expand Down Expand Up @@ -45,7 +46,7 @@ xhr.addEventListener('load', function () {
});
}
});
xhr.open('GET', 'https://cdn.assets.scratch.mit.edu/internalapi/asset/b7853f557e4426412e64bb3da6531a99.svg/get/');
xhr.open('GET', 'https://cdn.assets.scratch.mit.edu/internalapi/asset/7e4d03ea982f865367dfc821108bf59f.svg/get/');
xhr.send();

if (wantedSkin === WantedSkinType.pen) {
Expand Down

0 comments on commit aea28a5

Please sign in to comment.