@next2d/geom 2.13.1 → 3.0.1

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.
Files changed (2) hide show
  1. package/README.md +272 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,279 @@
1
- @next2d/geom
2
- =============
1
+ # @next2d/geom
3
2
 
4
- ## Installation
3
+ **Important**: `@next2d/geom` prohibits importing other packages. This package is a foundational module that must remain independent to avoid circular dependencies.
5
4
 
6
- ```
5
+ **重要**: `@next2d/geom` は他の packages の import を禁止しています。このパッケージは基盤モジュールであり、循環依存を避けるために独立を維持する必要があります。
6
+
7
+ ## Overview / 概要
8
+
9
+ **English:**
10
+ The `@next2d/geom` package provides geometric primitives and utilities for 2D transformations and color manipulation. This package implements fundamental geometric classes used in graphics programming, including matrices for transformations, points for coordinates, rectangles for bounding boxes, and color transformations for visual effects.
11
+
12
+ **Japanese:**
13
+ `@next2d/geom` パッケージは、2D変換とカラー操作のための幾何プリミティブとユーティリティを提供します。このパッケージは、グラフィックスプログラミングで使用される基本的な幾何クラスを実装しており、変換用のマトリックス、座標用のポイント、境界ボックス用の矩形、視覚効果用のカラー変換が含まれます。
14
+
15
+ ## Installation / インストール
16
+
17
+ ```bash
7
18
  npm install @next2d/geom
