• 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/TransformInterpolation.ts
1
import { Transform } from '../Math/transform';
2

3
/**
4
 * Blend 2 transforms for interpolation, will interpolate from the context of newTx's parent if it exists
5
 */
6
export function blendTransform(oldTx: Transform, newTx: Transform, blend: number, target?: Transform): Transform {
UNCOV
7
  if (oldTx.parent !== newTx.parent) {
×
8
    // Caller expects a local transform
9
    // Adjust old tx to be local to the new parent whatever that is
UNCOV
10
    const oldTxWithNewParent = oldTx.clone();
×
UNCOV
11
    const oldGlobalPos = oldTx.globalPos.clone();
×
UNCOV
12
    const oldGlobalScale = oldTx.globalScale.clone();
×
UNCOV
13
    const oldGlobalRotation = oldTx.globalRotation;
×
UNCOV
14
    oldTxWithNewParent.parent = newTx.parent;
×
UNCOV
15
    oldTxWithNewParent.globalPos = oldGlobalPos;
×
UNCOV
16
    oldTxWithNewParent.globalScale = oldGlobalScale;
×
UNCOV
17
    oldTxWithNewParent.globalRotation = oldGlobalRotation;
×
UNCOV
18
    oldTx = oldTxWithNewParent;
×
19
  }
UNCOV
20
  let interpolatedPos = newTx.pos;
×
UNCOV
21
  let interpolatedScale = newTx.scale;
×
UNCOV
22
  let interpolatedRotation = newTx.rotation;
×
23

UNCOV
24
  interpolatedPos = newTx.pos.scale(blend).add(oldTx.pos.scale(1.0 - blend));
×
UNCOV
25
  interpolatedScale = newTx.scale.scale(blend).add(oldTx.scale.scale(1.0 - blend));
×
26
  // Rotational lerp https://stackoverflow.com/a/30129248
UNCOV
27
  const cosine = (1.0 - blend) * Math.cos(oldTx.rotation) + blend * Math.cos(newTx.rotation);
×
UNCOV
28
  const sine = (1.0 - blend) * Math.sin(oldTx.rotation) + blend * Math.sin(newTx.rotation);
×
UNCOV
29
  interpolatedRotation = Math.atan2(sine, cosine);
×
30

UNCOV
31
  const tx = target ?? new Transform();
×
UNCOV
32
  tx.setTransform(interpolatedPos, interpolatedRotation, interpolatedScale);
×
UNCOV
33
  return tx;
×
34
}
35

36
/**
37
 *
38
 */
39
export function blendGlobalTransform(oldTx: Transform, newTx: Transform, blend: number, target?: Transform): Transform {
40
  let interpolatedPos = newTx.globalPos;
×
41
  let interpolatedScale = newTx.globalScale;
×
42
  let interpolatedRotation = newTx.globalRotation;
×
43

44
  interpolatedPos = newTx.globalPos.scale(blend).add(oldTx.globalPos.scale(1.0 - blend));
×
45
  interpolatedScale = newTx.globalScale.scale(blend).add(oldTx.globalScale.scale(1.0 - blend));
×
46
  // Rotational lerp https://stackoverflow.com/a/30129248
47
  const cosine = (1.0 - blend) * Math.cos(oldTx.globalRotation) + blend * Math.cos(newTx.globalRotation);
×
48
  const sine = (1.0 - blend) * Math.sin(oldTx.globalRotation) + blend * Math.sin(newTx.globalRotation);
×
49
  interpolatedRotation = Math.atan2(sine, cosine);
×
50

51
  const tx = target ?? new Transform();
×
52
  tx.setTransform(interpolatedPos, interpolatedRotation, interpolatedScale);
×
53
  return tx;
×
54
}
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