All files / src/elements/sector ArcElement.ts

100% Statements 71/71
100% Branches 4/4
100% Functions 4/4
100% Lines 71/71

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 721x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 45x 45x 45x 45x 45x 45x 45x 45x 1x 1x 236x 236x 236x 236x 236x 236x 236x 1x 1x 7x 7x 1x 1x 1x 1x 1x  
/*----------------------------------------------------------------------+
|    Title:	ArcElement.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: 2026, Nelson Brown, brownnrl@gmail.com            |
|                           https://www.nelsonbrown.net/                |
+----------------------------------------------------------------------*/
 
import {SectorElement} from "./SectorElement";
import {PointElement} from "../point/PointElement";
import {PlaneElement} from "../plane/PlaneElement";
 
/**
 * Port of geom_applet/source/Arc.java — an arc through three points.
 *
 * Given points A, M, B (with M on the arc between A and B), draws the
 * arc of the unique circle passing through all three. The circle's
 * center is recomputed on every update() as circumcenter(A, M, B) and
 * stored in the inherited _Center field; SectorElement.drawEdge then
 * sweeps the arc from A to B using the inherited angle math.
 *
 * _Center is an internal bare PointElement, not registered on the
 * slate. Arc.update() writes into it directly, so it stays in sync
 * with A, M, B without needing a separate elementsForUpdate entry.
 *
 * translate / rotate are overridden so that grabbing and moving the
 * arc (either via a drag or via a global pivot rotation) perturbs
 * only the inherited _Center; A, M, B are independent slate elements
 * and are moved by their own handlers. This mirrors Java Arc.java
 * exactly — see geom_applet/source/Arc.java lines 19-23.
 */
export class ArcElement extends SectorElement {
 
    _M : PointElement;  // the "through" point on the arc between A and B
 
    constructor(A: PointElement, M: PointElement, B: PointElement, P: PlaneElement) {
        super();
        this.dimension = 2;
        this._Center = new PointElement();
        this._A = A;
        this._M = M;
        this._B = B;
        this._P = P;
    }
 
    update(): void {
        // Java Arc.update() explicitly calls P.update() first. The TS
        // slate already updates elements in dependency order, so this
        // is arguably redundant — but we keep it for parity with Java
        // in case some emergent behavior depends on it.
        this._P.update();
        this._Center.toCircumcenter(this._A, this._M, this._B);
    }
 
    translate(dx: number, dy: number): void {
        this._Center.translate(dx, dy);
    }
 
    rotate(pivot: PointElement, ac: number, as: number): void {
        this._Center.rotate(pivot, ac, as);
    }
}