@docyrus/animaguru 0.6.0
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/NOTICE.md +256 -0
- package/README.md +241 -0
- package/dist/animaguru.js +27338 -0
- package/package.json +37 -0
- package/skills/animaguru/SKILL.md +115 -0
- package/skills/animaguru-advertising/SKILL.md +25 -0
- package/skills/animaguru-advertising/references/brand-bumper.md +11 -0
- package/skills/animaguru-advertising/references/comparison.md +11 -0
- package/skills/animaguru-advertising/references/creator-testimonial.md +11 -0
- package/skills/animaguru-advertising/references/editorial-advertorial.md +11 -0
- package/skills/animaguru-advertising/references/game-reward.md +11 -0
- package/skills/animaguru-advertising/references/offer-promotion.md +11 -0
- package/skills/animaguru-advertising/references/product-launch.md +11 -0
- package/skills/animaguru-advertising/references/product-proof.md +11 -0
- package/skills/animaguru-analog-film-tape/SKILL.md +29 -0
- package/skills/animaguru-analog-film-tape/references/recipe.md +23 -0
- package/skills/animaguru-animated-data-visualization/SKILL.md +39 -0
- package/skills/animaguru-animated-data-visualization/references/data-contract.md +16 -0
- package/skills/animaguru-animated-data-visualization/references/variants.md +17 -0
- package/skills/animaguru-art-deco-motion/SKILL.md +29 -0
- package/skills/animaguru-art-deco-motion/references/recipe.md +22 -0
- package/skills/animaguru-ascii-crt/SKILL.md +29 -0
- package/skills/animaguru-ascii-crt/references/recipe.md +22 -0
- package/skills/animaguru-blueprint-drafting/SKILL.md +29 -0
- package/skills/animaguru-blueprint-drafting/references/recipe.md +22 -0
- package/skills/animaguru-cartoon-character-animation/SKILL.md +35 -0
- package/skills/animaguru-cartoon-character-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/SKILL.md +33 -0
- package/skills/animaguru-cutout-animation/references/production-recipe.md +37 -0
- package/skills/animaguru-cutout-animation/references/variants.md +17 -0
- package/skills/animaguru-cutout-animation/references/visual-style.md +34 -0
- package/skills/animaguru-dark-tech-stage/SKILL.md +29 -0
- package/skills/animaguru-dark-tech-stage/references/recipe.md +23 -0
- package/skills/animaguru-diagram-formula-motion/SKILL.md +36 -0
- package/skills/animaguru-diagram-formula-motion/references/variants.md +17 -0
- package/skills/animaguru-engraved-relief-print/SKILL.md +29 -0
- package/skills/animaguru-engraved-relief-print/references/recipe.md +24 -0
- package/skills/animaguru-flat-vector-motion/SKILL.md +35 -0
- package/skills/animaguru-flat-vector-motion/references/variants.md +17 -0
- package/skills/animaguru-general-video/SKILL.md +20 -0
- package/skills/animaguru-general-video/references/ambient-loop.md +11 -0
- package/skills/animaguru-general-video/references/music-lyrics.md +11 -0
- package/skills/animaguru-general-video/references/short-film.md +11 -0
- package/skills/animaguru-general-video/references/titles-event.md +11 -0
- package/skills/animaguru-general-video/references/visual-essay.md +11 -0
- package/skills/animaguru-generative-light-signal/SKILL.md +29 -0
- package/skills/animaguru-generative-light-signal/references/recipe.md +23 -0
- package/skills/animaguru-glass-mosaic/SKILL.md +29 -0
- package/skills/animaguru-glass-mosaic/references/recipe.md +23 -0
- package/skills/animaguru-halftone-editorial/SKILL.md +29 -0
- package/skills/animaguru-halftone-editorial/references/recipe.md +23 -0
- package/skills/animaguru-holographic-scan/SKILL.md +29 -0
- package/skills/animaguru-holographic-scan/references/recipe.md +22 -0
- package/skills/animaguru-interface-motion/SKILL.md +36 -0
- package/skills/animaguru-interface-motion/references/screen-mapping.md +16 -0
- package/skills/animaguru-interface-motion/references/variants.md +17 -0
- package/skills/animaguru-isometric-worlds/SKILL.md +35 -0
- package/skills/animaguru-isometric-worlds/references/variants.md +17 -0
- package/skills/animaguru-kinetic-typography/SKILL.md +35 -0
- package/skills/animaguru-kinetic-typography/references/variants.md +17 -0
- package/skills/animaguru-miniature-diorama/SKILL.md +29 -0
- package/skills/animaguru-miniature-diorama/references/recipe.md +23 -0
- package/skills/animaguru-painterly-depth-animation/SKILL.md +35 -0
- package/skills/animaguru-painterly-depth-animation/references/variants.md +17 -0
- package/skills/animaguru-paper-popup/SKILL.md +29 -0
- package/skills/animaguru-paper-popup/references/recipe.md +22 -0
- package/skills/animaguru-photo-footage-editorial/SKILL.md +29 -0
- package/skills/animaguru-photo-footage-editorial/references/recipe.md +23 -0
- package/skills/animaguru-pixel-art-animation/SKILL.md +36 -0
- package/skills/animaguru-pixel-art-animation/references/variants.md +17 -0
- package/skills/animaguru-portal-zoom/SKILL.md +29 -0
- package/skills/animaguru-portal-zoom/references/recipe.md +21 -0
- package/skills/animaguru-risograph-print/SKILL.md +29 -0
- package/skills/animaguru-risograph-print/references/recipe.md +23 -0
- package/skills/animaguru-sand-drawing/SKILL.md +29 -0
- package/skills/animaguru-sand-drawing/references/recipe.md +21 -0
- package/skills/animaguru-shadow-theatre/SKILL.md +29 -0
- package/skills/animaguru-shadow-theatre/references/recipe.md +23 -0
- package/skills/animaguru-silkscreen-poster/SKILL.md +29 -0
- package/skills/animaguru-silkscreen-poster/references/recipe.md +22 -0
- package/skills/animaguru-stop-motion-objects/SKILL.md +29 -0
- package/skills/animaguru-stop-motion-objects/references/recipe.md +23 -0
- package/skills/animaguru-studio-product-reveal/SKILL.md +29 -0
- package/skills/animaguru-studio-product-reveal/references/recipe.md +23 -0
- package/skills/animaguru-video/SKILL.md +79 -0
- package/skills/animaguru-whiteboard-line-drawing/SKILL.md +34 -0
- package/skills/animaguru-whiteboard-line-drawing/references/variants.md +17 -0
- package/templates/video/AGENTS.md +34 -0
- package/templates/video/CLAUDE.md +19 -0
- package/templates/video/README.md +101 -0
- package/templates/video/VIDEO-STYLE-NOTICES.txt +54 -0
- package/templates/video/film.config.json +10 -0
- package/templates/video/gitignore +11 -0
- package/templates/video/index.html +14 -0
- package/templates/video/package.json +28 -0
- package/templates/video/public/brand/logo-mark.svg +5 -0
- package/templates/video/scripts/build.mjs +12 -0
- package/templates/video/scripts/export-html.mjs +12 -0
- package/templates/video/scripts/export-mp4.mjs +209 -0
- package/templates/video/scripts/html-export-plugin.mjs +35 -0
- package/templates/video/scripts/html-export.mjs +54 -0
- package/templates/video/scripts/install-example.mjs +32 -0
- package/templates/video/scripts/review-analysis.mjs +29 -0
- package/templates/video/scripts/review-audio.mjs +24 -0
- package/templates/video/scripts/review.mjs +37 -0
- package/templates/video/scripts/starter-film.sha256 +1 -0
- package/templates/video/shared/locales/en/export.json +10 -0
- package/templates/video/shared/locales/en/film.json +42 -0
- package/templates/video/shared/locales/en/player.json +31 -0
- package/templates/video/shared/locales/en/style-studies.json +168 -0
- package/templates/video/shared/locales/en/timeline.json +33 -0
- package/templates/video/src/assets.ts +4 -0
- package/templates/video/src/download.ts +27 -0
- package/templates/video/src/exporter.ts +70 -0
- package/templates/video/src/film-resources.ts +29 -0
- package/templates/video/src/film.ts +132 -0
- package/templates/video/src/main.ts +219 -0
- package/templates/video/src/resource-timeline.ts +193 -0
- package/templates/video/src/review.ts +50 -0
- package/templates/video/src/studies/film.ts +26 -0
- package/templates/video/src/studies/media.ts +46 -0
- package/templates/video/src/studies/model.ts +60 -0
- package/templates/video/src/studies/pixi-renderer.ts +121 -0
- package/templates/video/src/studies/scenes.ts +410 -0
- package/templates/video/src/studies/timing.ts +53 -0
- package/templates/video/src/studies/variants.ts +39 -0
- package/templates/video/src/style.css +111 -0
- package/templates/video/src/timeline-model.ts +55 -0
- package/templates/video/style-source-provenance.json +11 -0
- package/templates/video/tsconfig.json +15 -0
- package/templates/video/vite.config.mjs +9 -0
- package/vendor/pixijs-skills/LICENSE +21 -0
- package/vendor/pixijs-skills/provenance.json +79 -0
- package/vendor/pixijs-skills/skills/pixijs/SKILL.md +66 -0
- package/vendor/pixijs-skills/skills/pixijs/references/index.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-accessibility/SKILL.md +224 -0
- package/vendor/pixijs-skills/skills/pixijs-application/SKILL.md +293 -0
- package/vendor/pixijs-skills/skills/pixijs-application/references/application-options.md +314 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/SKILL.md +303 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/background.md +137 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/bundles.md +122 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/caching.md +143 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/compressed-textures.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/fonts.md +205 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/gif.md +171 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/manifests.md +175 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/progress.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/resolution.md +142 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/spritesheet.md +119 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/svg.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-assets/references/video.md +158 -0
- package/vendor/pixijs-skills/skills/pixijs-blend-modes/SKILL.md +215 -0
- package/vendor/pixijs-skills/skills/pixijs-color/SKILL.md +299 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/SKILL.md +132 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/render-loop.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-core-concepts/references/renderers.md +287 -0
- package/vendor/pixijs-skills/skills/pixijs-create/SKILL.md +276 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/SKILL.md +405 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/advanced-gpu.md +244 -0
- package/vendor/pixijs-skills/skills/pixijs-custom-rendering/references/uniform-types.md +94 -0
- package/vendor/pixijs-skills/skills/pixijs-environments/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-events/SKILL.md +387 -0
- package/vendor/pixijs-skills/skills/pixijs-filters/SKILL.md +300 -0
- package/vendor/pixijs-skills/skills/pixijs-html-source/SKILL.md +228 -0
- package/vendor/pixijs-skills/skills/pixijs-math/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-migration-v8/SKILL.md +415 -0
- package/vendor/pixijs-skills/skills/pixijs-performance/SKILL.md +489 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-container/SKILL.md +345 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/SKILL.md +243 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/constructor-options.md +155 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/container-hierarchy.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/layers.md +145 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/masking.md +129 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/render-groups.md +140 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/scene-management.md +169 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-core-concepts/references/transforms.md +198 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-dom-container/SKILL.md +193 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-gif/SKILL.md +233 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-graphics/SKILL.md +576 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/SKILL.md +141 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-perspective.md +189 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-plane.md +159 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-rope.md +176 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh-simple.md +144 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-mesh/references/mesh.md +213 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-particle-container/SKILL.md +323 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/SKILL.md +120 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/animated-sprite.md +262 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/nineslice-sprite.md +202 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/sprite.md +181 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-sprite/references/tiling-sprite.md +216 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/SKILL.md +136 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/bitmap-text.md +232 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/html-text.md +192 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-bitmap-text.md +187 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/split-text.md +168 -0
- package/vendor/pixijs-skills/skills/pixijs-scene-text/references/text.md +311 -0
- package/vendor/pixijs-skills/skills/pixijs-ticker/SKILL.md +292 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pixijs-math
|
|
3
|
+
description: "Use this skill when working with coordinates, vectors, matrices, shapes, hit testing, or layout rectangles in PixiJS v8. Covers Point/ObservablePoint, Matrix (2D affine, decompose (including mirrored/negative-scale matrices), apply, applyInverse), shapes (Rectangle, Circle, Ellipse, Polygon, RoundedRectangle, Triangle), Rectangle layout helpers (pad, fit, enlarge, ceil, scale, getBounds), strokeContains hit tests, Polygon isClockwise/containsPolygon, toGlobal/toLocal, PointData/PointLike/Size types, DEG_TO_RAD, and pixi.js/math-extras vector and intersection helpers. Triggers on: Point, ObservablePoint, Matrix, Rectangle, Circle, Polygon, Triangle, RoundedRectangle, toGlobal, toLocal, hitArea, strokeContains, pad, fit, enlarge, ceil, getBounds, containsRect, intersects, isClockwise, math-extras, lineIntersection, segmentIntersection, DEG_TO_RAD, PointData, decompose, mirror, flip, negative scale, setFromMatrix."
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
PixiJS exposes lightweight math primitives (Point, Matrix, shape classes) used throughout the library for transforms, hit testing, and coordinate conversion. Import `pixi.js/math-extras` to add vector operations (add, dot, magnitude, reflect) and Rectangle intersection/union helpers.
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const parent = new Container();
|
|
13
|
+
parent.position.set(100, 100);
|
|
14
|
+
parent.scale.set(2);
|
|
15
|
+
app.stage.addChild(parent);
|
|
16
|
+
|
|
17
|
+
const child = new Container();
|
|
18
|
+
child.position.set(50, 50);
|
|
19
|
+
parent.addChild(child);
|
|
20
|
+
|
|
21
|
+
const globalPt = child.toGlobal(new Point(0, 0));
|
|
22
|
+
|
|
23
|
+
const m = new Matrix()
|
|
24
|
+
.translate(100, 50)
|
|
25
|
+
.rotate(Math.PI / 4)
|
|
26
|
+
.scale(2, 2);
|
|
27
|
+
const world = m.apply(new Point(10, 20));
|
|
28
|
+
|
|
29
|
+
const hitArea = new Rectangle(0, 0, 200, 100);
|
|
30
|
+
console.log(hitArea.contains(50, 50));
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Related skills:** `pixijs-scene-container` (transform properties), `pixijs-events` (hitArea usage), `pixijs-scene-core-concepts` (culling with Rectangle).
|
|
34
|
+
|
|
35
|
+
## Core Patterns
|
|
36
|
+
|
|
37
|
+
### Point and ObservablePoint
|
|
38
|
+
|
|
39
|
+
Point is a simple {x, y} value type. ObservablePoint fires a callback when x or y changes; it is used internally by Container's position, scale, pivot, origin, and skew.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { Point } from "pixi.js";
|
|
43
|
+
|
|
44
|
+
const p = new Point(10, 20);
|
|
45
|
+
p.set(30, 40); // set both
|
|
46
|
+
p.set(50); // x=50, y=50
|
|
47
|
+
|
|
48
|
+
const clone = p.clone();
|
|
49
|
+
console.log(p.equals(clone)); // true
|
|
50
|
+
|
|
51
|
+
p.copyFrom({ x: 1, y: 2 }); // accepts any PointData
|
|
52
|
+
|
|
53
|
+
// Point.shared: temporary point, reset to (0,0) on each access
|
|
54
|
+
const temp = Point.shared;
|
|
55
|
+
temp.set(100, 200);
|
|
56
|
+
// do not store a reference to Point.shared
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Container properties like `position`, `scale`, `pivot`, `origin`, and `skew` are ObservablePoints. Setting `.x` or `.y` on them triggers transform recalculation automatically.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { Container } from "pixi.js";
|
|
63
|
+
|
|
64
|
+
const obj = new Container();
|
|
65
|
+
obj.position.set(100, 200); // triggers observer -> marks transform dirty
|
|
66
|
+
obj.position.x = 150; // also triggers observer
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Matrix (2D affine transform)
|
|
70
|
+
|
|
71
|
+
Matrix represents a 3x3 affine transform: `| a c tx | b d ty | 0 0 1 |`. It supports translate, scale, rotate, append, prepend, invert, and decompose.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { Matrix, Point } from "pixi.js";
|
|
75
|
+
|
|
76
|
+
// Build a transform
|
|
77
|
+
const m = new Matrix()
|
|
78
|
+
.translate(100, 50)
|
|
79
|
+
.rotate(Math.PI / 4)
|
|
80
|
+
.scale(2, 2);
|
|
81
|
+
|
|
82
|
+
// Transform a point (local -> parent space)
|
|
83
|
+
const local = new Point(10, 20);
|
|
84
|
+
const world = m.apply(local);
|
|
85
|
+
|
|
86
|
+
// Inverse transform (parent -> local space)
|
|
87
|
+
const backToLocal = m.applyInverse(world);
|
|
88
|
+
|
|
89
|
+
// Combine matrices
|
|
90
|
+
const a = new Matrix().translate(50, 0);
|
|
91
|
+
const b = new Matrix().rotate(Math.PI / 2);
|
|
92
|
+
a.append(b); // a = a * b
|
|
93
|
+
|
|
94
|
+
// Decompose into position/scale/rotation/skew
|
|
95
|
+
const transform = {
|
|
96
|
+
position: new Point(),
|
|
97
|
+
scale: new Point(),
|
|
98
|
+
pivot: new Point(),
|
|
99
|
+
skew: new Point(),
|
|
100
|
+
rotation: 0,
|
|
101
|
+
};
|
|
102
|
+
m.decompose(transform);
|
|
103
|
+
console.log(transform.rotation); // ~0.785 (PI/4)
|
|
104
|
+
|
|
105
|
+
// A mirrored matrix (one axis flipped, axes still perpendicular) decomposes into
|
|
106
|
+
// rotation + negative scale.x with zero skew. scale.y is never negative: a y-axis
|
|
107
|
+
// flip comes back as scale.x = -1 plus a half turn. Either way the parts rebuild the matrix.
|
|
108
|
+
const mirrored = new Matrix().rotate(Math.PI / 6).scale(-1, 1);
|
|
109
|
+
mirrored.decompose(transform);
|
|
110
|
+
transform.scale.x; // -1
|
|
111
|
+
transform.skew.x; // 0
|
|
112
|
+
|
|
113
|
+
// Shared temporary matrix (reset on each access)
|
|
114
|
+
const temp = Matrix.shared;
|
|
115
|
+
// IDENTITY is read-only reference
|
|
116
|
+
const isDefault = m.equals(Matrix.IDENTITY);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Coordinate transforms via Container
|
|
120
|
+
|
|
121
|
+
Containers provide `toGlobal`, `toLocal`, and `getGlobalPosition` for coordinate conversion.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { Container, Point } from "pixi.js";
|
|
125
|
+
|
|
126
|
+
const parent = new Container();
|
|
127
|
+
parent.position.set(100, 100);
|
|
128
|
+
parent.scale.set(2);
|
|
129
|
+
|
|
130
|
+
const child = new Container();
|
|
131
|
+
child.position.set(50, 50);
|
|
132
|
+
parent.addChild(child);
|
|
133
|
+
|
|
134
|
+
// Local point in child's space -> global (world) space
|
|
135
|
+
const globalPt = child.toGlobal(new Point(0, 0));
|
|
136
|
+
// globalPt = { x: 200, y: 200 } (100 + 50*2, 100 + 50*2)
|
|
137
|
+
|
|
138
|
+
// Global point -> child's local space
|
|
139
|
+
const localPt = child.toLocal(new Point(200, 200));
|
|
140
|
+
// localPt = { x: 0, y: 0 }
|
|
141
|
+
|
|
142
|
+
// Convert between two containers
|
|
143
|
+
const other = new Container();
|
|
144
|
+
other.position.set(300, 300);
|
|
145
|
+
const ptInOther = child.toLocal(new Point(10, 10), other);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Shapes and hit testing
|
|
149
|
+
|
|
150
|
+
Rectangle, Circle, Ellipse, Polygon, RoundedRectangle, and Triangle all implement `contains(x, y)` for point-in-shape tests, plus `getBounds(out?)` and `strokeContains(x, y, width, alignment?)` (`Triangle` ignores `alignment` and always tests a centered stroke). They can be used as `hitArea` on containers for custom interaction regions.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { Rectangle, Circle, Ellipse, Polygon, Container } from "pixi.js";
|
|
154
|
+
|
|
155
|
+
const rect = new Rectangle(0, 0, 200, 100);
|
|
156
|
+
rect.contains(50, 50); // true
|
|
157
|
+
rect.contains(300, 50); // false
|
|
158
|
+
rect.left; // 0
|
|
159
|
+
rect.right; // 200
|
|
160
|
+
rect.top; // 0
|
|
161
|
+
rect.bottom; // 100
|
|
162
|
+
rect.isEmpty(); // false (Rectangle.EMPTY returns a fresh empty rect)
|
|
163
|
+
|
|
164
|
+
// Native Rectangle-to-Rectangle methods (no math-extras needed)
|
|
165
|
+
const other = new Rectangle(50, 50, 100, 100);
|
|
166
|
+
rect.containsRect(other); // true if `other` is fully inside `rect`
|
|
167
|
+
rect.containsRect(new Rectangle(100, 0, 100, 100)); // true: a flush right edge counts
|
|
168
|
+
rect.containsRect(rect.clone()); // true: identical rects contain each other
|
|
169
|
+
rect.intersects(other); // boolean: do they overlap at all?
|
|
170
|
+
rect.intersects(other, matrix); // overlap after transforming `other`
|
|
171
|
+
|
|
172
|
+
// Stroke hit testing (alignment: 1 = inner, 0.5 = centered, 0 = outer)
|
|
173
|
+
rect.strokeContains(0, 50, 4); // true if (0,50) lies on a 4px centered stroke
|
|
174
|
+
const circle = new Circle(100, 100, 50);
|
|
175
|
+
circle.strokeContains(150, 100, 4, 1); // inner-aligned stroke check
|
|
176
|
+
// A stroke that reaches past the shape's centre covers the whole interior; there is no hole
|
|
177
|
+
new Ellipse(0, 0, 10, 10).strokeContains(0, 0, 40, 1); // true
|
|
178
|
+
|
|
179
|
+
// getBounds works on every shape (returns a Rectangle, accepts an out param)
|
|
180
|
+
const bounds = circle.getBounds();
|
|
181
|
+
const reused = new Rectangle();
|
|
182
|
+
new Polygon([0, 0, 100, 0, 50, 100]).getBounds(reused);
|
|
183
|
+
|
|
184
|
+
// Use as hit area for interaction
|
|
185
|
+
const button = new Container();
|
|
186
|
+
button.hitArea = new Rectangle(0, 0, 200, 50);
|
|
187
|
+
button.eventMode = "static";
|
|
188
|
+
button.on("pointerdown", () => {
|
|
189
|
+
/* clicked */
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Do not confuse native `Rectangle.intersects(other)` (returns `boolean`) with math-extras `intersection(other)` (returns a `Rectangle` describing the overlap area).
|
|
194
|
+
|
|
195
|
+
### Rectangle layout helpers
|
|
196
|
+
|
|
197
|
+
Rectangle ships with mutating helpers used heavily in UI/layout, bounds aggregation, and pixel snapping. All return `this` for chaining.
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import { Rectangle } from "pixi.js";
|
|
201
|
+
|
|
202
|
+
const r = new Rectangle(10, 10, 100, 50);
|
|
203
|
+
|
|
204
|
+
r.pad(5); // grow on all sides: x=5, y=5, w=110, h=60
|
|
205
|
+
r.pad(10, 4); // separate horizontal/vertical padding
|
|
206
|
+
r.scale(2); // multiply x, y, width, height by 2
|
|
207
|
+
|
|
208
|
+
// fit shrinks `this` to lie inside another rect (clipping)
|
|
209
|
+
const viewport = new Rectangle(0, 0, 200, 200);
|
|
210
|
+
new Rectangle(150, 150, 200, 200).fit(viewport); // -> 150, 150, 50, 50
|
|
211
|
+
|
|
212
|
+
// enlarge expands `this` to include another rect (bounds aggregation)
|
|
213
|
+
const total = new Rectangle();
|
|
214
|
+
items.forEach((item) =>
|
|
215
|
+
total.enlarge(new Rectangle().copyFromBounds(item.getBounds())),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// ceil snaps to a pixel grid (resolution: 1 = whole pixels, 2 = half pixels)
|
|
219
|
+
new Rectangle(10.2, 10.6, 100.8, 100.4).ceil();
|
|
220
|
+
|
|
221
|
+
// copy a Container/Mesh bounds object straight into a Rectangle
|
|
222
|
+
new Rectangle().copyFromBounds(container.getBounds());
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Polygon
|
|
226
|
+
|
|
227
|
+
Polygon accepts four constructor formats: a flat number array, an array of point-like objects, or either passed as spread arguments.
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
import { Polygon, Point } from "pixi.js";
|
|
231
|
+
|
|
232
|
+
new Polygon([0, 0, 100, 0, 50, 100]); // flat numbers
|
|
233
|
+
new Polygon([new Point(0, 0), new Point(100, 0), new Point(50, 100)]); // PointData[]
|
|
234
|
+
new Polygon(0, 0, 100, 0, 50, 100); // spread numbers
|
|
235
|
+
new Polygon(new Point(0, 0), new Point(100, 0), new Point(50, 100)); // spread points
|
|
236
|
+
|
|
237
|
+
const poly = new Polygon([0, 0, 100, 0, 100, 100, 0, 100]);
|
|
238
|
+
poly.points; // [0, 0, 100, 0, 100, 100, 0, 100] (mutable flat array)
|
|
239
|
+
poly.closePath; // true by default; false produces an open path
|
|
240
|
+
poly.startX; // 0 - first vertex
|
|
241
|
+
poly.lastX; // 0 - last vertex (lastY for y)
|
|
242
|
+
poly.isClockwise(); // shoelace winding test (useful for SVG hole detection)
|
|
243
|
+
|
|
244
|
+
// Polygon-in-polygon containment for hole detection
|
|
245
|
+
const outer = new Polygon([0, 0, 100, 0, 100, 100, 0, 100]);
|
|
246
|
+
const hole = new Polygon([25, 25, 75, 25, 75, 75, 25, 75]);
|
|
247
|
+
outer.containsPolygon(hole); // true
|
|
248
|
+
|
|
249
|
+
// Stroke hit test follows the drawn stroke: alignment 1 = inside, 0.5 = centered,
|
|
250
|
+
// 0 = outside, independent of winding order
|
|
251
|
+
outer.strokeContains(-5, 50, 20); // true (centered stroke extends 10px outward)
|
|
252
|
+
outer.strokeContains(-5, 50, 20, 1); // false (inner stroke stays inside)
|
|
253
|
+
outer.strokeContains(5, 50, 20, 0); // false (outer stroke stays outside)
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Constants
|
|
257
|
+
|
|
258
|
+
```ts
|
|
259
|
+
import { DEG_TO_RAD, RAD_TO_DEG, PI_2 } from "pixi.js";
|
|
260
|
+
|
|
261
|
+
const angle = 45 * DEG_TO_RAD; // 0.785...
|
|
262
|
+
const degrees = angle * RAD_TO_DEG; // 45
|
|
263
|
+
const fullCircle = PI_2; // Math.PI * 2
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Types
|
|
267
|
+
|
|
268
|
+
- `PointData` - minimal `{x, y}` interface accepted by most APIs. Use it when typing parameters that only need to read coordinates.
|
|
269
|
+
- `PointLike` - extends `PointData` with `set()`, `copyFrom()`, `copyTo()`, `equals()`. Implemented by both `Point` and `ObservablePoint`.
|
|
270
|
+
- `Size` - `{ width, height }` interface used by renderer/canvas APIs.
|
|
271
|
+
- `SHAPE_PRIMITIVE` - string literal union: `'rectangle' | 'circle' | 'ellipse' | 'polygon' | 'roundedRectangle' | 'triangle'`. Every shape exposes `type` so you can branch without `instanceof`.
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
import type { PointData } from "pixi.js";
|
|
275
|
+
|
|
276
|
+
function distance(a: PointData, b: PointData): number {
|
|
277
|
+
const dx = a.x - b.x;
|
|
278
|
+
const dy = a.y - b.y;
|
|
279
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### math-extras (side-effect import)
|
|
284
|
+
|
|
285
|
+
`import 'pixi.js/math-extras'` adds methods to Point, ObservablePoint, and Rectangle via prototype extension. Not included in the default bundle.
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
import "pixi.js/math-extras";
|
|
289
|
+
import { Point } from "pixi.js";
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### Point / ObservablePoint vector methods
|
|
293
|
+
|
|
294
|
+
All methods accept an optional `out` parameter to avoid allocations. Without `out`, a new Point is returned.
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
const a = new Point(3, 4);
|
|
298
|
+
const b = new Point(1, 2);
|
|
299
|
+
|
|
300
|
+
// Arithmetic
|
|
301
|
+
const sum = a.add(b); // Point(4, 6)
|
|
302
|
+
const diff = a.subtract(b); // Point(2, 2)
|
|
303
|
+
const prod = a.multiply(b); // Point(3, 8) - component-wise
|
|
304
|
+
const scaled = a.multiplyScalar(2); // Point(6, 8)
|
|
305
|
+
|
|
306
|
+
// Dot and cross product
|
|
307
|
+
const dot = a.dot(b); // 11
|
|
308
|
+
const cross = a.cross(b); // 2 (z-component of 3D cross)
|
|
309
|
+
|
|
310
|
+
// Length
|
|
311
|
+
const len = a.magnitude(); // 5
|
|
312
|
+
const lenSq = a.magnitudeSquared(); // 25 (faster for comparisons)
|
|
313
|
+
|
|
314
|
+
// Normalize to unit vector
|
|
315
|
+
const unit = a.normalize(); // Point(0.6, 0.8)
|
|
316
|
+
|
|
317
|
+
// Projection and reflection
|
|
318
|
+
const proj = a.project(b); // project a onto b
|
|
319
|
+
const refl = a.reflect(new Point(0, 1)); // reflect across normal
|
|
320
|
+
|
|
321
|
+
// Rotation
|
|
322
|
+
const rotated = a.rotate(Math.PI / 2); // rotate 90 degrees
|
|
323
|
+
|
|
324
|
+
// Reuse existing point to avoid allocation
|
|
325
|
+
const out = new Point();
|
|
326
|
+
a.add(b, out); // result written to out
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
#### Rectangle extended methods
|
|
330
|
+
|
|
331
|
+
`containsRect` and `intersects` are native `Rectangle` methods (see above). math-extras adds `equals`, `intersection` (returns the overlap rect), and `union`:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
import "pixi.js/math-extras";
|
|
335
|
+
import { Rectangle } from "pixi.js";
|
|
336
|
+
|
|
337
|
+
const r1 = new Rectangle(0, 0, 100, 100);
|
|
338
|
+
const r2 = new Rectangle(50, 50, 100, 100);
|
|
339
|
+
|
|
340
|
+
r1.equals(r2); // false
|
|
341
|
+
|
|
342
|
+
const overlap = r1.intersection(r2); // Rectangle(50, 50, 50, 50)
|
|
343
|
+
const envelope = r1.union(r2); // Rectangle(0, 0, 150, 150)
|
|
344
|
+
|
|
345
|
+
// Optional out parameter
|
|
346
|
+
const out = new Rectangle();
|
|
347
|
+
r1.intersection(r2, out);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
#### Geometry utility functions
|
|
351
|
+
|
|
352
|
+
These functions are exported from `pixi.js/math-extras`, not the main `pixi.js` entry.
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import {
|
|
356
|
+
floatEqual,
|
|
357
|
+
lineIntersection,
|
|
358
|
+
segmentIntersection,
|
|
359
|
+
} from "pixi.js/math-extras";
|
|
360
|
+
import { Point } from "pixi.js";
|
|
361
|
+
|
|
362
|
+
// Epsilon-based float comparison (default epsilon: Number.EPSILON)
|
|
363
|
+
floatEqual(0.1 + 0.2, 0.3, 1e-10); // true with reasonable epsilon
|
|
364
|
+
floatEqual(1.0, 1.001, 0.01); // true (custom epsilon)
|
|
365
|
+
|
|
366
|
+
// Unbounded line intersection (returns {x: NaN, y: NaN} if parallel)
|
|
367
|
+
const hit = lineIntersection(
|
|
368
|
+
new Point(0, 0),
|
|
369
|
+
new Point(10, 10), // line A
|
|
370
|
+
new Point(10, 0),
|
|
371
|
+
new Point(0, 10), // line B
|
|
372
|
+
); // Point(5, 5)
|
|
373
|
+
if (isNaN(hit.x)) {
|
|
374
|
+
/* lines are parallel */
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Bounded segment intersection (returns {x: NaN, y: NaN} if segments don't cross)
|
|
378
|
+
const segHit = segmentIntersection(
|
|
379
|
+
new Point(0, 0),
|
|
380
|
+
new Point(10, 10),
|
|
381
|
+
new Point(10, 0),
|
|
382
|
+
new Point(0, 10),
|
|
383
|
+
); // Point(5, 5)
|
|
384
|
+
if (isNaN(segHit.x)) {
|
|
385
|
+
/* segments don't intersect */
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Common Mistakes
|
|
390
|
+
|
|
391
|
+
### HIGH: Importing from @pixi/math
|
|
392
|
+
|
|
393
|
+
Wrong:
|
|
394
|
+
|
|
395
|
+
```ts
|
|
396
|
+
import { Point } from "@pixi/math";
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Correct:
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
import { Point } from "pixi.js";
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
v8 uses a single `pixi.js` package. All sub-packages like `@pixi/math`, `@pixi/core`, etc. were removed.
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
### MEDIUM: Mutating ObservablePoint without triggering observer
|
|
409
|
+
|
|
410
|
+
Wrong:
|
|
411
|
+
|
|
412
|
+
```ts
|
|
413
|
+
// Replacing the reference loses observation
|
|
414
|
+
let pos = container.position;
|
|
415
|
+
pos = new Point(100, 200); // container.position unchanged
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Correct:
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
// Mutate in place to trigger the observer
|
|
422
|
+
container.position.set(100, 200);
|
|
423
|
+
// or
|
|
424
|
+
container.position.x = 100;
|
|
425
|
+
container.position.y = 200;
|
|
426
|
+
// or copy from another point
|
|
427
|
+
container.position.copyFrom(new Point(100, 200));
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Container's position, scale, pivot, origin, and skew are ObservablePoints. Setting `.x` or `.y` on them triggers the container's transform update. Reassigning the variable reference does not modify the container. Always mutate the existing ObservablePoint via `.set()`, `.copyFrom()`, or direct property assignment on the original object.
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
### MEDIUM: Not importing math-extras for extended methods
|
|
434
|
+
|
|
435
|
+
Wrong:
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
import { Point } from "pixi.js";
|
|
439
|
+
const p = new Point(1, 2);
|
|
440
|
+
p.add(new Point(3, 4)); // TypeError: p.add is not a function
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
Correct:
|
|
444
|
+
|
|
445
|
+
```ts
|
|
446
|
+
import "pixi.js/math-extras";
|
|
447
|
+
import { Point } from "pixi.js";
|
|
448
|
+
const p = new Point(1, 2);
|
|
449
|
+
const sum = p.add(new Point(3, 4)); // works
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Extended math utilities (add, subtract, multiply, magnitude, normalize, dot, cross, etc. on Point; intersection methods on shapes) require an explicit `import 'pixi.js/math-extras'`. These are not included in the default bundle.
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
### MEDIUM: Storing references to shared/temporary objects
|
|
456
|
+
|
|
457
|
+
Wrong:
|
|
458
|
+
|
|
459
|
+
```ts
|
|
460
|
+
const myPoint = Point.shared;
|
|
461
|
+
myPoint.set(100, 200);
|
|
462
|
+
// ... later ...
|
|
463
|
+
console.log(myPoint.x); // 0 (reset on next access)
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
Correct:
|
|
467
|
+
|
|
468
|
+
```ts
|
|
469
|
+
const myPoint = new Point();
|
|
470
|
+
myPoint.copyFrom(Point.shared.set(100, 200));
|
|
471
|
+
// or just
|
|
472
|
+
const myPoint = new Point(100, 200);
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
`Point.shared` and `Matrix.shared` are reset to zero/identity every time they are accessed. They exist for one-off calculations within a single expression. Never store a reference to them.
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
## API Reference
|
|
479
|
+
|
|
480
|
+
- [Point](https://pixijs.download/release/docs/maths.Point.html.md)
|
|
481
|
+
- [ObservablePoint](https://pixijs.download/release/docs/maths.ObservablePoint.html.md)
|
|
482
|
+
- [Matrix](https://pixijs.download/release/docs/maths.Matrix.html.md)
|
|
483
|
+
- [Rectangle](https://pixijs.download/release/docs/maths.Rectangle.html.md)
|
|
484
|
+
- [Circle](https://pixijs.download/release/docs/maths.Circle.html.md)
|
|
485
|
+
- [Ellipse](https://pixijs.download/release/docs/maths.Ellipse.html.md)
|
|
486
|
+
- [Polygon](https://pixijs.download/release/docs/maths.Polygon.html.md)
|
|
487
|
+
- [RoundedRectangle](https://pixijs.download/release/docs/maths.RoundedRectangle.html.md)
|
|
488
|
+
- [Triangle](https://pixijs.download/release/docs/maths.Triangle.html.md)
|
|
489
|
+
- [DEG_TO_RAD](https://pixijs.download/release/docs/maths.DEG_TO_RAD.html.md)
|