All files / src/elements/point PointConstructions.ts

100% Statements 630/630
99.23% Branches 130/131
100% Functions 80/80
100% Lines 630/630

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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 6311x 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 1x 1x 1x 1x 3364x 3364x 3364x 3364x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 489x 489x 489x 489x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10816x 10816x 10816x 10816x 1x 271x 271x 271x 271x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 158x 158x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 172x 172x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 58x 58x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 12805x 12805x 12805x 2x 2245x 2245x 2245x 2x 2241x 2241x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5278x 5278x 5278x 5278x 1x 204x 204x 204x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 19202x 19202x 19202x 19202x 2x 374x 374x 374x 374x 2x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 47x 47x 47x 47x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 1x 1x 1x 1x 2x 2x 2x 1016x 1016x 1016x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 532x 532x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 484x 484x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 586x 586x 586x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8888x 98x 8888x 8888x 1x 98x 98x 98x 98x 98x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 203x 203x 203x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 30x 30x 30x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 36x 36x 36x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 488x 488x 488x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 142x 142x 142x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 60x 60x 60x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 127x 127x 127x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 37x 37x 37x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8302x 8x 8302x 8302x 1x 8x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8294x 1x 8294x 8294x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 11986x 11986x 11986x 1x 288x 288x 288x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 27x 27x 27x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 274x 274x 274x 274x 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  
/*----------------------------------------------------------------------+
|    Point construction classes — extracted from Constructions.ts        |
|    Each class maps a (type, constructionName, signature) triple to     |
|    a construct() method that creates the geometry element.             |
+----------------------------------------------------------------------*/
 
import {Construction, ConstructionSignature, SortedParams, AllConstructions, PointConstructions,
        CircleConstructions, GeomElementsForUpdate} from "../Constructions";
import {GeomElement} from "../GeomElement";
import {CircleElement} from "../circle/CircleElement";
import {CircumcircleElement} from "../circle/CircumcircleElement";
import {PlaneElement} from "../plane/PlaneElement";
import {PointElement} from "./PointElement";
import {FixedPoint} from "./FixedPoint";
import {PlaneSlider} from "./PlaneSlider";
import {Midpoint} from "./Midpoint";
import {Intersection} from "./Intersection";
import {PlaneIntersection} from "./PlaneIntersection";
import {LineSlider} from "./LineSlider";
import {Layoff} from "./Layoff";
import {Foot} from "./Foot";
import {PlaneFootElement} from "./PlaneFootElement";
import {CircleSlider} from "./CircleSlider";
import {SimilarElement} from "./SimilarElement";
import {ProportionElement} from "./ProportionElement";
import {AngleDividerElement} from "./AngleDividerElement";
import {MeanProportionalElement} from "./MeanProportionalElement";
import {HarmonicElement} from "./HarmonicElement";
import {InvertPointElement} from "./InvertPointElement";
import {SphereSliderElement} from "./SphereSliderElement";
import {Perpendicular} from "../line/Perpendicular";
import {PlanePerpendicularLine} from "../line/PlanePerpendicularLine";
import {SphereElement} from "../sphere/SphereElement";
import {PolygonElement} from "../polygon/PolygonElement";
 
/***********************
 * Element Class Point *
 ***********************/
 
/* point
 * free
 * integers x, y
 * a freely dragable point in the screen plane with initial coordinates (x,y,0)
 * (Java: Slate.java point case 0 — new PlaneSlider(screen, x, y, 0))
 */
export class FreePointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.free;
    signature: ConstructionSignature = { points: 0, elements: 0, integers: 2 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new PlaneSlider(screen, N[0], N[1], 0);
 
        return [[g], g];
    }
 
}
 
// point
// midpoint
// points A, B
// the midpoint of a line AB
// (Java: Slate.java point case 1 — new Midpoint(A, B))
export class MidPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.midpoint;
    signature: ConstructionSignature = { points: 2, elements: 0, integers: 0 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new Midpoint(P[0], P[1]);
 
        return [[g], g];
    }
}
 