8
19
  ```
9
20
 
21
+ ## Directory Structure / ディレクトリ構造
22
+
23
+ ```
24
+ src/
25
+ ├── Matrix.ts # 2D transformation matrix class
26
+ │ └── service/ # Matrix operation services
27
+ │ ├── MatirxConcatService.ts # Matrix concatenation
28
+ │ ├── MatrixCloneService.ts # Matrix cloning
29
+ │ ├── MatrixCopyFromService.ts # Copy matrix data
30
+ │ ├── MatrixCreateBoxService.ts # Create transformation box
31
+ │ ├── MatrixCreateGradientBoxService.ts # Create gradient box
32
+ │ ├── MatrixDeltaTransformPointService.ts # Delta transformation
33
+ │ ├── MatrixIdentityService.ts # Identity matrix
34
+ │ ├── MatrixInvertService.ts # Matrix inversion
35
+ │ ├── MatrixRotateService.ts # Rotation transformation
36
+ │ ├── MatrixScaleService.ts # Scaling transformation
37
+ │ ├── MatrixSetToService.ts # Set matrix values
38
+ │ ├── MatrixTransformPointService.ts # Point transformation
39
+ │ └── MatrixTranslateService.ts # Translation transformation
40
+
41
+ ├── Point.ts # 2D point class
42
+ │ └── service/ # Point operation services
43
+ │ ├── PointAddService.ts # Add points
44
+ │ ├── PointCloneService.ts # Clone point
45
+ │ ├── PointCopyFromService.ts # Copy point data
46
+ │ ├── PointDistanceService.ts # Calculate distance
47
+ │ ├── PointEqualsService.ts # Point equality check
48
+ │ ├── PointInterpolateService.ts # Point interpolation
49
+ │ ├── PointNormalizeService.ts # Normalize point
50
+ │ ├── PointOffsetService.ts # Offset point
51
+ │ ├── PointPolarService.ts # Polar to Cartesian conversion
52
+ │ ├── PointSetToService.ts # Set point values
53
+ │ └── PointSubtractService.ts # Subtract points
54
+
55
+ ├── Rectangle.ts # Rectangle class for bounding boxes
56
+ │ └── service/ # Rectangle operation services
57
+ │ ├── RectangleCloneService.ts # Clone rectangle
58
+ │ ├── RectangleContainsService.ts # Contains coordinate check
59
+ │ ├── RectangleContainsPointService.ts # Contains point check
60
+ │ ├── RectangleContainsRectService.ts # Contains rectangle check
61
+ │ ├── RectangleCopyFromService.ts # Copy rectangle data
62
+ │ ├── RectangleEqualsService.ts # Rectangle equality check
63
+ │ ├── RectangleInflateService.ts # Inflate rectangle
64
+ │ ├── RectangleInflatePointService.ts # Inflate by point
65
+ │ ├── RectangleIntersectionService.ts # Calculate intersection
66
+ │ ├── RectangleIntersectsService.ts # Intersection check
67
+ │ ├── RectangleIsEmptyService.ts # Empty check
68
+ │ ├── RectangleOffsetService.ts # Offset rectangle
69
+ │ ├── RectangleOffsetPointService.ts # Offset by point
70
+ │ ├── RectangleSetEmptyService.ts # Set to empty
71
+ │ ├── RectangleSetToService.ts # Set rectangle values
72
+ │ └── RectangleUnionService.ts # Union of rectangles
73
+
74
+ ├── ColorTransform.ts # Color transformation class
75
+ │ └── service/ # ColorTransform operation services
76
+ │ └── ColorTransformConcatService.ts # Concatenate color transforms
77
+
78
+ ├── GeomUtil.ts # Utility functions
79
+ └── index.ts # Package exports
80
+ ```
81
+
82
+ ## Classes / クラス
83
+
84
+ ### Matrix
85
+
86
+ **English:**
87
+ The `Matrix` class represents a 3x2 affine transformation matrix used for 2D transformations. It determines how to map points from one coordinate space to another and supports operations like translation, rotation, scaling, and skewing.
88
+
89
+ **Japanese:**
90
+ `Matrix` クラスは、2D変換に使用される3x2のアフィン変換行列を表します。ある座標空間から別の座標空間へのポイントのマッピング方法を決定し、平行移動、回転、拡大縮小、傾斜などの操作をサポートします。
91
+
92
+ **Key Properties / 主要プロパティ:**
93
+ - `a`, `b`, `c`, `d` - Transformation matrix components / 変換行列の成分
94
+ - `tx`, `ty` - Translation values / 平行移動の値
95
+
96
+ **Common Operations / 一般的な操作:**
97
+ - `clone()` - Create a copy of the matrix / 行列のコピーを作成
98
+ - `concat(matrix)` - Combine with another matrix / 別の行列と結合
99
+ - `rotate(angle)` - Apply rotation / 回転を適用
100
+ - `scale(sx, sy)` - Apply scaling / 拡大縮小を適用
101
+ - `translate(dx, dy)` - Apply translation / 平行移動を適用
102
+ - `transformPoint(point)` - Transform a point / ポイントを変換
103
+ - `invert()` - Invert the matrix / 行列を反転
104
+ - `identity()` - Reset to identity matrix / 単位行列にリセット
105
+
106
+ ### Point
107
+
108
+ **English:**
109
+ The `Point` class represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
110
+
111
+ **Japanese:**
112
+ `Point` クラスは2次元座標系の位置を表し、xは水平軸、yは垂直軸を表します。
113
+
114
+ **Key Properties / 主要プロパティ:**
115
+ - `x` - Horizontal coordinate / 水平座標
116
+ - `y` - Vertical coordinate / 垂直座標
117
+ - `length` - Distance from origin (0,0) / 原点(0,0)からの距離
118
+
119
+ **Common Operations / 一般的な操作:**
120
+ - `clone()` - Create a copy of the point / ポイントのコピーを作成
121
+ - `add(point)` - Add coordinates / 座標を加算
122
+ - `subtract(point)` - Subtract coordinates / 座標を減算
123
+ - `offset(dx, dy)` - Offset by specified amounts / 指定量でオフセット
124
+ - `normalize(thickness)` - Scale to set length / 指定長さにスケール
125
+ - `equals(point)` - Check equality / 等価性をチェック
126
+ - `Point.distance(p1, p2)` - Calculate distance between points / 2点間の距離を計算
127
+ - `Point.interpolate(p1, p2, f)` - Interpolate between points / 2点間を補間
128
+ - `Point.polar(length, angle)` - Convert polar to Cartesian / 極座標を直交座標に変換
129
+
130
+ ### Rectangle
131
+
132
+ **English:**
133
+ The `Rectangle` class represents an area defined by its position (top-left corner point) and dimensions (width and height). It is commonly used for bounding boxes and collision detection.
134
+
135
+ **Japanese:**
136
+ `Rectangle` クラスは、位置(左上隅のポイント)と寸法(幅と高さ)によって定義される領域を表します。バウンディングボックスや衝突検出によく使用されます。
137
+
138
+ **Key Properties / 主要プロパティ:**
139
+ - `x`, `y` - Position of top-left corner / 左上隅の位置
140
+ - `width`, `height` - Dimensions / 寸法
141
+ - `left`, `right`, `top`, `bottom` - Edge coordinates / 辺の座標
142
+ - `topLeft`, `bottomRight` - Corner points / 角のポイント
143
+ - `size` - Dimensions as Point / Point型の寸法
144
+
145
+ **Common Operations / 一般的な操作:**
146
+ - `clone()` - Create a copy / コピーを作成
147
+ - `contains(x, y)` - Check if coordinates are inside / 座標が内部にあるか確認
148
+ - `containsPoint(point)` - Check if point is inside / ポイントが内部にあるか確認
149
+ - `containsRect(rect)` - Check if rectangle is inside / 矩形が内部にあるか確認
150
+ - `intersects(rect)` - Check for intersection / 交差をチェック
151
+ - `intersection(rect)` - Get intersection area / 交差領域を取得
152
+ - `union(rect)` - Get union area / 結合領域を取得
153
+ - `inflate(dx, dy)` - Increase size / サイズを増加
154
+ - `offset(dx, dy)` - Move position / 位置を移動
155
+ - `isEmpty()` - Check if empty / 空かどうか確認
156
+ - `setEmpty()` - Set to empty / 空に設定
157
+
158
+ ### ColorTransform
159
+
160
+ **English:**
161
+ The `ColorTransform` class allows you to adjust color values in display objects. Color transformation can be applied to all four channels: red, green, blue, and alpha transparency. Each channel uses the formula:
162
+ ```
163
+ new_value = (old_value * multiplier) + offset
164
+ ```
165
+
166
+ **Japanese:**
167
+ `ColorTransform` クラスを使用すると、表示オブジェクトのカラー値を調整できます。カラー変換は、赤、緑、青、アルファ透明度の4つのチャンネルすべてに適用できます。各チャンネルは次の式を使用します:
168
+ ```
169
+ 新しい値 = (古い値 * 乗数) + オフセット
170
+ ```
171
+
172
+ **Key Properties / 主要プロパティ:**
173
+ - `redMultiplier`, `greenMultiplier`, `blueMultiplier`, `alphaMultiplier` - Channel multipliers (0-1) / チャンネル乗数(0-1)
174
+ - `redOffset`, `greenOffset`, `blueOffset`, `alphaOffset` - Channel offsets (-255 to 255) / チャンネルオフセット(-255~255)
175
+
176
+ **Common Operations / 一般的な操作:**
177
+ - `clone()` - Create a copy / コピーを作成
178
+ - `concat(colorTransform)` - Combine color transformations / カラー変換を結合
179
+
180
+ ### GeomUtil
181
+
182
+ **English:**
183
+ The `GeomUtil` module provides utility functions for geometry operations, including object pooling for Float32Array instances to optimize memory usage and performance.
184
+
185
+ **Japanese:**
186
+ `GeomUtil` モジュールは、メモリ使用量とパフォーマンスを最適化するためのFloat32Arrayインスタンスのオブジェクトプーリングを含む、幾何演算用のユーティリティ関数を提供します。
187
+
188
+ **Key Functions / 主要な関数:**
189
+ - `$getFloat32Array6()` - Get pooled 6-element array for Matrix / Matrix用の6要素配列をプールから取得
190
+ - `$poolFloat32Array6()` - Return array to pool / 配列をプールに返却
191
+ - `$getFloat32Array8()` - Get pooled 8-element array for ColorTransform / ColorTransform用の8要素配列をプールから取得
192
+ - `$poolFloat32Array8()` - Return array to pool / 配列をプールに返却
193
+ - `$clamp()` - Clamp value between min and max / 値を最小値と最大値の間に制限
194
+
195
+ ## Matrix Transformation Pipeline / 行列変換パイプライン
196
+
197
+ ```mermaid
198
+ graph TD
199
+ A[Original Coordinates<br/>元の座標] --> B{Transformation Type<br/>変換タイプ}
200
+
201
+ B -->|Scale<br/>拡大縮小| C[Matrix.scale sx, sy]
202
+ B -->|Rotate<br/>回転| D[Matrix.rotate angle]
203
+ B -->|Translate<br/>平行移動| E[Matrix.translate dx, dy]
204
+ B -->|Custom<br/>カスタム| F[Matrix.setTo a,b,c,d,tx,ty]
205
+
206
+ C --> G{Combine Transforms?<br/>変換を結合?}
207
+ D --> G
208
+ E --> G
209
+ F --> G
210
+
211
+ G -->|Yes<br/>はい| H[Matrix.concat otherMatrix]
212
+ G -->|No<br/>いいえ| I[Apply Transform<br/>変換を適用]
213
+
214
+ H --> I
215
+
216
+ I --> J{Transform Type<br/>変換タイプ}
217
+
218
+ J -->|Full Transform<br/>完全変換| K[Matrix.transformPoint point]
219
+ J -->|Delta Only<br/>差分のみ| L[Matrix.deltaTransformPoint point]
220
+
221
+ K --> M[Transformed Coordinates<br/>変換後の座標]
222
+ L --> M
223
+
224
+ I --> N{Need Inverse?<br/>逆変換が必要?}
225
+ N -->|Yes<br/>はい| O[Matrix.invert]
226
+ N -->|No<br/>いいえ| P[Continue<br/>続行]
227
+
228
+ O --> Q[Reverse Transform<br/>逆変換]
229
+ P --> R[End<br/>終了]
230
+ Q --> R
231
+
232
+ style A fill:#e1f5ff
233
+ style M fill:#e1ffe1
234
+ style B fill:#fff5e1
235
+ style G fill:#fff5e1
236
+ style J fill:#fff5e1
237
+ style N fill:#fff5e1
238
+ ```
239
+
240
+ ## Usage Example / 使用例
241
+
242
+ ```typescript
243
+ import { Matrix, Point, Rectangle, ColorTransform } from '@next2d/geom';
244
+
245
+ // Matrix transformation
246
+ const matrix = new Matrix();
247
+ matrix.translate(100, 100);
248
+ matrix.rotate(Math.PI / 4); // 45 degrees
249
+ matrix.scale(2, 2);
250
+
251
+ const point = new Point(50, 50);
252
+ const transformed = matrix.transformPoint(point);
253
+
254
+ // Rectangle operations
255
+ const rect1 = new Rectangle(0, 0, 100, 100);
256
+ const rect2 = new Rectangle(50, 50, 100, 100);
257
+
258
+ if (rect1.intersects(rect2)) {
259
+ const intersection = rect1.intersection(rect2);
260
+ console.log('Intersection:', intersection);
261
+ }
262
+
263
+ // Color transformation
264
+ const colorTransform = new ColorTransform();
265
+ colorTransform.redMultiplier = 0.5;
266
+ colorTransform.greenOffset = 128;
267
+ ```
268
+
269
+ ## Performance Optimization / パフォーマンス最適化
270
+
271
+ **English:**
272
+ This package uses object pooling for Float32Array instances to minimize memory allocations and improve performance. The `GeomUtil` module provides pooling functions that reuse array instances, reducing garbage collection overhead in performance-critical applications.
273
+
274
+ **Japanese:**
275
+ このパッケージは、Float32Arrayインスタンスにオブジェクトプーリングを使用して、メモリ割り当てを最小限に抑え、パフォーマンスを向上させます。`GeomUtil` モジュールは、配列インスタンスを再利用するプーリング関数を提供し、パフォーマンスクリティカルなアプリケーションでのガベージコレクションのオーバーヘッドを削減します。
276
+
10
277
  ## License
278
+
11
279
  This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/geom",
3
- "version": "2.13.1",
3
+ "version": "3.0.1",
4
4
  "description": "Next2D Geom Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",