2
0

fixed start and ending vector direction to start and end in parallel

This commit is contained in:
2018-08-23 19:39:07 +02:00
parent 06bc85959a
commit 1e914f8e43
3 changed files with 15 additions and 13 deletions

View File

@@ -74,6 +74,7 @@ export class GraphsComponent implements OnChanges, OnInit {
} }
ngOnInit() { ngOnInit() {
console.log(this.svgElementRef);
this.updateGraphs(); this.updateGraphs();
} }
@@ -104,7 +105,7 @@ export class GraphsComponent implements OnChanges, OnInit {
private updateGraphs(): void { private updateGraphs(): void {
const genShiftStart = this.shiftPoint(this.matrix.start, this.config.vectors.start); const genShiftStart = this.shiftPoint(this.matrix.start, this.config.vectors.start);
const genShiftEnd = this.shiftPoint(this.matrix.end, this.config.vectors.end); const genShiftEnd = this.shiftPoint(this.matrix.end, this.config.vectors.end, false);
const curveList = [ const curveList = [
{ {
@@ -192,9 +193,9 @@ export class GraphsComponent implements OnChanges, OnInit {
}; };
} }
private *shiftPoint(point: Point, vector) { private *shiftPoint(point: Point, vector: number, startPositive: boolean = true) {
const genShiftX = this.shiftNumber(this.config.vectors.spacing, vector); const genShiftX = this.shiftNumber(this.config.vectors.spacing, vector, startPositive);
const genShiftY = this.shiftNumber(this.config.vectors.spacing, vector); const genShiftY = this.shiftNumber(this.config.vectors.spacing, vector, startPositive);
while (true) { while (true) {
yield { yield {
@@ -207,10 +208,10 @@ export class GraphsComponent implements OnChanges, OnInit {
} }
} }
private *shiftNumber(space: number, vector: number) { private *shiftNumber(space: number, vector: number, startPositive: boolean = true) {
let current = 0; let current = 0;
let index = 0; let index = 0;
const sign = this.math.flipSign(); const sign = this.math.flipSign(startPositive);
while (true) { while (true) {
yield current = sign.next().value * index * space + current; yield current = sign.next().value * index * space + current;

View File

@@ -31,7 +31,6 @@ import { CanvasService } from './../services/canvas.service';
import { MathService } from './../services/math.service'; import { MathService } from './../services/math.service';
import { GraphService } from '../services/graph.service'; import { GraphService } from '../services/graph.service';
import { AnimationService } from './../services/animation.service'; import { AnimationService } from './../services/animation.service';
// import { spread } from 'q';
@Directive({ @Directive({
selector: '[guilloche]' selector: '[guilloche]'
@@ -155,15 +154,17 @@ export class GuillocheDirective implements OnChanges, OnDestroy {
} }
private drawGraph(points: Point[]): void { private drawGraph(points: Point[]): void {
this.group
.attr('stroke', this.graph.color)
.attr('stroke-width', this.graph.stroke)
.attr('fill', 'none');
this.pathElements.push( this.pathElements.push(
this.group.append('path') this.group.append('path')
.attr('d', Shape.line() .attr('d', Shape.line()
.x(p => p.x) .x(p => p.x)
.y(p => p.y) .y(p => p.y)
.curve(Shape.curveBasis)(points)) .curve(Shape.curveBasis)(points)));
.attr('stroke', this.graph.color)
.attr('stroke-width', this.graph.stroke)
.attr('fill', 'none'));
if (env.debug) { if (env.debug) {
this.debugGraph(points); this.debugGraph(points);

View File

@@ -149,8 +149,8 @@ export class MathService {
} }
} }
public *flipSign() { public *flipSign(startPositive: boolean = true) {
let sign = 1; let sign = startPositive ? 1 : -1;
while (true) { while (true) {
yield sign = sign * (-1); yield sign = sign * (-1);