@@ -19,12 +19,12 @@ let __SilhouetteUpdateCanvas;
19
19
* @param {number } y - y
20
20
* @return {number } Alpha value for x/y position
21
21
*/
22
- const getPoint = ( { _width : width , _height : height , _data : data } , x , y ) => {
22
+ const getPoint = ( { _width : width , _height : height , _colorData : data } , x , y ) => {
23
23
// 0 if outside bouds, otherwise read from data.
24
24
if ( x >= width || y >= height || x < 0 || y < 0 ) {
25
25
return 0 ;
26
26
}
27
- return data [ ( y * width ) + x ] ;
27
+ return data [ ( ( ( y * width ) + x ) * 4 ) + 3 ] ;
28
28
} ;
29
29
30
30
/**
@@ -76,7 +76,6 @@ class Silhouette {
76
76
* The data representing a skin's silhouette shape.
77
77
* @type {Uint8ClampedArray }
78
78
*/
79
- this . _data = null ;
80
79
this . _colorData = null ;
81
80
82
81
this . colorAtNearest = this . colorAtLinear = ( _ , dst ) => dst . fill ( 0 ) ;
@@ -100,16 +99,11 @@ class Silhouette {
100
99
ctx . drawImage ( bitmapData , 0 , 0 , width , height ) ;
101
100
const imageData = ctx . getImageData ( 0 , 0 , width , height ) ;
102
101
103
- this . _data = new Uint8ClampedArray ( imageData . data . length / 4 ) ;
104
102
this . _colorData = imageData . data ;
105
103
// delete our custom overriden "uninitalized" color functions
106
104
// let the prototype work for itself
107
105
delete this . colorAtNearest ;
108
106
delete this . colorAtLinear ;
109
-
110
- for ( let i = 0 ; i < imageData . data . length ; i += 4 ) {
111
- this . _data [ i / 4 ] = imageData . data [ i + 3 ] ;
112
- }
113
107
}
114
108
115
109
/**
@@ -166,7 +160,7 @@ class Silhouette {
166
160
* @return {boolean } If the nearest pixel has an alpha value.
167
161
*/
168
162
isTouchingNearest ( vec ) {
169
- if ( ! this . _data ) return ;
163
+ if ( ! this . _colorData ) return ;
170
164
return getPoint (
171
165
this ,
172
166
Math . floor ( vec [ 0 ] * ( this . _width - 1 ) ) ,
@@ -181,7 +175,7 @@ class Silhouette {
181
175
* @return {boolean } Any of the pixels have some alpha.
182
176
*/
183
177
isTouchingLinear ( vec ) {
184
- if ( ! this . _data ) return ;
178
+ if ( ! this . _colorData ) return ;
185
179
const x = Math . floor ( vec [ 0 ] * ( this . _width - 1 ) ) ;
186
180
const y = Math . floor ( vec [ 1 ] * ( this . _height - 1 ) ) ;
187
181
return getPoint ( this , x , y ) > 0 ||
0 commit comments