// point
// intersection
// points A, B, C, D [, plane E = screen]
// the intersection of two lines AB and CD in the plane E
// (Java: Slate.java point case 2 — new Intersection(A,B,C,D,E))
export class IntersectionConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.intersection;
    signature: ConstructionSignature = { points: 4, elements: 0, integers: 0 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 4 && sp.N.length === 0
            && (sp.E.length === 0 || (sp.E.length === 1 && sp.E[0] instanceof PlaneElement));
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let plane = E.length > 0 ? E[0] as PlaneElement : screen;
        let g = new Intersection(P[0], P[1], P[2], P[3], plane);
        return [[g], g];
    }
}
 
// point
// intersection (plane-line variant)
// plane A, points B, C
// the intersection of the plane A and the line BC
// (Java: IntersectionPL.java — TS: PlaneIntersection.ts, renamed for clarity)
export class PlaneIntersectionConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.intersection;
    signature: ConstructionSignature = { points: 2, elements: 1, integers: 0, elementTypes: [PlaneElement] };
 
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const g = new PlaneIntersection(E[0] as PlaneElement, P[0], P[1]);
        return [[g], g];
    }
}
 
// point
// first
// points A, B
// the first end A of the line AB
// (Java: Slate.java point case 3 — returns P[0], preexists=true)
export class FirstPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.first;
    signature: ConstructionSignature = { points: 2, elements: 0, integers: 0 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        return [[], P[0]];
    }
 
}
 
// point
// last
// points A, B
// the last end B of the line AB
// (Java: Slate.java point case 4 — returns P[1], preexists=true)
export class LastPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.last;
    signature: ConstructionSignature = { points: 2, elements: 0, integers: 0 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        return [[], P[1]];
    }
}
 
// point
// center
// circle A
// the center of the circle A
// (Java: Slate.java point case 5, choice 0 — returns ((CircleElement)E[0]).Center)
export class CircleCenterConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.center;
    signature: ConstructionSignature = { points: 0, elements: 1, integers: 0, elementTypes: [CircleElement] };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        return [[], (E[0] as CircleElement).Center as PointElement];
    }
}
 
// point
// center (sphere variant)
// sphere A
// the center of the sphere A
// (Java: Slate.java point case 5, choice 1 — returns ((SphereElement)E[0]).Center)
export class SphereCenterConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.center;
    signature: ConstructionSignature = { points: 0, elements: 1, integers: 0, elementTypes: [SphereElement] };
    construct(_screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        return [[], (E[0] as SphereElement).Center as PointElement];
    }
}
 
// point
// lineSlider
// points A, B, integers x, y, [z=0]
// a point that slides along a line AB with initial coordinates (x,y,z)
// (Java: Slate.java point case 6 — new LineSlider(A,B,x,y,z,false))
export class LineSliderConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.lineSlider;
    signature: ConstructionSignature = { points: 2, elements: 0, integers: 2 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 2 && sp.E.length === 0 && (sp.N.length === 2 || sp.N.length === 3);
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = this.createSlider(P[0], P[1], N[0], N[1], N.length > 2 ? N[2] : 0);
        return [[g], g];
    }
    protected createSlider(a: PointElement, b: PointElement, x: number, y: number, z: number) {
        return new LineSlider(a, b, x, y, z, false);
    }
}
 
// point
// circleSlider
// circle A, integers x, y, [z=0]
// a point that slides along a circle A with given initial coordinates (x,y,z)
// (Java: Slate.java point case 7 — new CircleSlider(E[0], x, y, z))
export class CircleSliderConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.circleSlider;
    signature: ConstructionSignature = { points: 0, elements: 1, integers: 2, elementTypes: [CircleElement] };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 0 && sp.E.length === 1 && (sp.N.length === 2 || sp.N.length === 3)
            && sp.E[0] instanceof CircleElement;
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new CircleSlider(E[0] as CircleElement, N[0], N[1], N.length > 2 ? N[2] : 0);
        return [[g], g];
    }
}
 
