import * as d3 from 'd3'; import { Point } from '../types/Point'; import { Path, transformed } from './Path'; class Line extends Path { private readonly _start: Point; private readonly _end: Point; constructor (start: Point, end: Point) { super(); this._start = start; this._end = end; } angleAlong (t: number, x: d3.ScaleLinear, y: d3.ScaleLinear): number { const s = transformed(this._start, x, y); const e = transformed(this._end, x, y); return Math.atan2(s.x - e.x, s.y - e.y); } apply (context: CanvasRenderingContext2D, x: d3.ScaleLinear, y: d3.ScaleLinear): void { const s = transformed(this._start, x, y); const e = transformed(this._end, x, y); context.moveTo(s.x, s.y); context.lineTo(e.x, e.y); } pointAlong (t: number, x: d3.ScaleLinear, y: d3.ScaleLinear): Point { const s = transformed(this._start, x, y); const e = transformed(this._end, x, y); return { x: s.x + t * (e.x - s.x), y: s.y + t * (e.y - s.y) }; } points (): Point[] { return [this._start, this._end]; } } export { Line }