• 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

5.41
/src/engine/Graphics/Debug.ts
1
import { Vector } from '../Math/vector';
2
import { ExcaliburGraphicsContext, LineGraphicsOptions, PointGraphicsOptions } from './Context/ExcaliburGraphicsContext';
3
import { Color } from '../Color';
4
import { Ray } from '../Math/ray';
5
import { BoundingBox } from '../Collision/BoundingBox';
6

7
export class Debug {
8
  static _drawCalls: ((ctx: ExcaliburGraphicsContext) => void)[] = [];
1✔
9
  static _ctx: ExcaliburGraphicsContext;
10
  static z: number = Infinity;
1✔
11
  static registerGraphicsContext(ctx: ExcaliburGraphicsContext) {
12
    Debug._ctx = ctx;
×
13
  }
14
  static draw(debugDrawCall: (ctx: ExcaliburGraphicsContext) => void) {
UNCOV
15
    this._drawCalls.push(debugDrawCall);
×
16
  }
17

18
  static drawPoint(point: Vector, options?: PointGraphicsOptions) {
UNCOV
19
    Debug.draw((ctx) => {
×
UNCOV
20
      ctx.debug.drawPoint(point, options);
×
21
    });
22
  }
23

24
  static drawLine(start: Vector, end: Vector, options?: LineGraphicsOptions) {
UNCOV
25
    Debug.draw((ctx) => {
×
UNCOV
26
      ctx.debug.drawLine(start, end, options);
×
27
    });
28
  }
29

30
  static drawLines(points: Vector[], options?: LineGraphicsOptions) {
UNCOV
31
    if (points.length > 1) {
×
UNCOV
32
      Debug.draw((ctx) => {
×
UNCOV
33
        for (let i = 0; i < points.length - 1; i++) {
×
UNCOV
34
          ctx.debug.drawLine(points[i], points[i + 1], options);
×
35
        }
36
      });
37
    }
38
  }
39

40
  static drawText(text: string, pos: Vector) {
41
    Debug.draw((ctx) => {
×
42
      ctx.debug.drawText(text, pos);
×
43
    });
44
  }
45

46
  static drawPolygon(points: Vector[], options?: { color?: Color }) {
UNCOV
47
    if (points.length > 1) {
×
UNCOV
48
      Debug.draw((ctx) => {
×
UNCOV
49
        const firstPoint = points[0];
×
UNCOV
50
        const polygon = [...points, firstPoint];
×
UNCOV
51
        for (let i = 0; i < polygon.length - 1; i++) {
×
UNCOV
52
          ctx.debug.drawLine(polygon[i], polygon[i + 1], options);
×
53
        }
54
      });
55
    }
56
  }
57

58
  static drawCircle(
59
    center: Vector,
60
    radius: number,
61
    options?: {
62
      color?: Color;
63
      strokeColor?: Color;
64
      width?: number;
65
    }
66
  ) {
UNCOV
67
    const { color, strokeColor, width } = {
×
68
      color: Color.Black,
69
      strokeColor: undefined,
70
      width: undefined,
71
      ...options
72
    };
UNCOV
73
    Debug.draw((ctx) => {
×
UNCOV
74
      ctx.drawCircle(center, radius, color, strokeColor, width);
×
75
    });
76
  }
77

78
  static drawBounds(boundingBox: BoundingBox, options?: { color?: Color }): void {
UNCOV
79
    Debug.draw((ctx) => {
×
UNCOV
80
      ctx.debug.drawRect(boundingBox.left, boundingBox.top, boundingBox.width, boundingBox.height, options);
×
81
    });
82
  }
83

84
  static drawRay(ray: Ray, options?: { distance?: number; color?: Color }) {
UNCOV
85
    const { distance, color } = {
×
86
      color: Color.Blue,
87
      distance: 10,
88
      ...options
89
    };
UNCOV
90
    Debug.draw((ctx) => {
×
UNCOV
91
      const start = ray.pos;
×
UNCOV
92
      const end = ray.pos.add(ray.dir.scale(distance));
×
93

UNCOV
94
      ctx.debug.drawLine(start, end, { color });
×
95
    });
96
  }
97

98
  static flush(ctx: ExcaliburGraphicsContext) {
UNCOV
99
    ctx.save();
×
UNCOV
100
    ctx.z = Debug.z;
×
UNCOV
101
    for (const drawCall of Debug._drawCalls) {
×
UNCOV
102
      drawCall(ctx);
×
103
    }
UNCOV
104
    ctx.restore();
×
UNCOV
105
    Debug.clear();
×
106
  }
107

108
  static clear() {
UNCOV
109
    Debug._drawCalls.length = 0;
×
110
  }
111
}
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