All files / src/elements/line LineElement.ts

98.82% Statements 84/85
91.66% Branches 22/24
100% Functions 10/10
98.82% Lines 84/85

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 861x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3055x 3055x 3055x 3055x 3055x 1x 1x 81966x 81966x   81966x 81966x 81966x 81966x 81966x 81966x 73805x 73805x 73805x 73805x 73805x 73805x 73805x 73805x 1x 1x 81966x 1x 1x 81969x 81969x 81969x 41643x 41643x 41643x 41643x 1x 1x 81966x 1x 1x 19x 1x 1x 15x 1x 1x 42360x 1x  
/*----------------------------------------------------------------------+
|    Title:	LineElement.ts                                              |
|    A port of the software Geometry Applet by                          |
|    Author:    David E. Joyce                                          |
|        Department of Mathematics and Computer Science                 |
|        Clark University                                               |
|        Worcester, MA 01610-1477                                       |
|        U.S.A.                                                         |
|                                                                       |
|        http://aleph0.clarku.edu/~djoyce/home.html                     |
|        djoyce@clarku.edu                                              |
|                                                                       |
|    Date:    February, 1996.   Version 2.0.0 May, 1997.                |
|    TypeScript Port: 2019, Nelson Brown, brownnrl@gmail.com            |
|                           https://www.nelsonbrown.net/                |
+----------------------------------------------------------------------*/
 
 
import {PointElement} from "../point/PointElement";
import {GeomElement} from "../GeomElement";
import {SlateCanvas} from "../../Slate";
 
interface ILineElementConstructor {
    A : PointElement;
    B : PointElement;
}
 
export class LineElement extends GeomElement {
    protected _A : PointElement;
 
    get A() : PointElement { return this._A; }
 
    protected _B : PointElement;
    get B() : PointElement { return this._B; }
 
    constructor(ile?: ILineElementConstructor) {
        super();
        this.dimension = 1;
        this._A = ile && ile.A || null;
        this._B = ile && ile.B || null;
    }
 
    public drawEdge(c: HTMLCanvasElement, color?: string): void {
        if (color == null) {
            if (this.shouldHighlight) {
                color = this.edgeHighlightColor;
            } else {
                color = this.edgeColor;
            }
        }
 
        if (color == null) return;
 
        let ctx = c.getContext("2d");
        ctx.fillStyle = color;
        ctx.beginPath();
        ctx.moveTo(this._A.x, this._A.y);
        ctx.lineTo(this._B.x, this._B.y);
        ctx.stroke();
    }
 
    public drawFace(c: SlateCanvas): void {
    }
 
    public drawName(c: SlateCanvas): void {
        if (this.nameColor == null || this.name == null) return;
        if (this._A == null || !this._A.defined()) return;
        if (this._B == null || !this._B.defined()) return;
        const ix = Math.round((this._A.x + this._B.x) / 2);
        const iy = Math.round((this._A.y + this._B.y) / 2);
        this.drawString(ix, iy, c);
    }
 
    public drawVertex(c: SlateCanvas): void {
    }
 
    public rotate(pivot: PointElement, ac: number, as: number): void {
    }
 
    public translate(dx: number, dy: number): void {
    }
 
    public update(): void {
    }
}