• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

excaliburjs / Excalibur / 14804036802

02 May 2025 09:58PM UTC coverage: 5.927% (-83.4%) from 89.28%
14804036802

Pull #3404

github

web-flow
Merge 5c103d7f8 into 0f2ccaeb2
Pull Request #3404: feat: added Graph module to Math

234 of 8383 branches covered (2.79%)

229 of 246 new or added lines in 1 file covered. (93.09%)

13145 existing lines in 208 files now uncovered.

934 of 15759 relevant lines covered (5.93%)

4.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/engine/Graphics/Polygon.ts
1
import { ImageFiltering } from './Filtering';
2
import { Vector, vec } from '../Math/vector';
3
import { Raster, RasterOptions } from './Raster';
4

5
export interface PolygonOptions {
6
  points: Vector[];
7
}
8

9
/**
10
 * A polygon {@apilink Graphic} for drawing arbitrary polygons to the {@apilink ExcaliburGraphicsContext}
11
 *
12
 * Polygons default to {@apilink ImageFiltering.Blended}
13
 */
14
export class Polygon extends Raster {
UNCOV
15
  private _points: Vector[] = [];
×
16
  public get points(): Vector[] {
UNCOV
17
    return this._points;
×
18
  }
19
  public set points(points: Vector[]) {
UNCOV
20
    this._points = points;
×
UNCOV
21
    const min = this.minPoint;
×
UNCOV
22
    this.width = this._points.reduce((max, p) => Math.max(p.x, max), 0) - min.x;
×
UNCOV
23
    this.height = this._points.reduce((max, p) => Math.max(p.y, max), 0) - min.y;
×
UNCOV
24
    this.flagDirty();
×
25
  }
26

27
  public get minPoint() {
UNCOV
28
    const minX = this._points.reduce((min, p) => Math.min(p.x, min), Infinity);
×
UNCOV
29
    const minY = this._points.reduce((min, p) => Math.min(p.y, min), Infinity);
×
UNCOV
30
    return vec(minX, minY);
×
31
  }
32

33
  constructor(options: RasterOptions & PolygonOptions) {
UNCOV
34
    super(options);
×
UNCOV
35
    this.points = options.points;
×
UNCOV
36
    this.filtering = ImageFiltering.Blended;
×
UNCOV
37
    this.rasterize();
×
38
  }
39

40
  public clone(): Polygon {
UNCOV
41
    return new Polygon({
×
UNCOV
42
      points: this.points.map((p) => p.clone()),
×
43
      ...this.cloneGraphicOptions(),
44
      ...this.cloneRasterOptions()
45
    });
46
  }
47

48
  execute(ctx: CanvasRenderingContext2D): void {
UNCOV
49
    if (this.points && this.points.length) {
×
UNCOV
50
      ctx.beginPath();
×
51
      // Iterate through the supplied points and construct a 'polygon'
UNCOV
52
      const min = this.minPoint.negate();
×
UNCOV
53
      const firstPoint = this.points[0].add(min);
×
UNCOV
54
      ctx.moveTo(firstPoint.x, firstPoint.y);
×
UNCOV
55
      this.points.forEach((point) => {
×
UNCOV
56
        ctx.lineTo(point.x + min.x, point.y + min.y);
×
57
      });
UNCOV
58
      ctx.lineTo(firstPoint.x, firstPoint.y);
×
UNCOV
59
      ctx.closePath();
×
UNCOV
60
      if (this.color) {
×
UNCOV
61
        ctx.fill();
×
62
      }
UNCOV
63
      if (this.strokeColor) {
×
UNCOV
64
        ctx.stroke();
×
65
      }
66
    }
67
  }
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc