Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] make dot-filler use random number controlled by seed #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/fillers/dot-filler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PatternFiller, RenderHelper } from './filler-interface';
import { ResolvedOptions, OpSet, Op } from '../core';
import { Point, Line, lineLength } from '../geometry';
import { polygonHachureLines } from './scan-line-hachure';
import { Random } from 'src/math';

export class DotFiller implements PatternFiller {
private helper: RenderHelper;
Expand All @@ -17,6 +18,10 @@ export class DotFiller implements PatternFiller {
}

private dotsOnLines(lines: Line[], o: ResolvedOptions): OpSet {
if (!o.randomizer) {
o.randomizer = new Random(o.seed || 0);
}

const ops: Op[] = [];
let gap = o.hachureGap;
if (gap < 0) {
Expand All @@ -38,8 +43,8 @@ export class DotFiller implements PatternFiller {

for (let i = 0; i < count; i++) {
const y = minY + offset + (i * gap);
const cx = (x - ro) + Math.random() * 2 * ro;
const cy = (y - ro) + Math.random() * 2 * ro;
const cx = (x - ro) + o.randomizer.next() * 2 * ro;
const cy = (y - ro) + o.randomizer.next() * 2 * ro;
const el = this.helper.ellipse(cx, cy, fweight, fweight, o);
ops.push(...el.ops);
}
Expand Down