Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
43081j committed Feb 18, 2021
1 parent 6ecebf4 commit eec7c5c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class RoughCanvas {
this.gen = new RoughGenerator(config);
}

draw(drawable: Drawable) {
draw(drawable: Drawable): void {
const sets = drawable.sets || [];
const o = drawable.options || this.getDefaultOptions();
const ctx = this.ctx;
Expand All @@ -33,12 +33,14 @@ export class RoughCanvas {
ctx.restore();
break;
case 'fillPath':
{
ctx.save();
ctx.fillStyle = o.fill || '';
const fillRule: CanvasFillRule = (drawable.shape === 'curve' || drawable.shape === 'polygon') ? 'evenodd' : 'nonzero';
this._drawToContext(ctx, drawing, fillRule);
ctx.restore();
break;
}
case 'fillSketch':
this.fillSketch(ctx, drawing, o);
break;
Expand Down Expand Up @@ -148,4 +150,4 @@ export class RoughCanvas {
this.draw(drawing);
return drawing;
}
}
}
4 changes: 2 additions & 2 deletions src/fillers/hachure-filler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class HachureFiller implements PatternFiller {
if (d0 > error && d1 > error) {
intersections.push({
point: ip,
distance: d0
distance: d0,
});
}
}
Expand Down Expand Up @@ -110,4 +110,4 @@ export class HachureFiller implements PatternFiller {
return [];
}
}
}
}
6 changes: 3 additions & 3 deletions src/fillers/scan-line-hachure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function straightHachureLines(points: Point[], o: ResolvedOptions): Line[] {
ymin,
ymax: Math.max(p1[1], p2[1]),
x: ymin === p1[1] ? p1[0] : p2[0],
islope: (p2[0] - p1[0]) / (p2[1] - p1[1])
islope: (p2[0] - p1[0]) / (p2[1] - p1[1]),
});
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ function straightHachureLines(points: Point[], o: ResolvedOptions): Line[] {
const ne = activeEdges[nexti].edge;
lines.push([
[Math.round(ce.x), y],
[Math.round(ne.x), y]
[Math.round(ne.x), y],
]);
}
}
Expand All @@ -130,4 +130,4 @@ function straightHachureLines(points: Point[], o: ResolvedOptions): Line[] {
}
}
return lines;
}
}
10 changes: 5 additions & 5 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class RoughGenerator {
seed: 0,
combineNestedSvgPaths: false,
disableMultiStroke: false,
disableMultiStrokeFill: false
disableMultiStrokeFill: false,
};

constructor(config?: Config) {
Expand Down Expand Up @@ -238,15 +238,15 @@ export class RoughGenerator {
d: this.opsToPath(drawing),
stroke: o.stroke,
strokeWidth: o.strokeWidth,
fill: NOS
fill: NOS,
};
break;
case 'fillPath':
path = {
d: this.opsToPath(drawing),
stroke: NOS,
strokeWidth: 0,
fill: o.fill || NOS
fill: o.fill || NOS,
};
break;
case 'fillSketch':
Expand All @@ -269,7 +269,7 @@ export class RoughGenerator {
d: this.opsToPath(drawing),
stroke: o.fill || NOS,
strokeWidth: fweight,
fill: NOS
fill: NOS,
};
}
}
}
4 changes: 2 additions & 2 deletions src/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function orientation(p: Point, q: Point, r: Point) {
}

// Check is p1q1 intersects with p2q2
export function doIntersect(p1: Point, q1: Point, p2: Point, q2: Point) {
export function doIntersect(p1: Point, q1: Point, p2: Point, q2: Point): boolean {
const o1 = orientation(p1, q1, p2);
const o2 = orientation(p1, q1, q2);
const o3 = orientation(p2, q2, p1);
Expand Down Expand Up @@ -123,4 +123,4 @@ export function doIntersect(p1: Point, q1: Point, p2: Point, q2: Point) {
}

return false;
}
}
67 changes: 37 additions & 30 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const helper: RenderHelper = {
randOffset,
randOffsetWithRange,
ellipse,
doubleLineOps: doubleLineFillOps
doubleLineOps: doubleLineFillOps,
};

export function line(x1: number, y1: number, x2: number, y2: number, o: ResolvedOptions): OpSet {
Expand Down Expand Up @@ -48,7 +48,7 @@ export function rectangle(x: number, y: number, width: number, height: number, o
[x, y],
[x + width, y],
[x + width, y + height],
[x, y + height]
[x, y + height],
];
return polygon(points, o);
}
Expand Down Expand Up @@ -94,7 +94,7 @@ export function ellipseWithParams(x: number, y: number, o: ResolvedOptions, elli
}
return {
estimatedPoints: cp1,
opset: { type: 'path', ops: o1 }
opset: { type: 'path', ops: o1 },
};
}

