Skip to content

Commit e2fd7cc

Browse files
author
DD Liu
committed
Fix syntax and bump the error allowance
1 parent 0ae9cdd commit e2fd7cc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Drawable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const log = require('./util/log');
1313
* @type {twgl.v3}
1414
*/
1515
const __isTouchingPosition = twgl.v3.create();
16+
const FLOATING_POINT_ERROR_ALLOWANCE = 1e-6;
1617

1718
/**
1819
* Convert a scratch space location into a texture space float. Uses the
@@ -37,6 +38,10 @@ const getLocalPosition = (drawable, vec) => {
3738
// localPosition matches that transformation.
3839
localPosition[0] = 0.5 - (((v0 * m[0]) + (v1 * m[4]) + m[12]) / d);
3940
localPosition[1] = (((v0 * m[1]) + (v1 * m[5]) + m[13]) / d) + 0.5;
41+
// Fix floating point issues near 0.
42+
// TODO: Check if this can be removed after render pull 479 is merged
43+
if (Math.abs(localPosition[0]) < FLOATING_POINT_ERROR_ALLOWANCE) localPosition[0] = 0;
44+
if (Math.abs(localPosition[1]) < FLOATING_POINT_ERROR_ALLOWANCE) localPosition[1] = 0;
4045
// Apply texture effect transform if the localPosition is within the drawable's space,
4146
// and any effects are currently active.
4247
if (drawable.enabledEffects !== 0 &&

0 commit comments

Comments
 (0)