@flighthq/camera 0.5.1-edge.1471.4e82419 → 0.5.1-edge.1685.dc0e23a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,5 +13,5 @@ Import the supported application-facing API from `@flighthq/camera`. The `@fligh
13
13
  This package is part of the locked-version Flight SDK graph. Applications may instead install and import `@flighthq/sdk` when package-level tree shaking is sufficient.
14
14
 
15
15
  - [Flight project](https://github.com/flighthq/flight)
16
- - [Source for @flighthq/camera@0.5.1-edge.1471.4e82419](https://github.com/flighthq/flight/tree/4e82419a6322f8a673da169994c79fa561016515/packages/camera)
17
- - [License](https://github.com/flighthq/flight/blob/4e82419a6322f8a673da169994c79fa561016515/LICENSE.md)
16
+ - [Source for @flighthq/camera@0.5.1-edge.1685.dc0e23a](https://github.com/flighthq/flight/tree/dc0e23a17453ec75c20ccbf07058a57b5ef10c4c/packages/camera)
17
+ - [License](https://github.com/flighthq/flight/blob/dc0e23a17453ec75c20ccbf07058a57b5ef10c4c/LICENSE.md)
@@ -1,4 +1,5 @@
1
1
  import type { Camera2D, Camera2DOptions, EntityConstruction } from '@flighthq/types/contract';
2
- export declare function createCamera2D(viewportWidth: number, viewportHeight: number, options?: Readonly<Camera2DOptions>): Camera2D;
3
- export declare function initializeCamera2D(out: EntityConstruction<Camera2D>, viewportWidth: number, viewportHeight: number, options?: Readonly<Camera2DOptions>): void;
2
+ export declare function createCamera2D(options?: Readonly<Camera2DOptions>): Camera2D;
3
+ export declare function initializeCamera2D(out: EntityConstruction<Camera2D>, options?: Readonly<Camera2DOptions>): void;
4
+ export declare function setCamera2DLookAt(camera: Camera2D, x: number, y: number): void;
4
5
  //# sourceMappingURL=camera2d.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"camera2d.d.ts","sourceRoot":"","sources":["../src/camera2d.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAM9F,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,GAClC,QAAQ,CAIV;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EACjC,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,GAClC,IAAI,CAON"}
1
+ {"version":3,"file":"camera2d.d.ts","sourceRoot":"","sources":["../src/camera2d.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAK9F,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,QAAQ,CAI5E;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,eAAe,CAAC,GAAG,IAAI,CAK/G;AAID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAG9E"}
package/dist/camera2d.js CHANGED
@@ -1,19 +1,22 @@
1
1
  import { allocateEntity, finishEntity } from '@flighthq/entity/contract';
2
- // Allocates a plain-data 2D camera over a `viewportWidth` x `viewportHeight` surface. The camera
3
- // starts centered on world origin at zoom 1 with no rotation; `options` overrides any of `x`, `y`,
4
- // `zoom`, `rotation`. This is the only allocating function in the package — every other operation
5
- // writes into an `out` parameter.
6
- export function createCamera2D(viewportWidth, viewportHeight, options) {
2
+ // Allocates a plain-data 2D camera. The camera starts centered on world origin at zoom 1 with no
3
+ // rotation; `options` overrides any of `x`, `y`, `zoom`, `rotation`. This is the only allocating
4
+ // function in the package — every other operation writes into an `out` parameter.
5
+ export function createCamera2D(options) {
7
6
  const out = allocateEntity();
8
- initializeCamera2D(out, viewportWidth, viewportHeight, options);
7
+ initializeCamera2D(out, options);
9
8
  return finishEntity(out);
10
9
  }
11
- export function initializeCamera2D(out, viewportWidth, viewportHeight, options) {
10
+ export function initializeCamera2D(out, options) {
12
11
  out.rotation = options?.rotation ?? 0;
13
- out.viewportHeight = viewportHeight;
14
- out.viewportWidth = viewportWidth;
15
12
  out.x = options?.x ?? 0;
16
13
  out.y = options?.y ?? 0;
17
14
  out.zoom = options?.zoom ?? 1;
18
15
  }
16
+ // Centers the camera on a world position. The simplest camera operation — the named verb reads
17
+ // better than bare `camera.x = x; camera.y = y` because it names the intent.
18
+ export function setCamera2DLookAt(camera, x, y) {
19
+ camera.x = x;
20
+ camera.y = y;
21
+ }
19
22
  //# sourceMappingURL=camera2d.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"camera2d.js","sourceRoot":"","sources":["../src/camera2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzE,iGAAiG;AACjG,mGAAmG;AACnG,kGAAkG;AAClG,kCAAkC;AAClC,MAAM,UAAU,cAAc,CAC5B,aAAqB,EACrB,cAAsB,EACtB,OAAmC;IAEnC,MAAM,GAAG,GAAG,cAAc,EAAY,CAAC;IACvC,kBAAkB,CAAC,GAAG,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,GAAiC,EACjC,aAAqB,EACrB,cAAsB,EACtB,OAAmC;IAEnC,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,cAAc,GAAG,cAAc,CAAC;IACpC,GAAG,CAAC,aAAa,GAAG,aAAa,CAAC;IAClC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACxB,GAAG,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,CAAC,CAAC;AAChC,CAAC"}
1
+ {"version":3,"file":"camera2d.js","sourceRoot":"","sources":["../src/camera2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAGzE,iGAAiG;AACjG,iGAAiG;AACjG,kFAAkF;AAClF,MAAM,UAAU,cAAc,CAAC,OAAmC;IAChE,MAAM,GAAG,GAAG,cAAc,EAAY,CAAC;IACvC,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACjC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAAiC,EAAE,OAAmC;IACvG,GAAG,CAAC,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACxB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACxB,GAAG,CAAC,IAAI,GAAG,OAAO,EAAE,IAAI,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,+FAA+F;AAC/F,6EAA6E;AAC7E,MAAM,UAAU,iBAAiB,CAAC,MAAgB,EAAE,CAAS,EAAE,CAAS;IACtE,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -17,6 +17,4 @@ export * from './shadowCamera';
17
17
  export * from './viewMatrix';
18
18
  export * from './visibleBounds';
19
19
  export * from './zoom';
20
- export { initializeCamera3D } from './camera';
21
- export { initializeOrthographicProjection, initializePerspectiveProjection, initializeRawProjection, } from './projection';
22
20
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC"}
package/dist/contract.js CHANGED
@@ -17,6 +17,4 @@ export * from './shadowCamera';
17
17
  export * from './viewMatrix';
18
18
  export * from './visibleBounds';
19
19
  export * from './zoom';
20
- export { initializeCamera3D } from './camera';
21
- export { initializeOrthographicProjection, initializePerspectiveProjection, initializeRawProjection, } from './projection';
22
20
  //# sourceMappingURL=contract.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,uBAAuB,GACxB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,QAAQ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,20 @@
1
- export { applyObliqueNearClipPlane, areCameraGuardsEnabled, configureDirectionalShadowCamera3D, configureDirectionalShadowCamera3DTightFit, createCamera2D, createCamera3D, createOrthographicProjection, createPerspectiveProjection, createRawProjection, disableCameraGuards, enableCameraGuards, getCamera2DParallaxPoint, getCamera2DViewMatrix, getCamera2DVisibleBounds, getCamera3DForward, getCamera3DFrustum, getCamera3DFrustumCorners, getCamera3DInverseViewProjectionMatrix4, getCamera3DLinearDepth, getCamera3DPosition, getCamera3DRayThroughBoundingSphere, getCamera3DRight, getCamera3DScreenToWorldRay, getCamera3DUp, getCamera3DViewProjectionMatrix4, getCamera3DViewSpaceZ, getCamera3DWorldToScreen, getCubeCaptureFaceCamera3D, getOrthographicProjectionTexelSize, intersectCamera3DRayWithPlane, isBoxInCamera3DFrustum, isOrthographicProjection, isPerspectiveProjection, isRawProjection, isPointInCamera3DFrustum, isSphereInCamera3DFrustum, projectCamera2DPoint, reflectCamera3DByPlane, setCamera3DAspect, setCamera3DJitter, setCamera3DViewMatrix4FromLookAt, setCamera3DViewMatrix4FromMatrix4, setProjectionMatrix4, unprojectCamera2DPoint, updateCamera3DInverseViewProjection, zoomCamera2DAtScreenPoint, } from './contract';
1
+ export * from './basis';
2
+ export { createCamera3D, getCamera3DInverseViewProjectionMatrix4, getCamera3DViewProjectionMatrix4, setCamera3DAspect, setCamera3DJitter, setCamera3DViewMatrix4FromLookAt, setCamera3DViewMatrix4FromMatrix4, updateCamera3DInverseViewProjection, } from './camera';
3
+ export { createCamera2D, setCamera2DLookAt } from './camera2d';
4
+ export * from './cubeCapture';
5
+ export * from './culling';
6
+ export * from './depth';
7
+ export * from './enableCameraGuards';
8
+ export * from './explainCamera3DView';
9
+ export * from './frustumCorners';
10
+ export * from './intersection';
11
+ export * from './parallax';
12
+ export * from './picking';
13
+ export { createOrthographicProjection, createPerspectiveProjection, createRawProjection, getOrthographicProjectionTexelSize, isOrthographicProjection, isPerspectiveProjection, isRawProjection, setProjectionMatrix4, } from './projection';
14
+ export * from './projection2d';
15
+ export * from './reflection';
16
+ export * from './shadowCamera';
17
+ export * from './viewMatrix';
18
+ export { getCamera2DVisibleBounds } from './visibleBounds';
19
+ export * from './zoom';
2
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,kCAAkC,EAClC,0CAA0C,EAC1C,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,uCAAuC,EACvC,sBAAsB,EACtB,mBAAmB,EACnB,mCAAmC,EACnC,gBAAgB,EAChB,2BAA2B,EAC3B,aAAa,EACb,gCAAgC,EAChC,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,kCAAkC,EAClC,6BAA6B,EAC7B,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,gCAAgC,EAChC,iCAAiC,EACjC,oBAAoB,EACpB,sBAAsB,EACtB,mCAAmC,EACnC,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,cAAc,EACd,uCAAuC,EACvC,gCAAgC,EAChC,iBAAiB,EACjB,iBAAiB,EACjB,gCAAgC,EAChC,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/D,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,kCAAkC,EAClC,wBAAwB,EACxB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,cAAc,QAAQ,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,20 @@
1
- export { applyObliqueNearClipPlane, areCameraGuardsEnabled, configureDirectionalShadowCamera3D, configureDirectionalShadowCamera3DTightFit, createCamera2D, createCamera3D, createOrthographicProjection, createPerspectiveProjection, createRawProjection, disableCameraGuards, enableCameraGuards, getCamera2DParallaxPoint, getCamera2DViewMatrix, getCamera2DVisibleBounds, getCamera3DForward, getCamera3DFrustum, getCamera3DFrustumCorners, getCamera3DInverseViewProjectionMatrix4, getCamera3DLinearDepth, getCamera3DPosition, getCamera3DRayThroughBoundingSphere, getCamera3DRight, getCamera3DScreenToWorldRay, getCamera3DUp, getCamera3DViewProjectionMatrix4, getCamera3DViewSpaceZ, getCamera3DWorldToScreen, getCubeCaptureFaceCamera3D, getOrthographicProjectionTexelSize, intersectCamera3DRayWithPlane, isBoxInCamera3DFrustum, isOrthographicProjection, isPerspectiveProjection, isRawProjection, isPointInCamera3DFrustum, isSphereInCamera3DFrustum, projectCamera2DPoint, reflectCamera3DByPlane, setCamera3DAspect, setCamera3DJitter, setCamera3DViewMatrix4FromLookAt, setCamera3DViewMatrix4FromMatrix4, setProjectionMatrix4, unprojectCamera2DPoint, updateCamera3DInverseViewProjection, zoomCamera2DAtScreenPoint, } from './contract';
1
+ export * from './basis';
2
+ export { createCamera3D, getCamera3DInverseViewProjectionMatrix4, getCamera3DViewProjectionMatrix4, setCamera3DAspect, setCamera3DJitter, setCamera3DViewMatrix4FromLookAt, setCamera3DViewMatrix4FromMatrix4, updateCamera3DInverseViewProjection, } from './camera';
3
+ export { createCamera2D, setCamera2DLookAt } from './camera2d';
4
+ export * from './cubeCapture';
5
+ export * from './culling';
6
+ export * from './depth';
7
+ export * from './enableCameraGuards';
8
+ export * from './explainCamera3DView';
9
+ export * from './frustumCorners';
10
+ export * from './intersection';
11
+ export * from './parallax';
12
+ export * from './picking';
13
+ export { createOrthographicProjection, createPerspectiveProjection, createRawProjection, getOrthographicProjectionTexelSize, isOrthographicProjection, isPerspectiveProjection, isRawProjection, setProjectionMatrix4, } from './projection';
14
+ export * from './projection2d';
15
+ export * from './reflection';
16
+ export * from './shadowCamera';
17
+ export * from './viewMatrix';
18
+ export { getCamera2DVisibleBounds } from './visibleBounds';
19
+ export * from './zoom';
2
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,kCAAkC,EAClC,0CAA0C,EAC1C,cAAc,EACd,cAAc,EACd,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,uCAAuC,EACvC,sBAAsB,EACtB,mBAAmB,EACnB,mCAAmC,EACnC,gBAAgB,EAChB,2BAA2B,EAC3B,aAAa,EACb,gCAAgC,EAChC,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,kCAAkC,EAClC,6BAA6B,EAC7B,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,oBAAoB,EACpB,sBAAsB,EACtB,iBAAiB,EACjB,iBAAiB,EACjB,gCAAgC,EAChC,iCAAiC,EACjC,oBAAoB,EACpB,sBAAsB,EACtB,mCAAmC,EACnC,yBAAyB,GAC1B,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EACL,cAAc,EACd,uCAAuC,EACvC,gCAAgC,EAChC,iBAAiB,EACjB,iBAAiB,EACjB,gCAAgC,EAChC,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/D,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,mBAAmB,EACnB,kCAAkC,EAClC,wBAAwB,EACxB,uBAAuB,EACvB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,cAAc,QAAQ,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import type { Camera2D, Vector2Like } from '@flighthq/types/contract';
2
- export declare function getCamera2DParallaxPoint(camera: Readonly<Camera2D>, factor: number, out: Vector2Like): void;
2
+ export declare function getCamera2DParallaxPoint(camera: Readonly<Camera2D>, viewportWidth: number, viewportHeight: number, factor: number, out: Vector2Like): void;
3
3
  //# sourceMappingURL=parallax.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parallax.d.ts","sourceRoot":"","sources":["../src/parallax.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAkBtE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,GAAG,IAAI,CAI3G"}
1
+ {"version":3,"file":"parallax.d.ts","sourceRoot":"","sources":["../src/parallax.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAkBtE,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,WAAW,GACf,IAAI,CAIN"}
package/dist/parallax.js CHANGED
@@ -14,10 +14,10 @@ import { getCamera2DViewMatrix } from './viewMatrix';
14
14
  //
15
15
  // Accounts for zoom and rotation through the view matrix, so a rotated/zoomed camera yields the
16
16
  // correctly transformed offset.
17
- export function getCamera2DParallaxPoint(camera, factor, out) {
18
- getCamera2DViewMatrix(camera, scratchMatrix);
19
- out.x = (scratchMatrix.tx - camera.viewportWidth * 0.5) * factor;
20
- out.y = (scratchMatrix.ty - camera.viewportHeight * 0.5) * factor;
17
+ export function getCamera2DParallaxPoint(camera, viewportWidth, viewportHeight, factor, out) {
18
+ getCamera2DViewMatrix(camera, viewportWidth, viewportHeight, scratchMatrix);
19
+ out.x = (scratchMatrix.tx - viewportWidth * 0.5) * factor;
20
+ out.y = (scratchMatrix.ty - viewportHeight * 0.5) * factor;
21
21
  }
22
22
  const scratchMatrix = createMatrix();
23
23
  //# sourceMappingURL=parallax.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parallax.js","sourceRoot":"","sources":["../src/parallax.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,2FAA2F;AAC3F,EAAE;AACF,mGAAmG;AACnG,sGAAsG;AACtG,sGAAsG;AACtG,6BAA6B;AAC7B,EAAE;AACF,qFAAqF;AACrF,kGAAkG;AAClG,uCAAuC;AACvC,kGAAkG;AAClG,EAAE;AACF,gGAAgG;AAChG,gCAAgC;AAChC,MAAM,UAAU,wBAAwB,CAAC,MAA0B,EAAE,MAAc,EAAE,GAAgB;IACnG,qBAAqB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,MAAM,CAAC,aAAa,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;IACjE,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,MAAM,CAAC,cAAc,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;AACpE,CAAC;AAED,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"parallax.js","sourceRoot":"","sources":["../src/parallax.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,2FAA2F;AAC3F,EAAE;AACF,mGAAmG;AACnG,sGAAsG;AACtG,sGAAsG;AACtG,6BAA6B;AAC7B,EAAE;AACF,qFAAqF;AACrF,kGAAkG;AAClG,uCAAuC;AACvC,kGAAkG;AAClG,EAAE;AACF,gGAAgG;AAChG,gCAAgC;AAChC,MAAM,UAAU,wBAAwB,CACtC,MAA0B,EAC1B,aAAqB,EACrB,cAAsB,EACtB,MAAc,EACd,GAAgB;IAEhB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAC5E,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,aAAa,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;IAC1D,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,GAAG,cAAc,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC;AAC7D,CAAC;AAED,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import type { Camera2D, Vector2Like } from '@flighthq/types/contract';
2
- export declare function projectCamera2DPoint(camera: Readonly<Camera2D>, worldX: number, worldY: number, out: Vector2Like): void;
3
- export declare function unprojectCamera2DPoint(camera: Readonly<Camera2D>, screenX: number, screenY: number, out: Vector2Like): void;
2
+ export declare function projectCamera2DPoint(camera: Readonly<Camera2D>, viewportWidth: number, viewportHeight: number, worldX: number, worldY: number, out: Vector2Like): void;
3
+ export declare function unprojectCamera2DPoint(camera: Readonly<Camera2D>, viewportWidth: number, viewportHeight: number, screenX: number, screenY: number, out: Vector2Like): void;
4
4
  //# sourceMappingURL=projection2d.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"projection2d.d.ts","sourceRoot":"","sources":["../src/projection2d.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMtE,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,WAAW,GACf,IAAI,CAGN;AAKD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,WAAW,GACf,IAAI,CAGN"}
1
+ {"version":3,"file":"projection2d.d.ts","sourceRoot":"","sources":["../src/projection2d.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMtE,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,WAAW,GACf,IAAI,CAGN;AAKD,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,WAAW,GACf,IAAI,CAGN"}
@@ -2,15 +2,15 @@ import { createMatrix, inverseMatrixTransformPointXY, matrixTransformPointXY } f
2
2
  import { getCamera2DViewMatrix } from './viewMatrix';
3
3
  // Projects a world point to its screen position through the camera's view matrix and writes the
4
4
  // result to `out` (world -> screen). The inverse is `unprojectCamera2DPoint`.
5
- export function projectCamera2DPoint(camera, worldX, worldY, out) {
6
- getCamera2DViewMatrix(camera, scratchMatrix);
5
+ export function projectCamera2DPoint(camera, viewportWidth, viewportHeight, worldX, worldY, out) {
6
+ getCamera2DViewMatrix(camera, viewportWidth, viewportHeight, scratchMatrix);
7
7
  matrixTransformPointXY(out, scratchMatrix, worldX, worldY);
8
8
  }
9
9
  // Unprojects a screen point back to the world point that renders there and writes it to `out`
10
10
  // (screen -> world). Uses the inverse of the camera's view matrix; the exact inverse of
11
11
  // `projectCamera2DPoint`.
12
- export function unprojectCamera2DPoint(camera, screenX, screenY, out) {
13
- getCamera2DViewMatrix(camera, scratchMatrix);
12
+ export function unprojectCamera2DPoint(camera, viewportWidth, viewportHeight, screenX, screenY, out) {
13
+ getCamera2DViewMatrix(camera, viewportWidth, viewportHeight, scratchMatrix);
14
14
  inverseMatrixTransformPointXY(out, scratchMatrix, screenX, screenY);
15
15
  }
16
16
  const scratchMatrix = createMatrix();
@@ -1 +1 @@
1
- {"version":3,"file":"projection2d.js","sourceRoot":"","sources":["../src/projection2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGlH,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,gGAAgG;AAChG,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAClC,MAA0B,EAC1B,MAAc,EACd,MAAc,EACd,GAAgB;IAEhB,qBAAqB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,sBAAsB,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED,8FAA8F;AAC9F,wFAAwF;AACxF,0BAA0B;AAC1B,MAAM,UAAU,sBAAsB,CACpC,MAA0B,EAC1B,OAAe,EACf,OAAe,EACf,GAAgB;IAEhB,qBAAqB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,6BAA6B,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"projection2d.js","sourceRoot":"","sources":["../src/projection2d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAGlH,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,gGAAgG;AAChG,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAClC,MAA0B,EAC1B,aAAqB,EACrB,cAAsB,EACtB,MAAc,EACd,MAAc,EACd,GAAgB;IAEhB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAC5E,sBAAsB,CAAC,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC7D,CAAC;AAED,8FAA8F;AAC9F,wFAAwF;AACxF,0BAA0B;AAC1B,MAAM,UAAU,sBAAsB,CACpC,MAA0B,EAC1B,aAAqB,EACrB,cAAsB,EACtB,OAAe,EACf,OAAe,EACf,GAAgB;IAEhB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAC5E,6BAA6B,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import type { Camera2D, MatrixLike } from '@flighthq/types/contract';
2
- export declare function getCamera2DViewMatrix(camera: Readonly<Camera2D>, out: MatrixLike): void;
2
+ export declare function getCamera2DViewMatrix(camera: Readonly<Camera2D>, viewportWidth: number, viewportHeight: number, out: MatrixLike): void;
3
3
  //# sourceMappingURL=viewMatrix.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewMatrix.d.ts","sourceRoot":"","sources":["../src/viewMatrix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAcrE,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAIvF"}
1
+ {"version":3,"file":"viewMatrix.d.ts","sourceRoot":"","sources":["../src/viewMatrix.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAcrE,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,UAAU,GACd,IAAI,CAIN"}
@@ -11,9 +11,9 @@ import { setTransformMatrix, translateMatrixByVectorXY } from '@flighthq/geometr
11
11
  // `T(center) * R(-rotation) * S(zoom)` head; `translateMatrixByVectorXY` post-multiplies the inner
12
12
  // `T(-x, -y)` in world space, leaving the linear part (a, b, c, d) untouched. Alias-safe: `out` may
13
13
  // be any matrix, including one aliased with a scratch used elsewhere.
14
- export function getCamera2DViewMatrix(camera, out) {
14
+ export function getCamera2DViewMatrix(camera, viewportWidth, viewportHeight, out) {
15
15
  const zoom = camera.zoom;
16
- setTransformMatrix(out, zoom, zoom, -camera.rotation, camera.viewportWidth * 0.5, camera.viewportHeight * 0.5);
16
+ setTransformMatrix(out, zoom, zoom, -camera.rotation, viewportWidth * 0.5, viewportHeight * 0.5);
17
17
  translateMatrixByVectorXY(out, out, -camera.x, -camera.y);
18
18
  }
19
19
  //# sourceMappingURL=viewMatrix.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewMatrix.js","sourceRoot":"","sources":["../src/viewMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAG5F,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,EAAE;AACF,qGAAqG;AACrG,EAAE;AACF,kGAAkG;AAClG,iGAAiG;AACjG,wFAAwF;AACxF,mGAAmG;AACnG,oGAAoG;AACpG,sEAAsE;AACtE,MAAM,UAAU,qBAAqB,CAAC,MAA0B,EAAE,GAAe;IAC/E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACzB,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,aAAa,GAAG,GAAG,EAAE,MAAM,CAAC,cAAc,GAAG,GAAG,CAAC,CAAC;IAC/G,yBAAyB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC"}
1
+ {"version":3,"file":"viewMatrix.js","sourceRoot":"","sources":["../src/viewMatrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAG5F,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,EAAE;AACF,qGAAqG;AACrG,EAAE;AACF,kGAAkG;AAClG,iGAAiG;AACjG,wFAAwF;AACxF,mGAAmG;AACnG,oGAAoG;AACpG,sEAAsE;AACtE,MAAM,UAAU,qBAAqB,CACnC,MAA0B,EAC1B,aAAqB,EACrB,cAAsB,EACtB,GAAe;IAEf,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACzB,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,GAAG,GAAG,EAAE,cAAc,GAAG,GAAG,CAAC,CAAC;IACjG,yBAAyB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC"}
@@ -1,4 +1,4 @@
1
1
  import type { Camera2D, RectangleLike } from '@flighthq/types/contract';
2
- export declare function getCamera2DVisibleBounds(camera: Readonly<Camera2D>, out: RectangleLike): void;
2
+ export declare function getCamera2DVisibleBounds(camera: Readonly<Camera2D>, viewportWidth: number, viewportHeight: number, out: RectangleLike): void;
3
3
  export declare function setCamera2DVisibleBoundsGuard(guard: ((camera: Readonly<Camera2D>) => void) | null): void;
4
4
  //# sourceMappingURL=visibleBounds.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"visibleBounds.d.ts","sourceRoot":"","sources":["../src/visibleBounds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAkBxE,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAW7F;AAID,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAExG"}
1
+ {"version":3,"file":"visibleBounds.d.ts","sourceRoot":"","sources":["../src/visibleBounds.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAkBxE,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAC1B,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,aAAa,GACjB,IAAI,CAWN;AAID,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAExG"}
@@ -14,8 +14,8 @@ import { getCamera2DViewMatrix } from './viewMatrix';
14
14
  // nothing. The asymmetry is the whole reason: over-drawing is slow and visible, under-drawing is
15
15
  // silent and wrong, and a cull bound that silently collapses removes content with nothing to point at
16
16
  // the cause.
17
- export function getCamera2DVisibleBounds(camera, out) {
18
- getCamera2DViewMatrix(camera, scratchMatrix);
17
+ export function getCamera2DVisibleBounds(camera, viewportWidth, viewportHeight, out) {
18
+ getCamera2DViewMatrix(camera, viewportWidth, viewportHeight, scratchMatrix);
19
19
  if (!inverseMatrix(scratchInverse, scratchMatrix)) {
20
20
  out.x = UNBOUNDED_ORIGIN;
21
21
  out.y = UNBOUNDED_ORIGIN;
@@ -24,7 +24,7 @@ export function getCamera2DVisibleBounds(camera, out) {
24
24
  degenerateVisibleBoundsGuard?.(camera);
25
25
  return;
26
26
  }
27
- matrixTransformBounds(out, scratchInverse, 0, 0, camera.viewportWidth, camera.viewportHeight);
27
+ matrixTransformBounds(out, scratchInverse, 0, 0, viewportWidth, viewportHeight);
28
28
  }
29
29
  // The seam the guard layer installs into; `null` keeps this module free of message text and of any
30
30
  // dependency on @flighthq/log, so an application that never imports the guards sheds both.
@@ -1 +1 @@
1
- {"version":3,"file":"visibleBounds.js","sourceRoot":"","sources":["../src/visibleBounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAGjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,sGAAsG;AACtG,qGAAqG;AACrG,oGAAoG;AACpG,+FAA+F;AAC/F,kGAAkG;AAClG,gEAAgE;AAChE,EAAE;AACF,qGAAqG;AACrG,sGAAsG;AACtG,oGAAoG;AACpG,mGAAmG;AACnG,iGAAiG;AACjG,sGAAsG;AACtG,aAAa;AACb,MAAM,UAAU,wBAAwB,CAAC,MAA0B,EAAE,GAAkB;IACrF,qBAAqB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,CAAC,GAAG,gBAAgB,CAAC;QACzB,GAAG,CAAC,CAAC,GAAG,gBAAgB,CAAC;QACzB,GAAG,CAAC,KAAK,GAAG,gBAAgB,CAAC;QAC7B,GAAG,CAAC,MAAM,GAAG,gBAAgB,CAAC;QAC9B,4BAA4B,EAAE,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IACD,qBAAqB,CAAC,GAAG,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;AAChG,CAAC;AAED,mGAAmG;AACnG,2FAA2F;AAC3F,MAAM,UAAU,6BAA6B,CAAC,KAAoD;IAChG,4BAA4B,GAAG,KAAK,CAAC;AACvC,CAAC;AAED,sGAAsG;AACtG,wGAAwG;AACxG,mGAAmG;AACnG,qGAAqG;AACrG,sGAAsG;AACtG,iFAAiF;AACjF,MAAM,gBAAgB,GAAG,MAAM,CAAC,SAAS,CAAC;AAC1C,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;AAE/C,IAAI,4BAA4B,GAAkD,IAAI,CAAC;AACvF,MAAM,cAAc,GAAG,YAAY,EAAE,CAAC;AACtC,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"visibleBounds.js","sourceRoot":"","sources":["../src/visibleBounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAGjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,sGAAsG;AACtG,qGAAqG;AACrG,oGAAoG;AACpG,+FAA+F;AAC/F,kGAAkG;AAClG,gEAAgE;AAChE,EAAE;AACF,qGAAqG;AACrG,sGAAsG;AACtG,oGAAoG;AACpG,mGAAmG;AACnG,iGAAiG;AACjG,sGAAsG;AACtG,aAAa;AACb,MAAM,UAAU,wBAAwB,CACtC,MAA0B,EAC1B,aAAqB,EACrB,cAAsB,EACtB,GAAkB;IAElB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;IAC5E,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,CAAC,GAAG,gBAAgB,CAAC;QACzB,GAAG,CAAC,CAAC,GAAG,gBAAgB,CAAC;QACzB,GAAG,CAAC,KAAK,GAAG,gBAAgB,CAAC;QAC7B,GAAG,CAAC,MAAM,GAAG,gBAAgB,CAAC;QAC9B,4BAA4B,EAAE,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IACD,qBAAqB,CAAC,GAAG,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC;AAClF,CAAC;AAED,mGAAmG;AACnG,2FAA2F;AAC3F,MAAM,UAAU,6BAA6B,CAAC,KAAoD;IAChG,4BAA4B,GAAG,KAAK,CAAC;AACvC,CAAC;AAED,sGAAsG;AACtG,wGAAwG;AACxG,mGAAmG;AACnG,qGAAqG;AACrG,sGAAsG;AACtG,iFAAiF;AACjF,MAAM,gBAAgB,GAAG,MAAM,CAAC,SAAS,CAAC;AAC1C,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,CAAC;AAE/C,IAAI,4BAA4B,GAAkD,IAAI,CAAC;AACvF,MAAM,cAAc,GAAG,YAAY,EAAE,CAAC;AACtC,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC"}
package/dist/zoom.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import type { Camera2D } from '@flighthq/types/contract';
2
- export declare function zoomCamera2DAtScreenPoint(camera: Camera2D, screenX: number, screenY: number, zoom: number): void;
2
+ export declare function zoomCamera2DAtScreenPoint(camera: Camera2D, viewportWidth: number, viewportHeight: number, screenX: number, screenY: number, zoom: number): void;
3
3
  //# sourceMappingURL=zoom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"zoom.d.ts","sourceRoot":"","sources":["../src/zoom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAWzD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAMhH"}
1
+ {"version":3,"file":"zoom.d.ts","sourceRoot":"","sources":["../src/zoom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAWzD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,EAChB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,GACX,IAAI,CAMN"}
package/dist/zoom.js CHANGED
@@ -7,10 +7,10 @@ import { unprojectCamera2DPoint } from './projection2d';
7
7
  //
8
8
  // Reads the pre-zoom world point, applies the new zoom, then adjusts `x`/`y` by the difference so the
9
9
  // same screen point unprojects to the same world point as before.
10
- export function zoomCamera2DAtScreenPoint(camera, screenX, screenY, zoom) {
11
- unprojectCamera2DPoint(camera, screenX, screenY, scratchBefore);
10
+ export function zoomCamera2DAtScreenPoint(camera, viewportWidth, viewportHeight, screenX, screenY, zoom) {
11
+ unprojectCamera2DPoint(camera, viewportWidth, viewportHeight, screenX, screenY, scratchBefore);
12
12
  camera.zoom = zoom;
13
- unprojectCamera2DPoint(camera, screenX, screenY, scratchAfter);
13
+ unprojectCamera2DPoint(camera, viewportWidth, viewportHeight, screenX, screenY, scratchAfter);
14
14
  camera.x += scratchBefore.x - scratchAfter.x;
15
15
  camera.y += scratchBefore.y - scratchAfter.y;
16
16
  }
package/dist/zoom.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"zoom.js","sourceRoot":"","sources":["../src/zoom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,oGAAoG;AACpG,oGAAoG;AACpG,+FAA+F;AAC/F,2FAA2F;AAC3F,EAAE;AACF,sGAAsG;AACtG,kEAAkE;AAClE,MAAM,UAAU,yBAAyB,CAAC,MAAgB,EAAE,OAAe,EAAE,OAAe,EAAE,IAAY;IACxG,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAChE,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC/D,MAAM,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,YAAY,GAAG,aAAa,EAAE,CAAC;AACrC,MAAM,aAAa,GAAG,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"zoom.js","sourceRoot":"","sources":["../src/zoom.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAExD,oGAAoG;AACpG,oGAAoG;AACpG,+FAA+F;AAC/F,2FAA2F;AAC3F,EAAE;AACF,sGAAsG;AACtG,kEAAkE;AAClE,MAAM,UAAU,yBAAyB,CACvC,MAAgB,EAChB,aAAqB,EACrB,cAAsB,EACtB,OAAe,EACf,OAAe,EACf,IAAY;IAEZ,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;IAC/F,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9F,MAAM,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAC7C,MAAM,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,YAAY,GAAG,aAAa,EAAE,CAAC;AACrC,MAAM,aAAa,GAAG,aAAa,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/camera",
3
- "version": "0.5.1-edge.1471.4e82419",
3
+ "version": "0.5.1-edge.1685.dc0e23a",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,10 +38,10 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/entity": "0.5.1-edge.1471.4e82419",
42
- "@flighthq/geometry": "0.5.1-edge.1471.4e82419",
43
- "@flighthq/log": "0.5.1-edge.1471.4e82419",
44
- "@flighthq/types": "0.5.1-edge.1471.4e82419"
41
+ "@flighthq/entity": "0.5.1-edge.1685.dc0e23a",
42
+ "@flighthq/geometry": "0.5.1-edge.1685.dc0e23a",
43
+ "@flighthq/log": "0.5.1-edge.1685.dc0e23a",
44
+ "@flighthq/types": "0.5.1-edge.1685.dc0e23a"
45
45
  },
46
46
  "devDependencies": {
47
47
  "typescript": "^5.3.0"
@@ -1,12 +1,10 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
 
3
- import { createCamera2D, initializeCamera2D } from './camera2d';
3
+ import { createCamera2D, initializeCamera2D, setCamera2DLookAt } from './camera2d';
4
4
 
5
5
  describe('createCamera2D', () => {
6
6
  it('uses identity defaults for an unconfigured camera', () => {
7
- const camera = createCamera2D(800, 600);
8
- expect(camera.viewportWidth).toBe(800);
9
- expect(camera.viewportHeight).toBe(600);
7
+ const camera = createCamera2D();
10
8
  expect(camera.x).toBe(0);
11
9
  expect(camera.y).toBe(0);
12
10
  expect(camera.zoom).toBe(1);
@@ -14,7 +12,7 @@ describe('createCamera2D', () => {
14
12
  });
15
13
 
16
14
  it('applies overrides from options', () => {
17
- const camera = createCamera2D(1024, 768, { x: 10, y: 20, zoom: 2, rotation: Math.PI / 4 });
15
+ const camera = createCamera2D({ x: 10, y: 20, zoom: 2, rotation: Math.PI / 4 });
18
16
  expect(camera.x).toBe(10);
19
17
  expect(camera.y).toBe(20);
20
18
  expect(camera.zoom).toBe(2);
@@ -26,3 +24,19 @@ describe('initializeCamera2D', () => {
26
24
  expect(typeof initializeCamera2D).toBe('function');
27
25
  });
28
26
  });
27
+
28
+ describe('setCamera2DLookAt', () => {
29
+ it('centers the camera on a world position', () => {
30
+ const camera = createCamera2D();
31
+ setCamera2DLookAt(camera, 100, 200);
32
+ expect(camera.x).toBe(100);
33
+ expect(camera.y).toBe(200);
34
+ });
35
+
36
+ it('overwrites a previous position', () => {
37
+ const camera = createCamera2D({ x: 50, y: 60 });
38
+ setCamera2DLookAt(camera, -10, 30);
39
+ expect(camera.x).toBe(-10);
40
+ expect(camera.y).toBe(30);
41
+ });
42
+ });
@@ -25,7 +25,7 @@ describe('disableCameraGuards', () => {
25
25
  test('leaves the core silent again once removed', () => {
26
26
  enableCameraGuards();
27
27
  disableCameraGuards();
28
- expect(captureLog(() => getCamera2DVisibleBounds(degenerateCamera(), createRectangle()))).toHaveLength(0);
28
+ expect(captureLog(() => getCamera2DVisibleBounds(degenerateCamera(), 64, 64, createRectangle()))).toHaveLength(0);
29
29
  });
30
30
  });
31
31
 
@@ -35,7 +35,7 @@ describe('enableCameraGuards', () => {
35
35
  // directly, and deterministically, in visibleBounds.test.ts.
36
36
  test('warns, naming the zoom and the consequence, when the visible bounds cannot be computed', () => {
37
37
  enableCameraGuards();
38
- const entries = captureLog(() => getCamera2DVisibleBounds(degenerateCamera(), createRectangle()));
38
+ const entries = captureLog(() => getCamera2DVisibleBounds(degenerateCamera(), 64, 64, createRectangle()));
39
39
  expect(entries).toHaveLength(1);
40
40
  expect(entries[0].data).toMatchObject({ zoom: 0 });
41
41
  expect(String((entries[0].data as { message: string }).message)).toContain('nothing is culled');
@@ -72,7 +72,7 @@ describe('enableCameraGuards', () => {
72
72
 
73
73
  test('stays silent for a camera whose view matrix inverts', () => {
74
74
  enableCameraGuards();
75
- expect(captureLog(() => getCamera2DVisibleBounds(createCamera2D(64, 64), createRectangle()))).toHaveLength(0);
75
+ expect(captureLog(() => getCamera2DVisibleBounds(createCamera2D(), 64, 64, createRectangle()))).toHaveLength(0);
76
76
  });
77
77
  });
78
78
 
@@ -92,5 +92,5 @@ function captureLog(run: () => void): LogEntry[] {
92
92
  }
93
93
 
94
94
  function degenerateCamera(): Camera2D {
95
- return createCamera2D(64, 64, { zoom: 0 });
95
+ return createCamera2D({ zoom: 0 });
96
96
  }
@@ -6,25 +6,25 @@ import { getCamera2DParallaxPoint } from './parallax';
6
6
 
7
7
  describe('getCamera2DParallaxPoint', () => {
8
8
  it('returns no offset at factor 0 (screen-locked layer)', () => {
9
- const camera = createCamera2D(800, 600, { x: 100, y: 50 });
9
+ const camera = createCamera2D({ x: 100, y: 50 });
10
10
  const out = createVector2();
11
- getCamera2DParallaxPoint(camera, 0, out);
11
+ getCamera2DParallaxPoint(camera, 800, 600, 0, out);
12
12
  expect(out.x).toBeCloseTo(0, 9);
13
13
  expect(out.y).toBeCloseTo(0, 9);
14
14
  });
15
15
 
16
16
  it('returns the full camera screen offset at factor 1 (world-locked layer)', () => {
17
- const camera = createCamera2D(800, 600, { x: 100, y: 50 });
17
+ const camera = createCamera2D({ x: 100, y: 50 });
18
18
  const out = createVector2();
19
- getCamera2DParallaxPoint(camera, 1, out);
19
+ getCamera2DParallaxPoint(camera, 800, 600, 1, out);
20
20
  expect(out.x).toBeCloseTo(-100, 9);
21
21
  expect(out.y).toBeCloseTo(-50, 9);
22
22
  });
23
23
 
24
24
  it('returns half the camera offset at factor 0.5', () => {
25
- const camera = createCamera2D(800, 600, { x: 100, y: 50 });
25
+ const camera = createCamera2D({ x: 100, y: 50 });
26
26
  const out = createVector2();
27
- getCamera2DParallaxPoint(camera, 0.5, out);
27
+ getCamera2DParallaxPoint(camera, 800, 600, 0.5, out);
28
28
  expect(out.x).toBeCloseTo(-50, 9);
29
29
  expect(out.y).toBeCloseTo(-25, 9);
30
30
  });
@@ -6,17 +6,17 @@ import { projectCamera2DPoint, unprojectCamera2DPoint } from './projection2d';
6
6
 
7
7
  describe('projectCamera2DPoint', () => {
8
8
  it('projects the camera center to the viewport center', () => {
9
- const camera = createCamera2D(800, 600);
9
+ const camera = createCamera2D();
10
10
  const out = createVector2();
11
- projectCamera2DPoint(camera, 0, 0, out);
11
+ projectCamera2DPoint(camera, 800, 600, 0, 0, out);
12
12
  expect(out.x).toBeCloseTo(400, 9);
13
13
  expect(out.y).toBeCloseTo(300, 9);
14
14
  });
15
15
 
16
16
  it('accounts for zoom', () => {
17
- const camera = createCamera2D(800, 600, { zoom: 2 });
17
+ const camera = createCamera2D({ zoom: 2 });
18
18
  const out = createVector2();
19
- projectCamera2DPoint(camera, 100, 0, out);
19
+ projectCamera2DPoint(camera, 800, 600, 100, 0, out);
20
20
  expect(out.x).toBeCloseTo(600, 9);
21
21
  expect(out.y).toBeCloseTo(300, 9);
22
22
  });
@@ -24,19 +24,25 @@ describe('projectCamera2DPoint', () => {
24
24
 
25
25
  describe('unprojectCamera2DPoint', () => {
26
26
  it('unprojects the viewport center to the camera position', () => {
27
- const camera = createCamera2D(800, 600, { x: 25, y: 40 });
27
+ const camera = createCamera2D({ x: 25, y: 40 });
28
28
  const out = createVector2();
29
- unprojectCamera2DPoint(camera, 400, 300, out);
29
+ unprojectCamera2DPoint(camera, 800, 600, 400, 300, out);
30
30
  expect(out.x).toBeCloseTo(25, 9);
31
31
  expect(out.y).toBeCloseTo(40, 9);
32
32
  });
33
33
 
34
34
  it('round-trips project then unproject across zooms and rotations', () => {
35
35
  const cameras = [
36
- createCamera2D(800, 600),
37
- createCamera2D(800, 600, { x: 120, y: -80, zoom: 2 }),
38
- createCamera2D(1024, 768, { x: -50, y: 200, zoom: 0.5, rotation: Math.PI / 3 }),
39
- createCamera2D(640, 480, { x: 10, y: 10, zoom: 1.5, rotation: -Math.PI / 6 }),
36
+ createCamera2D(),
37
+ createCamera2D({ x: 120, y: -80, zoom: 2 }),
38
+ createCamera2D({ x: -50, y: 200, zoom: 0.5, rotation: Math.PI / 3 }),
39
+ createCamera2D({ x: 10, y: 10, zoom: 1.5, rotation: -Math.PI / 6 }),
40
+ ];
41
+ const viewports: ReadonlyArray<readonly [number, number]> = [
42
+ [800, 600],
43
+ [800, 600],
44
+ [1024, 768],
45
+ [640, 480],
40
46
  ];
41
47
  const points: ReadonlyArray<readonly [number, number]> = [
42
48
  [0, 0],
@@ -46,10 +52,12 @@ describe('unprojectCamera2DPoint', () => {
46
52
  ];
47
53
  const screen = createVector2();
48
54
  const world = createVector2();
49
- for (const camera of cameras) {
55
+ for (let i = 0; i < cameras.length; i++) {
56
+ const camera = cameras[i];
57
+ const [vw, vh] = viewports[i];
50
58
  for (const [px, py] of points) {
51
- projectCamera2DPoint(camera, px, py, screen);
52
- unprojectCamera2DPoint(camera, screen.x, screen.y, world);
59
+ projectCamera2DPoint(camera, vw, vh, px, py, screen);
60
+ unprojectCamera2DPoint(camera, vw, vh, screen.x, screen.y, world);
53
61
  expect(world.x).toBeCloseTo(px, 6);
54
62
  expect(world.y).toBeCloseTo(py, 6);
55
63
  }
@@ -6,9 +6,9 @@ import { getCamera2DViewMatrix } from './viewMatrix';
6
6
 
7
7
  describe('getCamera2DViewMatrix', () => {
8
8
  it('maps the camera center world point to the viewport center', () => {
9
- const camera = createCamera2D(800, 600);
9
+ const camera = createCamera2D();
10
10
  const view = createMatrix();
11
- getCamera2DViewMatrix(camera, view);
11
+ getCamera2DViewMatrix(camera, 800, 600, view);
12
12
  const out = createVector2();
13
13
  matrixTransformPointXY(out, view, 0, 0);
14
14
  expect(out.x).toBeCloseTo(400, 9);
@@ -16,9 +16,9 @@ describe('getCamera2DViewMatrix', () => {
16
16
  });
17
17
 
18
18
  it('projects a right-of-center world point at zoom 1', () => {
19
- const camera = createCamera2D(800, 600);
19
+ const camera = createCamera2D();
20
20
  const view = createMatrix();
21
- getCamera2DViewMatrix(camera, view);
21
+ getCamera2DViewMatrix(camera, 800, 600, view);
22
22
  const out = createVector2();
23
23
  matrixTransformPointXY(out, view, 100, 0);
24
24
  expect(out.x).toBeCloseTo(500, 9);
@@ -26,9 +26,9 @@ describe('getCamera2DViewMatrix', () => {
26
26
  });
27
27
 
28
28
  it('magnifies about the center at zoom 2', () => {
29
- const camera = createCamera2D(800, 600, { zoom: 2 });
29
+ const camera = createCamera2D({ zoom: 2 });
30
30
  const view = createMatrix();
31
- getCamera2DViewMatrix(camera, view);
31
+ getCamera2DViewMatrix(camera, 800, 600, view);
32
32
  const out = createVector2();
33
33
  matrixTransformPointXY(out, view, 100, 0);
34
34
  expect(out.x).toBeCloseTo(600, 9);
@@ -37,9 +37,9 @@ describe('getCamera2DViewMatrix', () => {
37
37
 
38
38
  it('rotates the view opposite the camera rotation', () => {
39
39
  // Camera3D rotated +90deg (CCW): a world point to the right appears above the center.
40
- const camera = createCamera2D(800, 600, { rotation: Math.PI / 2 });
40
+ const camera = createCamera2D({ rotation: Math.PI / 2 });
41
41
  const view = createMatrix();
42
- getCamera2DViewMatrix(camera, view);
42
+ getCamera2DViewMatrix(camera, 800, 600, view);
43
43
  const out = createVector2();
44
44
  matrixTransformPointXY(out, view, 100, 0);
45
45
  expect(out.x).toBeCloseTo(400, 9);
@@ -7,9 +7,9 @@ import { getCamera2DVisibleBounds, setCamera2DVisibleBoundsGuard } from './visib
7
7
 
8
8
  describe('getCamera2DVisibleBounds', () => {
9
9
  it('covers the full viewport in world units at zoom 1', () => {
10
- const camera = createCamera2D(800, 600);
10
+ const camera = createCamera2D();
11
11
  const out = createRectangle();
12
- getCamera2DVisibleBounds(camera, out);
12
+ getCamera2DVisibleBounds(camera, 800, 600, out);
13
13
  expect(out.x).toBeCloseTo(-400, 9);
14
14
  expect(out.y).toBeCloseTo(-300, 9);
15
15
  expect(out.width).toBeCloseTo(800, 9);
@@ -17,9 +17,9 @@ describe('getCamera2DVisibleBounds', () => {
17
17
  });
18
18
 
19
19
  it('shrinks to half size centered at zoom 2', () => {
20
- const camera = createCamera2D(800, 600, { zoom: 2 });
20
+ const camera = createCamera2D({ zoom: 2 });
21
21
  const out = createRectangle();
22
- getCamera2DVisibleBounds(camera, out);
22
+ getCamera2DVisibleBounds(camera, 800, 600, out);
23
23
  expect(out.x).toBeCloseTo(-200, 9);
24
24
  expect(out.y).toBeCloseTo(-150, 9);
25
25
  expect(out.width).toBeCloseTo(400, 9);
@@ -27,9 +27,9 @@ describe('getCamera2DVisibleBounds', () => {
27
27
  });
28
28
 
29
29
  it('returns the enclosing AABB of a rotated view, larger than the viewport', () => {
30
- const camera = createCamera2D(800, 600, { rotation: Math.PI / 4 });
30
+ const camera = createCamera2D({ rotation: Math.PI / 4 });
31
31
  const out = createRectangle();
32
- getCamera2DVisibleBounds(camera, out);
32
+ getCamera2DVisibleBounds(camera, 800, 600, out);
33
33
  // AABB of an 800x600 rect rotated 45deg: both extents = (800 + 600) * cos(45deg).
34
34
  expect(out.width).toBeCloseTo(989.9494936611666, 6);
35
35
  expect(out.height).toBeCloseTo(989.9494936611666, 6);
@@ -44,7 +44,7 @@ describe('getCamera2DVisibleBounds', () => {
44
44
  [0, 600],
45
45
  ];
46
46
  for (const [sx, sy] of corners) {
47
- unprojectCamera2DPoint(camera, sx, sy, corner);
47
+ unprojectCamera2DPoint(camera, 800, 600, sx, sy, corner);
48
48
  expect(corner.x).toBeGreaterThanOrEqual(out.x - 1e-6);
49
49
  expect(corner.x).toBeLessThanOrEqual(out.x + out.width + 1e-6);
50
50
  expect(corner.y).toBeGreaterThanOrEqual(out.y - 1e-6);
@@ -56,7 +56,7 @@ describe('getCamera2DVisibleBounds', () => {
56
56
  describe('setCamera2DVisibleBoundsGuard', () => {
57
57
  test('fails toward drawing: an unbounded rectangle that still intersects distant content', () => {
58
58
  const out = createRectangle();
59
- getCamera2DVisibleBounds(createCamera2D(64, 64, { zoom: 0 }), out);
59
+ getCamera2DVisibleBounds(createCamera2D({ zoom: 0 }), 64, 64, out);
60
60
  // Finite on purpose — the max edge must survive ordinary arithmetic, not rely on NaN comparisons.
61
61
  expect(Number.isFinite(out.x + out.width)).toBe(true);
62
62
  expect(Number.isFinite(out.y + out.height)).toBe(true);
@@ -69,8 +69,8 @@ describe('setCamera2DVisibleBoundsGuard', () => {
69
69
  const seen: number[] = [];
70
70
  setCamera2DVisibleBoundsGuard((camera) => seen.push(camera.zoom));
71
71
  try {
72
- getCamera2DVisibleBounds(createCamera2D(64, 64, { zoom: 0 }), createRectangle());
73
- getCamera2DVisibleBounds(createCamera2D(64, 64), createRectangle());
72
+ getCamera2DVisibleBounds(createCamera2D({ zoom: 0 }), 64, 64, createRectangle());
73
+ getCamera2DVisibleBounds(createCamera2D(), 64, 64, createRectangle());
74
74
  expect(seen).toEqual([0]);
75
75
  } finally {
76
76
  setCamera2DVisibleBoundsGuard(null);
@@ -79,7 +79,7 @@ describe('setCamera2DVisibleBoundsGuard', () => {
79
79
 
80
80
  test('leaves an invertible camera computing the same bounds as before', () => {
81
81
  const out = createRectangle();
82
- getCamera2DVisibleBounds(createCamera2D(64, 32), out);
82
+ getCamera2DVisibleBounds(createCamera2D(), 64, 32, out);
83
83
  expect(out.width).toBeCloseTo(64, 6);
84
84
  expect(out.height).toBeCloseTo(32, 6);
85
85
  });
package/src/zoom.test.ts CHANGED
@@ -7,14 +7,14 @@ import { zoomCamera2DAtScreenPoint } from './zoom';
7
7
 
8
8
  describe('zoomCamera2DAtScreenPoint', () => {
9
9
  it('keeps the world point under a screen corner fixed while zooming', () => {
10
- const camera = createCamera2D(800, 600);
10
+ const camera = createCamera2D();
11
11
  const before = createVector2();
12
- unprojectCamera2DPoint(camera, 0, 0, before);
12
+ unprojectCamera2DPoint(camera, 800, 600, 0, 0, before);
13
13
 
14
- zoomCamera2DAtScreenPoint(camera, 0, 0, 2);
14
+ zoomCamera2DAtScreenPoint(camera, 800, 600, 0, 0, 2);
15
15
 
16
16
  const after = createVector2();
17
- unprojectCamera2DPoint(camera, 0, 0, after);
17
+ unprojectCamera2DPoint(camera, 800, 600, 0, 0, after);
18
18
  expect(camera.zoom).toBe(2);
19
19
  expect(after.x).toBeCloseTo(before.x, 9);
20
20
  expect(after.y).toBeCloseTo(before.y, 9);
@@ -24,14 +24,14 @@ describe('zoomCamera2DAtScreenPoint', () => {
24
24
  });
25
25
 
26
26
  it('keeps an arbitrary screen point fixed under a rotated camera', () => {
27
- const camera = createCamera2D(800, 600, { x: 30, y: -20, zoom: 1.5, rotation: Math.PI / 5 });
27
+ const camera = createCamera2D({ x: 30, y: -20, zoom: 1.5, rotation: Math.PI / 5 });
28
28
  const before = createVector2();
29
- unprojectCamera2DPoint(camera, 250, 175, before);
29
+ unprojectCamera2DPoint(camera, 800, 600, 250, 175, before);
30
30
 
31
- zoomCamera2DAtScreenPoint(camera, 250, 175, 3);
31
+ zoomCamera2DAtScreenPoint(camera, 800, 600, 250, 175, 3);
32
32
 
33
33
  const after = createVector2();
34
- unprojectCamera2DPoint(camera, 250, 175, after);
34
+ unprojectCamera2DPoint(camera, 800, 600, 250, 175, after);
35
35
  expect(camera.zoom).toBe(3);
36
36
  expect(after.x).toBeCloseTo(before.x, 6);
37
37
  expect(after.y).toBeCloseTo(before.y, 6);