// circle
// circumcircle — points A, B, C [, plane D = screen]
// the circle passing through 3 points A, B, and C in the plane D
// (Java: Slate.java circle case 1 — new Circumcircle(A,B,C,D))
export class CircumcircleConstruction extends Construction {
    constructionMethod: AllConstructions = CircleConstructions.circumcircle;
    signature: ConstructionSignature = { points: 3, elements: 0, integers: 0 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 3 && sp.N.length === 0
            && (sp.E.length === 0 || (sp.E.length === 1 && sp.E[0] instanceof PlaneElement));
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let plane = E.length > 0 ? E[0] as PlaneElement : screen;
        let g = new CircumcircleElement(P[0], P[1], P[2], plane);
        return [[g], g];
    }
}
 
// point
// circumcenter — points A, B, C [, plane D = screen]
// the center of a circle ABC passing through 3 points A, B, and C in the plane D
// (Java: Slate.java point case 8 — new Circumcircle(A,B,C,D), returns circ.Center)
export class CircumcenterConstruction extends CircumcircleConstruction {
    constructionMethod: AllConstructions = PointConstructions.circumcenter;
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let es = super.construct(screen, P, E, N);
        let g : CircleElement = es[1] as CircleElement;
        es[0].push(g.Center);
        return [es[0], g.Center];
    }
}
 
/* point
 * foot
 * points A, B, C
 * the foot of a perpendicular drawn from A to a line BC
 */
// (Java: Slate.java point case 10, choice 0 — new Foot(A,B,C))
export class FootPointConstruction extends Construction {
    constructionMethod : AllConstructions = PointConstructions.foot;
    signature: ConstructionSignature = { points: 3, elements: 0, integers: 0 };
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]) : [GeomElementsForUpdate, GeomElement] {
        let g = new Foot(P[0], P[1], P[2]);
 
        return [[g], g];
    }
}
 
// point
// foot (plane variant — solid geometry)
// point A plane B
// the foot of a perpendicular drawn from A to a plane B
// (Java: PlaneFoot.java — TS: PlaneFootElement.ts, renamed for clarity)
export class PlaneFootPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.foot;
    signature: ConstructionSignature = { points: 1, elements: 1, integers: 0, elementTypes: [PlaneElement] };
 
    construct(_screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const g = new PlaneFootElement(P[0], E[0] as PlaneElement);
        return [[g], g];
    }
}
 
// point
// layoff used for extend and cutoff
export abstract class LayoffConstruction extends Construction {
    signature: ConstructionSignature = { points: 4, elements: 0, integers: 0 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = this._createLayoff(P);
        return [[g], g];
    }
 
    protected abstract _createLayoff(ps: PointElement[]) : GeomElement;
}
 
// point
// cutoff
// points A, B, C, D
// the point E on a line AB so that AE = CD
// (Java: Slate.java point case 11 — new Layoff(A,A,B,C,D))
export class CutoffConstruction extends LayoffConstruction {
    constructionMethod: AllConstructions = PointConstructions.cutoff;
    protected _createLayoff(ps: PointElement[]) : GeomElement {
        return new Layoff(ps[0], ps[0], ps[1], ps[2], ps[3]);
    }
}
 
// point
// extend
// points A, B, C, D
// the point E on a line AB so that BE = CD
// (Java: Slate.java point case 12 — new Layoff(B,A,B,C,D))
export class ExtendConstruction extends LayoffConstruction {
    constructionMethod: AllConstructions = PointConstructions.extend;
    protected _createLayoff(ps: PointElement[]) : GeomElement {
        return new Layoff(ps[1], ps[0], ps[1], ps[2], ps[3]);
    }
}
 
// point
// parallelogram
// points C, A, B
// the 4th vertex D' of the parallelogram C-A-B-D' given 3 vertices C, A, B
// D' = C + (B - A)  [reuses Layoff with equal direction and length vectors]
// (Java: Slate.java point case 13 — new Layoff(C,A,B,A,B))
export class ParallelogramConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.parallelogram;
    signature: ConstructionSignature = { points: 3, elements: 0, integers: 0 };
 
    construct(_screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const g = new Layoff(P[0], P[1], P[2], P[1], P[2]);
        return [[g], g];
    }
}
 
