Merge pull request #324 from fsih/threshold

Reduce the overlap to .1
This commit is contained in:
DD Liu 2018-03-16 15:07:31 -04:00 committed by GitHub
commit b12a9cde95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View file

@ -82,17 +82,17 @@ const sortItemsByZIndex = function (a, b) {
return null; return null;
}; };
// Expand the size of the path by approx one pixel all around // Expand the size of the path by amount all around
const expandByOne = function (path) { const expandBy = function (path, amount) {
const center = path.position; const center = path.position;
let pathArea = path.area; let pathArea = path.area;
for (const seg of path.segments) { for (const seg of path.segments) {
const halfNorm = seg.point.subtract(center) const delta = seg.point.subtract(center)
.normalize() .normalize()
.divide(2); .multiply(amount);
seg.point = seg.point.add(halfNorm); seg.point = seg.point.add(delta);
// If that made the path area smaller, go the other way. // If that made the path area smaller, go the other way.
if (path.area < pathArea) seg.point = seg.point.subtract(halfNorm.multiply(2)); if (path.area < pathArea) seg.point = seg.point.subtract(delta.multiply(2));
pathArea = path.area; pathArea = path.area;
} }
}; };
@ -112,7 +112,7 @@ export {
HANDLE_RATIO, HANDLE_RATIO,
checkPointsClose, checkPointsClose,
ensureClockwise, ensureClockwise,
expandByOne, expandBy,
getRandomInt, getRandomInt,
getRandomBoolean, getRandomBoolean,
snapDeltaToAngle, snapDeltaToAngle,

View file

@ -1,6 +1,6 @@
import paper from '@scratch/paper'; import paper from '@scratch/paper';
import {getHoveredItem} from '../hover'; import {getHoveredItem} from '../hover';
import {expandByOne} from '../math'; import {expandBy} from '../math';
class FillTool extends paper.Tool { class FillTool extends paper.Tool {
static get TOLERANCE () { static get TOLERANCE () {
@ -104,7 +104,7 @@ class FillTool extends paper.Tool {
this.addedFillItem.data.origItem = hitItem; this.addedFillItem.data.origItem = hitItem;
// This usually fixes it so there isn't a teeny tiny gap in between the fill and the outline // This usually fixes it so there isn't a teeny tiny gap in between the fill and the outline
// when filling in a hole // when filling in a hole
expandByOne(this.addedFillItem); expandBy(this.addedFillItem, .1);
this.addedFillItem.insertAbove(hitItem.parent); this.addedFillItem.insertAbove(hitItem.parent);
} else if (this.fillItem.parent instanceof paper.CompoundPath) { } else if (this.fillItem.parent instanceof paper.CompoundPath) {
this.fillItemOrigColor = hitItem.parent.fillColor; this.fillItemOrigColor = hitItem.parent.fillColor;