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

graphty-org / graphty-element / 16214082367

11 Jul 2025 07:07AM UTC coverage: 68.182% (+1.1%) from 67.128%
16214082367

push

github

apowers313
refactor: extract mesh creation logic into NodeMesh and EdgeMesh classes

546 of 780 branches covered (70.0%)

Branch coverage included in aggregate %.

333 of 334 new or added lines in 3 files covered. (99.7%)

80 existing lines in 5 files now uncovered.

3954 of 5820 relevant lines covered (67.94%)

994.07 hits per line

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

48.48
/src/camera/TwoDCameraController.ts
1
import {Camera, Engine, FreeCamera, Scene, TransformNode, Vector3, WebGPUEngine} from "@babylonjs/core";
1✔
2

3
// === Configuration Object ===
4
export interface TwoDCameraControlsConfigType {
5
    panAcceleration: number;
6
    panDamping: number;
7
    zoomFactorPerFrame: number;
8
    zoomDamping: number;
9
    zoomMin: number;
10
    zoomMax: number;
11
    rotateSpeedPerFrame: number;
12
    rotateDamping: number;
13
    rotateMin: number | null;
14
    rotateMax: number | null;
15
    mousePanScale: number;
16
    mouseWheelZoomSpeed: number;
17
    touchPanScale: number;
18
    touchPinchMin: number;
19
    touchPinchMax: number;
20
    initialOrthoSize: number;
21
    rotationEnabled: boolean;
22
    inertiaEnabled: boolean;
23
}
24

25
// === Camera Controller Class ===
26
export class TwoDCameraController {
1✔
27
    public camera: FreeCamera;
28
    public parent: TransformNode;
29
    public velocity = {x: 0, y: 0, zoom: 0, rotate: 0};
1✔
30

31
    constructor(
1✔
32
        public scene: Scene,
61✔
33
        public engine: Engine | WebGPUEngine,
61✔
34
        public canvas: HTMLCanvasElement,
61✔
35
        public config: TwoDCameraControlsConfigType,
61✔
36
    ) {
61✔
37
        this.camera = new FreeCamera("orthoCamera", new Vector3(0, 0, -10), scene);
61✔
38
        this.camera.mode = Camera.ORTHOGRAPHIC_CAMERA;
61✔
39
        this.camera.inertia = 0;
61✔
40
        this.camera.inputs.clear();
61✔
41

42
        this.parent = new TransformNode("parent", scene);
61✔
43
        this.updateOrtho(config.initialOrthoSize);
61✔
44
        this.camera.setTarget(Vector3.Zero());
61✔
45
    }
61✔
46

47
    public updateOrtho(size: number): void {
1✔
48
        const aspect = this.engine.getRenderHeight() / this.engine.getRenderWidth();
61✔
49
        this.camera.orthoLeft = -size;
61✔
50
        this.camera.orthoRight = size;
61✔
51
        this.camera.orthoTop = size * aspect;
61✔
52
        this.camera.orthoBottom = -size * aspect;
61✔
53
    }
61✔
54

55
    public pan(dx: number, dy: number): void {
1✔
56
        this.camera.position.x += dx;
×
57
        this.camera.position.y += dy;
×
58
    }
×
59

60
    public zoom(factor: number): void {
1✔
61
        this.camera.orthoLeft = factor * (this.camera.orthoLeft ?? 1);
×
62
        this.camera.orthoRight = factor * (this.camera.orthoRight ?? 1);
×
63
        this.camera.orthoTop = factor * (this.camera.orthoTop ?? 1);
×
64
        this.camera.orthoBottom = factor * (this.camera.orthoBottom ?? 1);
×
65
    }
×
66

67
    public rotate(delta: number): void {
1✔
68
        this.parent.rotation.z += delta;
×
69
    }
×
70

71
    public applyInertia(): void {
1✔
UNCOV
72
        const v = this.velocity;
×
UNCOV
73
        const c = this.config;
×
74

UNCOV
75
        this.camera.position.x += v.x;
×
UNCOV
76
        this.camera.position.y += v.y;
×
77

UNCOV
78
        const zoomScale = Math.exp(v.zoom);
×
UNCOV
79
        this.camera.orthoLeft = zoomScale * (this.camera.orthoLeft ?? 1);
×
UNCOV
80
        this.camera.orthoRight = zoomScale * (this.camera.orthoRight ?? 1);
×
UNCOV
81
        this.camera.orthoTop = zoomScale * (this.camera.orthoTop ?? 1);
×
UNCOV
82
        this.camera.orthoBottom = zoomScale * (this.camera.orthoBottom ?? 1);
×
83

UNCOV
84
        this.parent.rotation.z += v.rotate;
×
85

UNCOV
86
        v.x *= c.panDamping;
×
UNCOV
87
        v.y *= c.panDamping;
×
UNCOV
88
        v.zoom *= c.zoomDamping;
×
UNCOV
89
        v.rotate *= c.rotateDamping;
×
UNCOV
90
    }
×
91

92
    public zoomToBoundingBox(min: Vector3, max: Vector3): void {
1✔
UNCOV
93
        const centerX = (min.x + max.x) / 2;
×
UNCOV
94
        const centerY = (min.y + max.y) / 2;
×
95

UNCOV
96
        const sizeX = max.x - min.x;
×
UNCOV
97
        const sizeY = max.y - min.y;
×
UNCOV
98
        const largest = Math.max(sizeX, sizeY);
×
99

UNCOV
100
        this.camera.position.x = centerX;
×
UNCOV
101
        this.camera.position.y = centerY;
×
UNCOV
102
        this.updateOrtho(largest * 0.6); // Padding factor as needed
×
UNCOV
103
    }
×
104
}
1✔
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