// point
// similar — points A, B, D, E, F [, planes C, G = screen]
// the point H so that triangle ABH in plane C is similar to triangle DEF in plane G
// (Java: Slate.java point case 14 — Similar.java)
export class SimilarPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.similar;
    signature: ConstructionSignature = { points: 5, elements: 0, integers: 0 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 5 && sp.N.length === 0
            && (sp.E.length === 0 || sp.E.length === 2);
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let c = E.length > 0 ? E[0] as PlaneElement : screen;
        let g2 = E.length > 1 ? E[1] as PlaneElement : screen;
        let g = new SimilarElement(P[0], P[1], c, P[2], P[3], P[4], g2);
        return [[g], g];
    }
}
 
// point perpendicular constructions
export abstract class PointPerpendicularConstruction extends Construction {
    constructionMethod : AllConstructions = PointConstructions.perpendicular;
}
 
 
/* point
 * perpendicular
 * points A, B, [plane C (screen)]
 * the point D so that AD is equal and perpendicular to AB in plane C
 * (Java: Slate.java point case 15, choice 0 — new Perpendicular(A,B,screen,A,B))
 */
export class PointPerpendicular1Construction extends PointPerpendicularConstruction {
    signature: ConstructionSignature = { points: 2, elements: 0, integers: 0 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new Perpendicular({C:P[0], D:P[1],P:screen, E:P[0], F:P[1]});
        return [[g], g.B];
    }
}
 
 
/* point
 * perpendicular
 * points A, B, plane C
 * the point D so that AD is equal and perpendicular to AB in plane C
 * (Java: Slate.java point case 15, choice 1 — new Perpendicular(A,B,C,A,B))
 */
export class PointPerpendicular2Construction extends PointPerpendicularConstruction {
    signature: ConstructionSignature = { points: 2, elements: 1, integers: 0, elementTypes: [PlaneElement] };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new Perpendicular({C:P[0], D:P[1],P:E[0] as PlaneElement, E:P[0], F:P[1]});
        return [[g], g.B];
    }
}
 
 
/* point
 * perpendicular
 * points A, B, D, E [plane C (screen)]
 * the point F so that AF is perpendicular to AB in plane C and equals DE
 * (Java: Slate.java point case 15, choice 2 — new Perpendicular(A,B,screen,D,E))
 */
export class PointPerpendicular3Construction extends PointPerpendicularConstruction {
    signature: ConstructionSignature = { points: 4, elements: 0, integers: 0 };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new Perpendicular({C:P[0], D:P[1],P:screen, E:P[2], F:P[3]});
        return [[g], g.B];
    }
}
 
 
/* point
 * perpendicular
 * points A, B, plane C, points D, E
 * the point F so that AF is perpendicular to AB in plane C and equals DE
 * (Java: Slate.java point case 15, choice 3 — new Perpendicular(A,B,C,D,E))
 */
export class PointPerpendicular4Construction extends PointPerpendicularConstruction {
    signature: ConstructionSignature = { points: 4, elements: 1, integers: 0, elementTypes: [PlaneElement] };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new Perpendicular({C:P[0], D:P[1],P:E[0] as PlaneElement, E:P[2], F:P[3]});
        return [[g], g.B];
    }
}
 
 
/* point
 * perpendicular
 * point A, plane B, points C, D
 * the point E on the line perpendicular to plane B passing through
 * A so that the distance from E to B equals CD
 * (Java: Slate.java point case 15, choice 4 — new PlanePerpendicular(A,B,C,D))
 */
