diff --git a/src/line.ts b/src/line.ts index bca11ac..277ef12 100755 --- a/src/line.ts +++ b/src/line.ts @@ -144,6 +144,11 @@ export class Line implements GeoShape { return this.shift(p.x, p.y); } + /** Reverse the line's start and end points. */ + flip() { + return this.make(this.p2, this.p1) + } + equals(other: Line, tolerance?: number) { // Note: Checking line types breaks some applications in Mathigon textbooks. // if (other.type !== 'line') return false; diff --git a/test/line-test.ts b/test/line-test.ts index f0a865a..dd92fa0 100644 --- a/test/line-test.ts +++ b/test/line-test.ts @@ -42,3 +42,12 @@ tape('line intercepts', (test) => { test.end(); }); + +tape('flip', (test) => { + const a = new Line(new Point(1, 1), new Point(2, 2)); + const b = a.flip(); + test.equals(b.p1, a.p2); + test.equals(b.p2, a.p1); + + test.end(); +}); \ No newline at end of file