Expand Down Expand Up @@ -295,41 +295,45 @@ function _line(x1: number, y1: number, x2: number, y2: number, o: ResolvedOption
if (move) {
if (overlay) {
ops.push({
op: 'move', data: [
op: 'move',
data: [
x1 + randomHalf(),
y1 + randomHalf()
]
y1 + randomHalf(),
],
});
} else {
ops.push({
op: 'move', data: [
op: 'move',
data: [
x1 + _offsetOpt(offset, o, roughnessGain),
y1 + _offsetOpt(offset, o, roughnessGain)
]
y1 + _offsetOpt(offset, o, roughnessGain),
],
});
}
}
if (overlay) {
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
midDispX + x1 + (x2 - x1) * divergePoint + randomHalf(),
midDispY + y1 + (y2 - y1) * divergePoint + randomHalf(),
midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomHalf(),
midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomHalf(),
x2 + randomHalf(),
y2 + randomHalf()
]
y2 + randomHalf(),
],
});
} else {
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
midDispX + x1 + (x2 - x1) * divergePoint + randomFull(),
midDispY + y1 + (y2 - y1) * divergePoint + randomFull(),
midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomFull(),
midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomFull(),
x2 + randomFull(),
y2 + randomFull()
]
y2 + randomFull(),
],
});
}
return ops;
Expand Down Expand Up @@ -382,10 +386,12 @@ function _curve(points: Point[], closePoint: Point | null, o: ResolvedOptions):
} else if (len === 3) {
ops.push({ op: 'move', data: [points[1][0], points[1][1]] });
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
points[1][0], points[1][1],
points[2][0], points[2][1],
points[2][0], points[2][1]]
points[2][0], points[2][1],
],
});
} else if (len === 2) {
ops.push(..._doubleLine(points[0][0], points[0][1], points[1][0], points[1][1], o));
Expand All @@ -400,27 +406,27 @@ function _computeEllipsePoints(increment: number, cx: number, cy: number, rx: nu

allPoints.push([
_offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment)
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment),
]);
for (let angle = radOffset; angle < (Math.PI * 2 + radOffset - 0.01); angle = angle + increment) {
const p: Point = [
_offsetOpt(offset, o) + cx + rx * Math.cos(angle),
_offsetOpt(offset, o) + cy + ry * Math.sin(angle)
_offsetOpt(offset, o) + cy + ry * Math.sin(angle),
];
corePoints.push(p);
allPoints.push(p);
}
allPoints.push([
_offsetOpt(offset, o) + cx + rx * Math.cos(radOffset + Math.PI * 2 + overlap * 0.5),
_offsetOpt(offset, o) + cy + ry * Math.sin(radOffset + Math.PI * 2 + overlap * 0.5)
_offsetOpt(offset, o) + cy + ry * Math.sin(radOffset + Math.PI * 2 + overlap * 0.5),
]);
allPoints.push([
_offsetOpt(offset, o) + cx + 0.98 * rx * Math.cos(radOffset + overlap),
_offsetOpt(offset, o) + cy + 0.98 * ry * Math.sin(radOffset + overlap)
_offsetOpt(offset, o) + cy + 0.98 * ry * Math.sin(radOffset + overlap),
]);
allPoints.push([
_offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset + overlap * 0.5),
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset + overlap * 0.5)
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset + overlap * 0.5),
]);

return [allPoints, corePoints];
Expand All @@ -431,21 +437,21 @@ function _arc(increment: number, cx: number, cy: number, rx: number, ry: number,
const points: Point[] = [];
points.push([
_offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment)
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment),
]);
for (let angle = radOffset; angle <= stp; angle = angle + increment) {
points.push([
_offsetOpt(offset, o) + cx + rx * Math.cos(angle),
_offsetOpt(offset, o) + cy + ry * Math.sin(angle)
_offsetOpt(offset, o) + cy + ry * Math.sin(angle),
]);
}
points.push([
cx + rx * Math.cos(stp),
cy + ry * Math.sin(stp)
cy + ry * Math.sin(stp),
]);
points.push([
cx + rx * Math.cos(stp),
cy + ry * Math.sin(stp)
cy + ry * Math.sin(stp),
]);
return _curve(points, null, o);
}
Expand All @@ -463,12 +469,13 @@ function _bezierTo(x1: number, y1: number, x2: number, y2: number, x: number, y:
}
f = [x + _offsetOpt(ros[i], o), y + _offsetOpt(ros[i], o)];
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
x1 + _offsetOpt(ros[i], o), y1 + _offsetOpt(ros[i], o),
x2 + _offsetOpt(ros[i], o), y2 + _offsetOpt(ros[i], o),
f[0], f[1]
]
f[0], f[1],
],
});
}
return ops;
}
}
4 changes: 2 additions & 2 deletions src/rough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default {

newSeed(): number {
return RoughGenerator.newSeed();
}
};
},
};

0 comments on commit eec7c5c

Please sign in to comment.