export class PointPerpendicular5Construction extends PointPerpendicularConstruction {
    signature: ConstructionSignature = { points: 3, elements: 1, integers: 0, elementTypes: [PlaneElement] };
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new PlanePerpendicularLine({C:P[0], P:E[0] as PlaneElement, D:P[1], E:P[2]});
        return [[g], g.B];
    }
}
 
 
// point
// proportion
// 8 points S0, S1, T0, T1, U0, U1, V0, V1
// the point V' on V0V1 so that |S0S1|:|T0T1| = |U0U1|:|V0V'|
// (Java: Proportion.java — 26 lines, line-for-line port)
export class ProportionPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.proportion;
    signature: ConstructionSignature = { points: 8, elements: 0, integers: 0 };
 
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new ProportionElement(P[0], P[1], P[2], P[3], P[4], P[5], P[6], P[7]);
        return [[g], g];
    }
}
 
// point
// invert
// point A circle B
// the image of a point A inverted in the circle B
// (Java: InvertPoint.java — 16 lines, calls toInvertPoint(A, C))
export class InvertPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.invert;
    signature: ConstructionSignature = { points: 1, elements: 1, integers: 0, elementTypes: [CircleElement] };
 
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const g = new InvertPointElement(P[0], E[0] as CircleElement);
        return [[g], g];
    }
}
 
// point
// meanProportional
// 6 points S0, S1, T0, T1, U0, U1
// the point U' on U0U1 so that S:U' = U':T (geometric mean)
// (Java: MeanProportional.java — 23 lines, line-for-line port)
export class MeanProportionalPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.meanProportional;
    signature: ConstructionSignature = { points: 6, elements: 0, integers: 0 };
 
    construct(screen : PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new MeanProportionalElement(P[0], P[1], P[2], P[3], P[4], P[5]);
        return [[g], g];
    }
}
 
// point
// planeSlider
// plane A integers x, y, z
// a point that slides on the plane A with initial coordinates (x,y,z)
// (Java: Slate.java point case 19 — new PlaneSlider((PlaneElement)E[0], N[0], N[1], N[2]).
// PlaneSlider.ts already has the full constructor + update() + drag().)
export class PlaneSliderConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.planeSlider;
    signature: ConstructionSignature = { points: 0, elements: 1, integers: 3, elementTypes: [PlaneElement] };
 
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const g = new PlaneSlider(E[0] as PlaneElement, N[0], N[1], N[2]);
        return [[g], g];
    }
}
 
// point
// sphereSlider
// sphere A integers x, y, z
// a point that slides on the sphere A with initial coordinates (x,y,z)
// (Java: SphereSlider.java — 43 lines, line-for-line port)
export class SphereSliderConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.sphereSlider;
    signature: ConstructionSignature = { points: 0, elements: 1, integers: 3, elementTypes: [SphereElement] };
 
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const g = new SphereSliderElement(E[0] as SphereElement, N[0], N[1], N[2]);
        return [[g], g];
    }
}
 
// point
// angleBisector — points B, A, C [, plane D = screen]
// bisect angle BAC — the point on BC where the bisector from A meets BC
// (Java: AngleDivider.java with n=2, Slate.java point case 21)
export class AngleBisectorPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.angleBisector;
    signature: ConstructionSignature = { points: 3, elements: 0, integers: 0 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 3 && sp.N.length === 0
            && (sp.E.length === 0 || (sp.E.length === 1 && sp.E[0] instanceof PlaneElement));
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let plane = E.length > 0 ? E[0] as PlaneElement : screen;
        let g = new AngleDividerElement(P[0], P[1], P[2], plane, 2);
        return [[g], g];
    }
}
 
// point
// angleDivider — points B, A, C, integer n [, plane D = screen]
// n-sect angle BAC — the point on BC where the 1/n ray from A meets BC
// (Java: AngleDivider.java with variable n, Slate.java point case 22)
export class AngleDividerPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.angleDivider;
    signature: ConstructionSignature = { points: 3, elements: 0, integers: 1 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 3 && sp.N.length === 1
            && (sp.E.length === 0 || (sp.E.length === 1 && sp.E[0] instanceof PlaneElement));
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let plane = E.length > 0 ? E[0] as PlaneElement : screen;
        let g = new AngleDividerElement(P[0], P[1], P[2], plane, N[0]);
        return [[g], g];
    }
}
 
