Skip to content

Commit aea28a5

Browse files
committed
Fix silhouette sampling math
1 parent 69f1eea commit aea28a5

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Silhouette.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ class Silhouette {
126126
colorAtNearest (vec, dst) {
127127
return getColor4b(
128128
this,
129-
Math.floor(vec[0] * (this._width - 1)),
130-
Math.floor(vec[1] * (this._height - 1)),
129+
Math.round(vec[0] * this._width),
130+
Math.round(vec[1] * this._height),
131131
dst
132132
);
133133
}
@@ -140,8 +140,8 @@ class Silhouette {
140140
* @returns {Uint8ClampedArray} dst
141141
*/
142142
colorAtLinear (vec, dst) {
143-
const x = vec[0] * (this._width - 1);
144-
const y = vec[1] * (this._height - 1);
143+
const x = vec[0] * this._width;
144+
const y = vec[1] * this._height;
145145

146146
const x1D = x % 1;
147147
const y1D = y % 1;
@@ -173,8 +173,8 @@ class Silhouette {
173173
if (!this._colorData) return;
174174
return getPoint(
175175
this,
176-
Math.floor(vec[0] * (this._width - 1)),
177-
Math.floor(vec[1] * (this._height - 1))
176+
Math.round(vec[0] * this._width),
177+
Math.round(vec[1] * this._height)
178178
) > 0;
179179
}
180180

@@ -186,8 +186,8 @@ class Silhouette {
186186
*/
187187
isTouchingLinear (vec) {
188188
if (!this._colorData) return;
189-
const x = Math.floor(vec[0] * (this._width - 1));
190-
const y = Math.floor(vec[1] * (this._height - 1));
189+
const x = Math.round(vec[0] * this._width);
190+
const y = Math.round(vec[1] * this._height);
191191
return getPoint(this, x, y) > 0 ||
192192
getPoint(this, x + 1, y) > 0 ||
193193
getPoint(this, x, y + 1) > 0 ||

src/playground/playground.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const canvas = document.getElementById('scratch-stage');
55
let fudge = 90;
66
const renderer = new ScratchRender(canvas);
77
renderer.setLayerGroupOrdering(['group1']);
8+
window.renderer = renderer;
89

910
const drawableID = renderer.createDrawable('group1');
1011
renderer.updateDrawableProperties(drawableID, {
@@ -45,7 +46,7 @@ xhr.addEventListener('load', function () {
4546
});
4647
}
4748
});
48-
xhr.open('GET', 'https://cdn.assets.scratch.mit.edu/internalapi/asset/b7853f557e4426412e64bb3da6531a99.svg/get/');
49+
xhr.open('GET', 'https://cdn.assets.scratch.mit.edu/internalapi/asset/7e4d03ea982f865367dfc821108bf59f.svg/get/');
4950
xhr.send();
5051

5152
if (wantedSkin === WantedSkinType.pen) {

0 commit comments

Comments
 (0)