// point
// fixed
// integers x, y [, z=0]
// the fixed point with coordinates (x, y, z). z defaults to 0 if not provided.
// (Java: Slate.java point case 23 — new FixedPoint(x,y,z))
export class FixedPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.fixed;
    signature: ConstructionSignature = { points: 0, elements: 0, integers: 2 };
    public validateSignature(cm: AllConstructions, sp: SortedParams): boolean {
        if (cm !== this.constructionMethod) return false;
        return sp.P.length === 0 && sp.E.length === 0 && (sp.N.length === 2 || sp.N.length === 3);
    }
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new FixedPoint({x:N[0], y:N[1], z: N.length > 2 ? N[2] : 0});
        return [[g], g];
    }
}
 
// point
// lineSegmentSlider
// points A, B, integers x, y, [z]
// a point that slides along within the line segment AB with initial coordinates (x,y,z)
// (Java: Slate.java point case 24 — new LineSlider(A,B,x,y,z,true))
export class LineSliderSegmentConstruction extends LineSliderConstruction {
    constructionMethod: AllConstructions = PointConstructions.lineSegmentSlider;
    protected createSlider(a: PointElement, b: PointElement, x: number, y: number, z: number) {
        return new LineSlider(a, b, x, y, z, true);
    }
}
 
 
// point
// harmonic
// points B, C, D
// the harmonic conjugate of B with respect to C and D
// (Java: Harmonic.java — 43 lines, line-for-line port.
// Slate.java point case 25 — new Harmonic(P[0], P[1], P[2]))
export class HarmonicPointConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.harmonic;
    signature: ConstructionSignature = { points: 3, elements: 0, integers: 0 };
 
    construct(screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        let g = new HarmonicElement(P[0], P[1], P[2]);
        return [[g], g];
    }
}
 
// point
// vertex
// polygon A, integer n
// the nth vertex (1-based) of polygon A
// (Java: Slate.java point case 9 — returns ((PolygonElement)E[0]).V[n-1])
export class VertexConstruction extends Construction {
    constructionMethod: AllConstructions = PointConstructions.vertex;
    signature: ConstructionSignature = { points: 0, elements: 1, integers: 1, elementTypes: [PolygonElement] };
 
    construct(_screen: PlaneElement, P: PointElement[], E: GeomElement[], N: number[]): [GeomElementsForUpdate, GeomElement] {
        const poly = E[0] as PolygonElement;
        const vertex = poly.V[N[0] - 1];
        return [[vertex], vertex];
    }
}
 
export const pointConstructions: Construction[] = [
    new FreePointConstruction(),
    new FixedPointConstruction(),
    new FirstPointConstruction(),
    new LastPointConstruction(),
    new CircleCenterConstruction(),
    new CircumcenterConstruction(),
    new MidPointConstruction(),
    new IntersectionConstruction(),
    new FootPointConstruction(),
    new PlaneFootPointConstruction(),
    new ExtendConstruction(),
    new CutoffConstruction(),
    new ParallelogramConstruction(),
    new SimilarPointConstruction(),
    new ProportionPointConstruction(),
    new AngleBisectorPointConstruction(),
    new AngleDividerPointConstruction(),
    new MeanProportionalPointConstruction(),
    new PlaneSliderConstruction(),
    new SphereSliderConstruction(),
    new HarmonicPointConstruction(),
    new InvertPointConstruction(),
    new PlaneIntersectionConstruction(),
    new SphereCenterConstruction(),
    new CircumcircleConstruction(),
    new LineSliderConstruction(),
    new LineSliderSegmentConstruction(),
    new CircleSliderConstruction(),
    new PointPerpendicular1Construction(),
    new PointPerpendicular2Construction(),
    new PointPerpendicular3Construction(),
    new PointPerpendicular4Construction(),
    new PointPerpendicular5Construction(),
    new VertexConstruction(),
];