@retikz/core 0.3.0-alpha.3 → 0.3.0-alpha.4
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 +41 -41
- package/dist/es/compile/anchor-cache.d.ts +5 -3
- package/dist/es/compile/anchor-cache.d.ts.map +1 -1
- package/dist/es/compile/anchor-cache.js +14 -10
- package/dist/es/compile/boundary.d.ts +19 -0
- package/dist/es/compile/boundary.d.ts.map +1 -0
- package/dist/es/compile/boundary.js +64 -0
- package/dist/es/compile/compile.d.ts.map +1 -1
- package/dist/es/compile/compile.js +14 -2
- package/dist/es/compile/node.d.ts +24 -8
- package/dist/es/compile/node.d.ts.map +1 -1
- package/dist/es/compile/node.js +100 -16
- package/dist/es/compile/path/anchor.d.ts.map +1 -1
- package/dist/es/compile/path/anchor.js +7 -6
- package/dist/es/compile/path/index.d.ts.map +1 -1
- package/dist/es/compile/path/index.js +5 -3
- package/dist/es/compile/path/relative.js +1 -1
- package/dist/es/compile/scope.d.ts.map +1 -1
- package/dist/es/compile/scope.js +2 -1
- package/dist/es/geometry/arc.d.ts +14 -0
- package/dist/es/geometry/arc.d.ts.map +1 -1
- package/dist/es/geometry/arc.js +65 -9
- package/dist/es/geometry/index.d.ts +1 -0
- package/dist/es/geometry/index.d.ts.map +1 -1
- package/dist/es/geometry/rect.d.ts +2 -2
- package/dist/es/geometry/rect.d.ts.map +1 -1
- package/dist/es/geometry/rect.js +3 -3
- package/dist/es/geometry/roundedContour.d.ts +88 -0
- package/dist/es/geometry/roundedContour.d.ts.map +1 -0
- package/dist/es/geometry/roundedContour.js +417 -0
- package/dist/es/index.d.ts +6 -5
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +9 -6
- package/dist/es/ir/boundary.d.ts +25 -0
- package/dist/es/ir/boundary.d.ts.map +1 -0
- package/dist/es/ir/boundary.js +14 -0
- package/dist/es/ir/index.d.ts +2 -0
- package/dist/es/ir/index.d.ts.map +1 -1
- package/dist/es/ir/node.d.ts +43 -7
- package/dist/es/ir/node.d.ts.map +1 -1
- package/dist/es/ir/node.js +8 -3
- package/dist/es/ir/path/arrow.d.ts +12 -12
- package/dist/es/ir/path/path.d.ts +490 -147
- package/dist/es/ir/path/path.d.ts.map +1 -1
- package/dist/es/ir/path/path.js +2 -0
- package/dist/es/ir/path/step.d.ts +674 -154
- package/dist/es/ir/path/step.d.ts.map +1 -1
- package/dist/es/ir/path/step.js +2 -2
- package/dist/es/ir/path/target.d.ts +43 -8
- package/dist/es/ir/path/target.d.ts.map +1 -1
- package/dist/es/ir/path/target.js +4 -5
- package/dist/es/ir/scope.d.ts +843 -234
- package/dist/es/ir/scope.d.ts.map +1 -1
- package/dist/es/ir/scope.js +6 -2
- package/dist/es/ir/shape.d.ts +14 -0
- package/dist/es/ir/shape.d.ts.map +1 -0
- package/dist/es/ir/shape.js +9 -0
- package/dist/es/parsers/parseNodeTarget.d.ts.map +1 -1
- package/dist/es/parsers/parseNodeTarget.js +4 -2
- package/dist/es/primitive/ellipse.d.ts +3 -0
- package/dist/es/primitive/ellipse.d.ts.map +1 -1
- package/dist/es/primitive/group.d.ts +3 -0
- package/dist/es/primitive/group.d.ts.map +1 -1
- package/dist/es/primitive/path.d.ts +3 -0
- package/dist/es/primitive/path.d.ts.map +1 -1
- package/dist/es/primitive/rect.d.ts +3 -0
- package/dist/es/primitive/rect.d.ts.map +1 -1
- package/dist/es/primitive/text.d.ts +3 -0
- package/dist/es/primitive/text.d.ts.map +1 -1
- package/dist/es/shapes/_contour.d.ts +19 -0
- package/dist/es/shapes/_contour.d.ts.map +1 -0
- package/dist/es/shapes/_contour.js +60 -0
- package/dist/es/shapes/_shared.d.ts +54 -0
- package/dist/es/shapes/_shared.d.ts.map +1 -1
- package/dist/es/shapes/_shared.js +68 -1
- package/dist/es/shapes/arc.d.ts +8 -0
- package/dist/es/shapes/arc.d.ts.map +1 -0
- package/dist/es/shapes/arc.js +104 -0
- package/dist/es/shapes/define.d.ts +13 -0
- package/dist/es/shapes/define.d.ts.map +1 -0
- package/dist/es/shapes/define.js +13 -0
- package/dist/es/shapes/ellipse.d.ts +5 -4
- package/dist/es/shapes/ellipse.d.ts.map +1 -1
- package/dist/es/shapes/ellipse.js +15 -7
- package/dist/es/shapes/index.d.ts +9 -6
- package/dist/es/shapes/index.d.ts.map +1 -1
- package/dist/es/shapes/index.js +10 -5
- package/dist/es/shapes/polygon.d.ts +13 -0
- package/dist/es/shapes/polygon.d.ts.map +1 -0
- package/dist/es/shapes/polygon.js +104 -0
- package/dist/es/shapes/rectangle.d.ts +7 -5
- package/dist/es/shapes/rectangle.d.ts.map +1 -1
- package/dist/es/shapes/rectangle.js +37 -8
- package/dist/es/shapes/sector.d.ts +9 -0
- package/dist/es/shapes/sector.d.ts.map +1 -0
- package/dist/es/shapes/sector.js +143 -0
- package/dist/es/shapes/star.d.ts +15 -0
- package/dist/es/shapes/star.d.ts.map +1 -0
- package/dist/es/shapes/star.js +113 -0
- package/dist/es/shapes/types.d.ts +47 -14
- package/dist/es/shapes/types.d.ts.map +1 -1
- package/dist/lib/compile/anchor-cache.cjs +14 -10
- package/dist/lib/compile/anchor-cache.d.ts +5 -3
- package/dist/lib/compile/anchor-cache.d.ts.map +1 -1
- package/dist/lib/compile/boundary.cjs +65 -0
- package/dist/lib/compile/boundary.d.ts +19 -0
- package/dist/lib/compile/boundary.d.ts.map +1 -0
- package/dist/lib/compile/compile.cjs +14 -2
- package/dist/lib/compile/compile.d.ts.map +1 -1
- package/dist/lib/compile/node.cjs +100 -16
- package/dist/lib/compile/node.d.ts +24 -8
- package/dist/lib/compile/node.d.ts.map +1 -1
- package/dist/lib/compile/path/anchor.cjs +7 -6
- package/dist/lib/compile/path/anchor.d.ts.map +1 -1
- package/dist/lib/compile/path/index.cjs +5 -3
- package/dist/lib/compile/path/index.d.ts.map +1 -1
- package/dist/lib/compile/path/relative.cjs +1 -1
- package/dist/lib/compile/scope.cjs +2 -1
- package/dist/lib/compile/scope.d.ts.map +1 -1
- package/dist/lib/geometry/arc.cjs +66 -8
- package/dist/lib/geometry/arc.d.ts +14 -0
- package/dist/lib/geometry/arc.d.ts.map +1 -1
- package/dist/lib/geometry/index.d.ts +1 -0
- package/dist/lib/geometry/index.d.ts.map +1 -1
- package/dist/lib/geometry/rect.cjs +3 -3
- package/dist/lib/geometry/rect.d.ts +2 -2
- package/dist/lib/geometry/rect.d.ts.map +1 -1
- package/dist/lib/geometry/roundedContour.cjs +418 -0
- package/dist/lib/geometry/roundedContour.d.ts +88 -0
- package/dist/lib/geometry/roundedContour.d.ts.map +1 -0
- package/dist/lib/index.cjs +14 -7
- package/dist/lib/index.d.ts +6 -5
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/ir/boundary.cjs +15 -0
- package/dist/lib/ir/boundary.d.ts +25 -0
- package/dist/lib/ir/boundary.d.ts.map +1 -0
- package/dist/lib/ir/index.d.ts +2 -0
- package/dist/lib/ir/index.d.ts.map +1 -1
- package/dist/lib/ir/node.cjs +8 -3
- package/dist/lib/ir/node.d.ts +43 -7
- package/dist/lib/ir/node.d.ts.map +1 -1
- package/dist/lib/ir/path/arrow.d.ts +12 -12
- package/dist/lib/ir/path/path.cjs +2 -0
- package/dist/lib/ir/path/path.d.ts +490 -147
- package/dist/lib/ir/path/path.d.ts.map +1 -1
- package/dist/lib/ir/path/step.cjs +2 -2
- package/dist/lib/ir/path/step.d.ts +674 -154
- package/dist/lib/ir/path/step.d.ts.map +1 -1
- package/dist/lib/ir/path/target.cjs +4 -5
- package/dist/lib/ir/path/target.d.ts +43 -8
- package/dist/lib/ir/path/target.d.ts.map +1 -1
- package/dist/lib/ir/scope.cjs +6 -2
- package/dist/lib/ir/scope.d.ts +843 -234
- package/dist/lib/ir/scope.d.ts.map +1 -1
- package/dist/lib/ir/shape.cjs +9 -0
- package/dist/lib/ir/shape.d.ts +14 -0
- package/dist/lib/ir/shape.d.ts.map +1 -0
- package/dist/lib/parsers/parseNodeTarget.cjs +4 -2
- package/dist/lib/parsers/parseNodeTarget.d.ts.map +1 -1
- package/dist/lib/primitive/ellipse.d.ts +3 -0
- package/dist/lib/primitive/ellipse.d.ts.map +1 -1
- package/dist/lib/primitive/group.d.ts +3 -0
- package/dist/lib/primitive/group.d.ts.map +1 -1
- package/dist/lib/primitive/path.d.ts +3 -0
- package/dist/lib/primitive/path.d.ts.map +1 -1
- package/dist/lib/primitive/rect.d.ts +3 -0
- package/dist/lib/primitive/rect.d.ts.map +1 -1
- package/dist/lib/primitive/text.d.ts +3 -0
- package/dist/lib/primitive/text.d.ts.map +1 -1
- package/dist/lib/shapes/_contour.cjs +61 -0
- package/dist/lib/shapes/_contour.d.ts +19 -0
- package/dist/lib/shapes/_contour.d.ts.map +1 -0
- package/dist/lib/shapes/_shared.cjs +70 -0
- package/dist/lib/shapes/_shared.d.ts +54 -0
- package/dist/lib/shapes/_shared.d.ts.map +1 -1
- package/dist/lib/shapes/arc.cjs +104 -0
- package/dist/lib/shapes/arc.d.ts +8 -0
- package/dist/lib/shapes/arc.d.ts.map +1 -0
- package/dist/lib/shapes/define.cjs +13 -0
- package/dist/lib/shapes/define.d.ts +13 -0
- package/dist/lib/shapes/define.d.ts.map +1 -0
- package/dist/lib/shapes/ellipse.cjs +15 -7
- package/dist/lib/shapes/ellipse.d.ts +5 -4
- package/dist/lib/shapes/ellipse.d.ts.map +1 -1
- package/dist/lib/shapes/index.cjs +12 -6
- package/dist/lib/shapes/index.d.ts +9 -6
- package/dist/lib/shapes/index.d.ts.map +1 -1
- package/dist/lib/shapes/polygon.cjs +104 -0
- package/dist/lib/shapes/polygon.d.ts +13 -0
- package/dist/lib/shapes/polygon.d.ts.map +1 -0
- package/dist/lib/shapes/rectangle.cjs +37 -8
- package/dist/lib/shapes/rectangle.d.ts +7 -5
- package/dist/lib/shapes/rectangle.d.ts.map +1 -1
- package/dist/lib/shapes/sector.cjs +143 -0
- package/dist/lib/shapes/sector.d.ts +9 -0
- package/dist/lib/shapes/sector.d.ts.map +1 -0
- package/dist/lib/shapes/star.cjs +113 -0
- package/dist/lib/shapes/star.d.ts +15 -0
- package/dist/lib/shapes/star.d.ts.map +1 -0
- package/dist/lib/shapes/types.d.ts +47 -14
- package/dist/lib/shapes/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/es/shapes/circle.d.ts +0 -8
- package/dist/es/shapes/circle.d.ts.map +0 -1
- package/dist/es/shapes/circle.js +0 -34
- package/dist/es/shapes/diamond.d.ts +0 -8
- package/dist/es/shapes/diamond.d.ts.map +0 -1
- package/dist/es/shapes/diamond.js +0 -66
- package/dist/lib/shapes/circle.cjs +0 -34
- package/dist/lib/shapes/circle.d.ts +0 -8
- package/dist/lib/shapes/circle.d.ts.map +0 -1
- package/dist/lib/shapes/diamond.cjs +0 -66
- package/dist/lib/shapes/diamond.d.ts +0 -8
- package/dist/lib/shapes/diamond.d.ts.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/shapes/define.ts
|
|
2
|
+
/**
|
|
3
|
+
* 注册一个参数化 shape(定义点 typed,返回擦除形态进 registry)
|
|
4
|
+
* @description 定义点用具体 `TParams` 拿全程类型安全(`paramsSchema` 输出与 5 个计算函数末位 `params` 同型),
|
|
5
|
+
* 返回擦除成 `ShapeDefinition`(所有函数收 `IRJsonObject`)供同构 registry 存放。擦除的单点 cast 封在此处,
|
|
6
|
+
* **形状实现者不 cast**。含函数与 `paramsSchema`,**不进 IR**——它是 `CompileOptions.shapes` 运行时注入的
|
|
7
|
+
* TS 对象,符合 IR 100% JSON 可序列化约束(函数只在运行时注入面,不在 IR 字段里)。
|
|
8
|
+
* @param def shape 定义(paramsSchema / circumscribe / boundaryPoint / anchor / edgePoint? / emit)
|
|
9
|
+
* @returns 擦除成 `ShapeDefinition` 的同一份 def(便于 `export const sector = defineShape({ ... })`)
|
|
10
|
+
*/
|
|
11
|
+
var defineShape = (def) => def;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { defineShape };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ShapeDefinition } from './types';
|
|
2
1
|
/**
|
|
3
2
|
* ellipse 注册项
|
|
4
|
-
* @description circumscribe
|
|
5
|
-
*
|
|
3
|
+
* @description circumscribe 受 `params.circumscribe` 控制:`'equal'`(等轴,circle:两轴 = 内框对角线半长
|
|
4
|
+
* `√(hw²+hh²)`)/ `'proportional'`(默认,各轴 ×√2,内框 4 顶点落在椭圆周上)。几何由外接框半轴派生;
|
|
5
|
+
* emit / anchor / edgePoint / boundaryPoint 只一套(不读 `params`)。circle 在 compile 期规范化为
|
|
6
|
+
* `{ type: 'ellipse', params: { circumscribe: 'equal' } }`。
|
|
6
7
|
*/
|
|
7
|
-
export declare const ellipse: ShapeDefinition;
|
|
8
|
+
export declare const ellipse: import('./types').ShapeDefinition;
|
|
8
9
|
//# sourceMappingURL=ellipse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ellipse.d.ts","sourceRoot":"","sources":["../../../src/shapes/ellipse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ellipse.d.ts","sourceRoot":"","sources":["../../../src/shapes/ellipse.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,mCAmClB,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineShape } from "./define.js";
|
|
2
2
|
import { asRectAnchor } from "./_shared.js";
|
|
3
|
+
import { ellipse as ellipse$1 } from "../geometry/ellipse.js";
|
|
4
|
+
import { z } from "zod";
|
|
3
5
|
//#region src/shapes/ellipse.ts
|
|
4
6
|
/** 外接框 Rect → Ellipse(rx/ry = 半宽/半高) */
|
|
5
7
|
var toEllipse = (r) => ({
|
|
@@ -11,14 +13,20 @@ var toEllipse = (r) => ({
|
|
|
11
13
|
});
|
|
12
14
|
/**
|
|
13
15
|
* ellipse 注册项
|
|
14
|
-
* @description circumscribe
|
|
15
|
-
*
|
|
16
|
+
* @description circumscribe 受 `params.circumscribe` 控制:`'equal'`(等轴,circle:两轴 = 内框对角线半长
|
|
17
|
+
* `√(hw²+hh²)`)/ `'proportional'`(默认,各轴 ×√2,内框 4 顶点落在椭圆周上)。几何由外接框半轴派生;
|
|
18
|
+
* emit / anchor / edgePoint / boundaryPoint 只一套(不读 `params`)。circle 在 compile 期规范化为
|
|
19
|
+
* `{ type: 'ellipse', params: { circumscribe: 'equal' } }`。
|
|
16
20
|
*/
|
|
17
|
-
var ellipse = {
|
|
18
|
-
circumscribe: (
|
|
21
|
+
var ellipse = defineShape({
|
|
22
|
+
paramsSchema: z.strictObject({ circumscribe: z.enum(["proportional", "equal"]).optional().describe("Circumscription policy from the inner content box: \"proportional\" (per-axis ×√2, ellipse) or \"equal\" (isotropic, circle: r = diagonal half-length). Default \"proportional\".") }),
|
|
23
|
+
circumscribe: (hw, hh, params) => params.circumscribe === "equal" ? {
|
|
24
|
+
halfWidth: Math.hypot(hw, hh),
|
|
25
|
+
halfHeight: Math.hypot(hw, hh)
|
|
26
|
+
} : {
|
|
19
27
|
halfWidth: hw * Math.SQRT2,
|
|
20
28
|
halfHeight: hh * Math.SQRT2
|
|
21
|
-
}
|
|
29
|
+
},
|
|
22
30
|
boundaryPoint: (r, toward) => ellipse$1.boundaryPoint(toEllipse(r), toward),
|
|
23
31
|
anchor: (r, name) => {
|
|
24
32
|
const a = asRectAnchor(name);
|
|
@@ -41,6 +49,6 @@ var ellipse = {
|
|
|
41
49
|
opacity: style.opacity
|
|
42
50
|
};
|
|
43
51
|
}
|
|
44
|
-
};
|
|
52
|
+
});
|
|
45
53
|
//#endregion
|
|
46
54
|
export { ellipse };
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { BuiltinShapeName } from '../ir/node';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { arc } from './arc';
|
|
3
|
+
import { defineShape } from './define';
|
|
4
4
|
import { ellipse } from './ellipse';
|
|
5
|
+
import { polygon } from './polygon';
|
|
5
6
|
import { rectangle } from './rectangle';
|
|
7
|
+
import { sector } from './sector';
|
|
8
|
+
import { star } from './star';
|
|
6
9
|
import { ShapeDefinition } from './types';
|
|
7
|
-
/** 内置
|
|
8
|
-
export declare const BUILTIN_SHAPES: Record<BuiltinShapeName, ShapeDefinition>;
|
|
9
|
-
export { rectangle,
|
|
10
|
-
export type { ShapeDefinition, ShapeStyle } from './types';
|
|
10
|
+
/** 内置 shape 注册项(circle / diamond 已收为 preset,不占独立项);与 `CompileOptions.shapes` 合并时被同名注入覆盖 */
|
|
11
|
+
export declare const BUILTIN_SHAPES: Record<Exclude<BuiltinShapeName, 'circle' | 'diamond'> | 'sector' | 'arc' | 'polygon' | 'star', ShapeDefinition>;
|
|
12
|
+
export { rectangle, ellipse, polygon, sector, arc, star, defineShape };
|
|
13
|
+
export type { ShapeDefinition, ShapeDefinitionInput, ShapeStyle } from './types';
|
|
11
14
|
export type { Rect } from '../geometry/rect';
|
|
12
15
|
export type { Position } from '../geometry/point';
|
|
13
16
|
export { worldToLocal, localToWorld } from '../geometry/_transform';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/shapes/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,2FAA2F;AAC3F,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,EAAE,eAAe,CAO3I,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjF,YAAY,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/es/shapes/index.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import "../geometry/_transform.js";
|
|
2
|
+
import "./define.js";
|
|
3
|
+
import { arc } from "./arc.js";
|
|
2
4
|
import { ellipse } from "./ellipse.js";
|
|
3
|
-
import {
|
|
4
|
-
import { diamond } from "./diamond.js";
|
|
5
|
+
import { polygon } from "./polygon.js";
|
|
5
6
|
import { rectangle } from "./rectangle.js";
|
|
7
|
+
import { sector } from "./sector.js";
|
|
8
|
+
import { star } from "./star.js";
|
|
6
9
|
//#region src/shapes/index.ts
|
|
7
|
-
/** 内置
|
|
10
|
+
/** 内置 shape 注册项(circle / diamond 已收为 preset,不占独立项);与 `CompileOptions.shapes` 合并时被同名注入覆盖 */
|
|
8
11
|
var BUILTIN_SHAPES = {
|
|
9
12
|
rectangle,
|
|
10
|
-
circle,
|
|
11
13
|
ellipse,
|
|
12
|
-
|
|
14
|
+
sector,
|
|
15
|
+
arc,
|
|
16
|
+
polygon,
|
|
17
|
+
star
|
|
13
18
|
};
|
|
14
19
|
//#endregion
|
|
15
20
|
export { BUILTIN_SHAPES };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* polygon 注册项:正多边形(sides 顶点均布外接圆,rotate 定起始角,cornerRadius 顶点倒角)
|
|
3
|
+
* @description 文本容器形状——circumscribe 从内框 `innerHalfWidth/Height` 推能容纳内框的外接圆、再取其 AABB 半轴,
|
|
4
|
+
* 尺寸仍由内框 + minimumSize 驱动(区别于 sector / star 的 params-半径驱动)。emit / boundaryPoint 把顶点环构造成
|
|
5
|
+
* `sides` 条折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点插逐角夹紧的
|
|
6
|
+
* fillet 弧。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint 收带 rotate 的 rect 且 rayOrigin = 几何中心
|
|
7
|
+
* (多边形关于中心对称,AABB 中心 = 形心 = node position)。命名 anchor 走外接 AABB 的 9 名 rect anchor(不随
|
|
8
|
+
* cornerRadius 移);self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams:cornerRadius 是长度随 scale
|
|
9
|
+
* 缩(几何均值因子),sides 计数 / rotate 角度不缩。
|
|
10
|
+
* diamond ≡ `{ type: 'polygon', params: { sides: 4, rotate: 45 } }`,由 compile 规范化。
|
|
11
|
+
*/
|
|
12
|
+
export declare const polygon: import('./types').ShapeDefinition;
|
|
13
|
+
//# sourceMappingURL=polygon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../../src/shapes/polygon.ts"],"names":[],"mappings":"AA8EA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO,mCAiElB,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { localToWorld } from "../geometry/_transform.js";
|
|
2
|
+
import { rect } from "../geometry/rect.js";
|
|
3
|
+
import { defineShape } from "./define.js";
|
|
4
|
+
import { asRectAnchor } from "./_shared.js";
|
|
5
|
+
import { boundaryFromContour, contourCommands } from "../geometry/roundedContour.js";
|
|
6
|
+
import { contourToPathCommands, verticesToSegments } from "./_contour.js";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
//#region src/shapes/polygon.ts
|
|
9
|
+
var DEG_TO_RAD = Math.PI / 180;
|
|
10
|
+
/** 顶点角集合(度):第 k 个顶点角 = rotate + k·(360/sides) */
|
|
11
|
+
var vertexAngles = (params) => {
|
|
12
|
+
const startDeg = params.rotate ?? 0;
|
|
13
|
+
const stepDeg = 360 / params.sides;
|
|
14
|
+
const out = [];
|
|
15
|
+
for (let k = 0; k < params.sides; k++) out.push(startDeg + k * stepDeg);
|
|
16
|
+
return out;
|
|
17
|
+
};
|
|
18
|
+
/** 顶点角的 |cos| 最大值(恒 >0,sides≥3 时至少一个顶点不在 ±y 轴上);用于由 AABB 半宽反推外接半径 */
|
|
19
|
+
var maxAbsCos = (params) => Math.max(...vertexAngles(params).map((a) => Math.abs(Math.cos(a * DEG_TO_RAD))));
|
|
20
|
+
/**
|
|
21
|
+
* 能容纳内框(半轴 hw/hh)的正 sides 边形外接圆半径
|
|
22
|
+
* @description rectangle / polygon 是文本容器——尺寸由内框(text + padding)驱动,circumscribe 从内框推外接。
|
|
23
|
+
* 正多边形 = 各边内法向投影 ≤ 内切半径(apothem) 的半平面交;apothem = R·cos(π/sides)。内框 4 角
|
|
24
|
+
* (±hw,±hh) 全在多边形内 ⇔ 对每条边法向 φ_j,max 角投影 hw·|cosφ_j|+hh·|sinφ_j| ≤ apothem。
|
|
25
|
+
* 取使等号成立的最小 R = max_j(hw·|cosφ_j|+hh·|sinφ_j|) / cos(π/sides),φ_j = rotate+(j+0.5)·(360/sides)。
|
|
26
|
+
*/
|
|
27
|
+
var circumradiusFor = (hw, hh, params) => {
|
|
28
|
+
const { sides } = params;
|
|
29
|
+
const startDeg = params.rotate ?? 0;
|
|
30
|
+
const stepDeg = 360 / sides;
|
|
31
|
+
const apothemFactor = Math.cos(Math.PI / sides);
|
|
32
|
+
let maxSupport = 0;
|
|
33
|
+
for (let j = 0; j < sides; j++) {
|
|
34
|
+
const phi = (startDeg + (j + .5) * stepDeg) * DEG_TO_RAD;
|
|
35
|
+
const support = hw * Math.abs(Math.cos(phi)) + hh * Math.abs(Math.sin(phi));
|
|
36
|
+
if (support > maxSupport) maxSupport = support;
|
|
37
|
+
}
|
|
38
|
+
return maxSupport / apothemFactor;
|
|
39
|
+
};
|
|
40
|
+
/** 由外接 AABB(emit / boundaryPoint 收到的 rect)反推外接圆半径:R = halfWidth / max|cosθ_k| */
|
|
41
|
+
var circumradiusFromRect = (rect, params) => rect.width / 2 / maxAbsCos(params);
|
|
42
|
+
/**
|
|
43
|
+
* 正多边形 `sides` 个顶点的世界坐标(外接圆半径 radius、起始角 rotate、绕 rect 中心)
|
|
44
|
+
* @description 顶点均布外接圆:第 k 个顶点角 = rotate + k·(360/sides);点在 rect 局部系算后经 localToWorld 投世界。
|
|
45
|
+
* emit / boundaryPoint / anchor 共用此真源。
|
|
46
|
+
*/
|
|
47
|
+
var polygonVertices = (rect, radius, params) => vertexAngles(params).map((deg) => {
|
|
48
|
+
const a = deg * DEG_TO_RAD;
|
|
49
|
+
return localToWorld(rect, [radius * Math.cos(a), radius * Math.sin(a)]);
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* polygon 注册项:正多边形(sides 顶点均布外接圆,rotate 定起始角,cornerRadius 顶点倒角)
|
|
53
|
+
* @description 文本容器形状——circumscribe 从内框 `innerHalfWidth/Height` 推能容纳内框的外接圆、再取其 AABB 半轴,
|
|
54
|
+
* 尺寸仍由内框 + minimumSize 驱动(区别于 sector / star 的 params-半径驱动)。emit / boundaryPoint 把顶点环构造成
|
|
55
|
+
* `sides` 条折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点插逐角夹紧的
|
|
56
|
+
* fillet 弧。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint 收带 rotate 的 rect 且 rayOrigin = 几何中心
|
|
57
|
+
* (多边形关于中心对称,AABB 中心 = 形心 = node position)。命名 anchor 走外接 AABB 的 9 名 rect anchor(不随
|
|
58
|
+
* cornerRadius 移);self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams:cornerRadius 是长度随 scale
|
|
59
|
+
* 缩(几何均值因子),sides 计数 / rotate 角度不缩。
|
|
60
|
+
* diamond ≡ `{ type: 'polygon', params: { sides: 4, rotate: 45 } }`,由 compile 规范化。
|
|
61
|
+
*/
|
|
62
|
+
var polygon = defineShape({
|
|
63
|
+
paramsSchema: z.strictObject({
|
|
64
|
+
sides: z.number().int().min(3).describe("Number of sides of the regular polygon (>= 3)."),
|
|
65
|
+
rotate: z.number().finite().optional().describe("Shape self-rotation in degrees (vertex start direction); default 0. Composes with Node.rotate."),
|
|
66
|
+
cornerRadius: z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.")
|
|
67
|
+
}),
|
|
68
|
+
circumscribe: (hw, hh, params) => {
|
|
69
|
+
const radius = circumradiusFor(hw, hh, params);
|
|
70
|
+
const angles = vertexAngles(params);
|
|
71
|
+
return {
|
|
72
|
+
halfWidth: Math.max(...angles.map((a) => Math.abs(radius * Math.cos(a * DEG_TO_RAD)))),
|
|
73
|
+
halfHeight: Math.max(...angles.map((a) => Math.abs(radius * Math.sin(a * DEG_TO_RAD))))
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
boundaryPoint: (rect, toward, params) => {
|
|
77
|
+
const segments = verticesToSegments(polygonVertices(rect, circumradiusFromRect(rect, params), params));
|
|
78
|
+
const center = [rect.x, rect.y];
|
|
79
|
+
return boundaryFromContour(segments, params.cornerRadius, center, toward) ?? center;
|
|
80
|
+
},
|
|
81
|
+
anchor: (rect$1, name, params) => {
|
|
82
|
+
const a = asRectAnchor(name);
|
|
83
|
+
return a ? rect.anchor(rect$1, a) : void 0;
|
|
84
|
+
},
|
|
85
|
+
*emit(rect, style, round, params) {
|
|
86
|
+
yield {
|
|
87
|
+
type: "path",
|
|
88
|
+
commands: contourToPathCommands(contourCommands(verticesToSegments(polygonVertices(rect, circumradiusFromRect(rect, params), params)), params.cornerRadius), round),
|
|
89
|
+
fill: style.fill ?? "transparent",
|
|
90
|
+
fillOpacity: style.fillOpacity,
|
|
91
|
+
stroke: style.stroke ?? "currentColor",
|
|
92
|
+
strokeOpacity: style.strokeOpacity,
|
|
93
|
+
strokeWidth: style.strokeWidth ?? 1,
|
|
94
|
+
dashPattern: style.dashPattern,
|
|
95
|
+
opacity: style.opacity
|
|
96
|
+
};
|
|
97
|
+
},
|
|
98
|
+
scaleParams: (params, sx, sy) => params.cornerRadius === void 0 ? params : {
|
|
99
|
+
...params,
|
|
100
|
+
cornerRadius: params.cornerRadius * Math.sqrt(sx * sy)
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
//#endregion
|
|
104
|
+
export { polygon };
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { ShapeDefinition } from './types';
|
|
2
1
|
/**
|
|
3
|
-
* rectangle
|
|
4
|
-
* @description circumscribe = identity(视觉边界 = 内框);
|
|
5
|
-
*
|
|
2
|
+
* rectangle 注册项(文本容器形状,尺寸由内框 + minimumSize 驱动)
|
|
3
|
+
* @description circumscribe = identity(视觉边界 = 内框);anchor / edgePoint 直接走 rect 数学层;
|
|
4
|
+
* boundaryPoint 把矩形 4 角构造成 4 条折线段、委托 rounded-contour 模块(cornerRadius 省略 / 0 出原尖角
|
|
5
|
+
* 求交、>0 在每个角插逐角夹紧的 fillet 弧,连接感知倒角),rayOrigin = 矩形中心(= node position)。
|
|
6
|
+
* emit 仍出 RectPrim,圆角半径优先取 `params.cornerRadius`、回退到 `style.cornerRadius`(顶层迁移期兼容)。
|
|
7
|
+
* scaleParams:cornerRadius 是长度,随 node scale 用 uniform 几何均值因子协同缩放(边数 / 角度类参数才不缩)。
|
|
6
8
|
*/
|
|
7
|
-
export declare const rectangle: ShapeDefinition;
|
|
9
|
+
export declare const rectangle: import('./types').ShapeDefinition;
|
|
8
10
|
//# sourceMappingURL=rectangle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rectangle.d.ts","sourceRoot":"","sources":["../../../src/shapes/rectangle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rectangle.d.ts","sourceRoot":"","sources":["../../../src/shapes/rectangle.ts"],"names":[],"mappings":"AAgCA;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,mCAiDpB,CAAC"}
|
|
@@ -1,25 +1,50 @@
|
|
|
1
|
+
import { localToWorld } from "../geometry/_transform.js";
|
|
1
2
|
import { rect } from "../geometry/rect.js";
|
|
3
|
+
import { defineShape } from "./define.js";
|
|
2
4
|
import { asRectAnchor } from "./_shared.js";
|
|
5
|
+
import { boundaryFromContour } from "../geometry/roundedContour.js";
|
|
6
|
+
import { verticesToSegments } from "./_contour.js";
|
|
7
|
+
import { z } from "zod";
|
|
3
8
|
//#region src/shapes/rectangle.ts
|
|
9
|
+
/** 轴对齐 / 旋转矩形的 4 个角(CW 绕向:左上 → 右上 → 右下 → 左下),局部系经 localToWorld 投世界 */
|
|
10
|
+
var rectVertices = (rect) => {
|
|
11
|
+
const halfW = rect.width / 2;
|
|
12
|
+
const halfH = rect.height / 2;
|
|
13
|
+
return [
|
|
14
|
+
localToWorld(rect, [-halfW, -halfH]),
|
|
15
|
+
localToWorld(rect, [halfW, -halfH]),
|
|
16
|
+
localToWorld(rect, [halfW, halfH]),
|
|
17
|
+
localToWorld(rect, [-halfW, halfH])
|
|
18
|
+
];
|
|
19
|
+
};
|
|
4
20
|
/**
|
|
5
|
-
* rectangle
|
|
6
|
-
* @description circumscribe = identity(视觉边界 = 内框);
|
|
7
|
-
*
|
|
21
|
+
* rectangle 注册项(文本容器形状,尺寸由内框 + minimumSize 驱动)
|
|
22
|
+
* @description circumscribe = identity(视觉边界 = 内框);anchor / edgePoint 直接走 rect 数学层;
|
|
23
|
+
* boundaryPoint 把矩形 4 角构造成 4 条折线段、委托 rounded-contour 模块(cornerRadius 省略 / 0 出原尖角
|
|
24
|
+
* 求交、>0 在每个角插逐角夹紧的 fillet 弧,连接感知倒角),rayOrigin = 矩形中心(= node position)。
|
|
25
|
+
* emit 仍出 RectPrim,圆角半径优先取 `params.cornerRadius`、回退到 `style.cornerRadius`(顶层迁移期兼容)。
|
|
26
|
+
* scaleParams:cornerRadius 是长度,随 node scale 用 uniform 几何均值因子协同缩放(边数 / 角度类参数才不缩)。
|
|
8
27
|
*/
|
|
9
|
-
var rectangle = {
|
|
28
|
+
var rectangle = defineShape({
|
|
29
|
+
paramsSchema: z.strictObject({ cornerRadius: z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.") }),
|
|
10
30
|
circumscribe: (hw, hh) => ({
|
|
11
31
|
halfWidth: hw,
|
|
12
32
|
halfHeight: hh
|
|
13
33
|
}),
|
|
14
|
-
boundaryPoint: (
|
|
34
|
+
boundaryPoint: (rect, toward, params) => {
|
|
35
|
+
const segments = verticesToSegments(rectVertices(rect));
|
|
36
|
+
const center = [rect.x, rect.y];
|
|
37
|
+
return boundaryFromContour(segments, params.cornerRadius, center, toward) ?? center;
|
|
38
|
+
},
|
|
15
39
|
anchor: (r, name) => {
|
|
16
40
|
const a = asRectAnchor(name);
|
|
17
41
|
return a ? rect.anchor(r, a) : void 0;
|
|
18
42
|
},
|
|
19
43
|
edgePoint: (r, side, t) => rect.edgePoint(r, side, t),
|
|
20
|
-
*emit(r, style, round) {
|
|
44
|
+
*emit(r, style, round, params) {
|
|
21
45
|
const halfW = r.width / 2;
|
|
22
46
|
const halfH = r.height / 2;
|
|
47
|
+
const cornerRadius = params.cornerRadius ?? style.cornerRadius;
|
|
23
48
|
yield {
|
|
24
49
|
type: "rect",
|
|
25
50
|
x: round(r.x - halfW),
|
|
@@ -32,10 +57,14 @@ var rectangle = {
|
|
|
32
57
|
strokeOpacity: style.strokeOpacity,
|
|
33
58
|
strokeWidth: style.strokeWidth ?? 1,
|
|
34
59
|
dashPattern: style.dashPattern,
|
|
35
|
-
cornerRadius:
|
|
60
|
+
cornerRadius: cornerRadius !== void 0 ? round(cornerRadius) : void 0,
|
|
36
61
|
opacity: style.opacity
|
|
37
62
|
};
|
|
63
|
+
},
|
|
64
|
+
scaleParams: (params, sx, sy) => params.cornerRadius === void 0 ? params : {
|
|
65
|
+
...params,
|
|
66
|
+
cornerRadius: params.cornerRadius * Math.sqrt(sx * sy)
|
|
38
67
|
}
|
|
39
|
-
};
|
|
68
|
+
});
|
|
40
69
|
//#endregion
|
|
41
70
|
export { rectangle };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sector 注册项:环楔(内外半径 + 起止角围成的可填充 2D 区域)
|
|
3
|
+
* @description 四何函数共用 `sectorGeometry`(单一真源):circumscribe 返回含圆心 + 内外弧的精确 AABB 半轴
|
|
4
|
+
* (含弧跨过 90°·k 轴向的 outerRadius 极值点),node position = AABB 中心;anchor 含 apex(圆心)/ centroid /
|
|
5
|
+
* inner-arc-mid / outer-arc-mid / start-edge-mid / end-edge-mid + 角度边界点;emit 出外弧 + 两径向边 + 内弧
|
|
6
|
+
* 闭合 path(innerRadius=0 时径向边交于圆心、无内弧)。scaleParams 只缩半径、不缩角度。
|
|
7
|
+
*/
|
|
8
|
+
export declare const sector: import('./types').ShapeDefinition;
|
|
9
|
+
//# sourceMappingURL=sector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sector.d.ts","sourceRoot":"","sources":["../../../src/shapes/sector.ts"],"names":[],"mappings":"AA0EA;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,mCAgGjB,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { localToWorld } from "../geometry/_transform.js";
|
|
2
|
+
import { defineShape } from "./define.js";
|
|
3
|
+
import { sectorGeometry, sectorPolarPoint } from "./_shared.js";
|
|
4
|
+
import { boundaryFromContour, contourCommands } from "../geometry/roundedContour.js";
|
|
5
|
+
import { contourToPathCommands } from "./_contour.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
//#region src/shapes/sector.ts
|
|
8
|
+
/** sector 局部 AABB 系点(圆心为原点偏移后)→ 世界系(含 rect 旋转 / 平移) */
|
|
9
|
+
var toWorld = (rect, geo, localFromApex) => {
|
|
10
|
+
return localToWorld(rect, [localFromApex[0] + geo.apexOffset[0], localFromApex[1] + geo.apexOffset[1]]);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 构造 sector 闭合轮廓的有序段序列(line + arc),段序与现状 emit 完全一致
|
|
14
|
+
* @description 环楔(innerRadius>0)4 段闭环:radial Line(inner-start→outer-start) → outer Arc(start→end, CW)
|
|
15
|
+
* → radial Line(outer-end→inner-end) → inner Arc(end→start, CCW)。pie(innerRadius=0)3 段闭环:
|
|
16
|
+
* radial Line(apex→outer-start) → outer Arc(start→end, CW) → radial Line(outer-end→apex),apex 处为 line-line 接缝。
|
|
17
|
+
* Arc 圆心 = apex 世界坐标、半径 = inner/outer radius、起止角与现状 emit 同(度,CW 即 counterClockwise=false)。
|
|
18
|
+
* emit / boundaryPoint 共用此真源;emit 收轴对齐 rect、boundaryPoint 收带 rotate 的 rect,rect 不同自然投不同世界系。
|
|
19
|
+
*/
|
|
20
|
+
var sectorSegments = (rect, geo, params) => {
|
|
21
|
+
const { innerRadius, outerRadius } = params;
|
|
22
|
+
const { start, end } = geo.range;
|
|
23
|
+
const apex = toWorld(rect, geo, [0, 0]);
|
|
24
|
+
const rotateDeg = (rect.rotate ?? 0) * 180 / Math.PI;
|
|
25
|
+
const sa = start + rotateDeg;
|
|
26
|
+
const ea = end + rotateDeg;
|
|
27
|
+
const outerStart = toWorld(rect, geo, sectorPolarPoint(outerRadius, start));
|
|
28
|
+
if (innerRadius > 0) {
|
|
29
|
+
const innerStart = toWorld(rect, geo, sectorPolarPoint(innerRadius, start));
|
|
30
|
+
const innerEnd = toWorld(rect, geo, sectorPolarPoint(innerRadius, end));
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
kind: "line",
|
|
34
|
+
from: innerStart,
|
|
35
|
+
to: outerStart
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
kind: "arc",
|
|
39
|
+
center: apex,
|
|
40
|
+
radius: outerRadius,
|
|
41
|
+
startAngle: sa,
|
|
42
|
+
endAngle: ea
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
kind: "line",
|
|
46
|
+
from: toWorld(rect, geo, sectorPolarPoint(outerRadius, end)),
|
|
47
|
+
to: innerEnd
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
kind: "arc",
|
|
51
|
+
center: apex,
|
|
52
|
+
radius: innerRadius,
|
|
53
|
+
startAngle: ea,
|
|
54
|
+
endAngle: sa,
|
|
55
|
+
counterClockwise: true
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
kind: "line",
|
|
62
|
+
from: apex,
|
|
63
|
+
to: outerStart
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
kind: "arc",
|
|
67
|
+
center: apex,
|
|
68
|
+
radius: outerRadius,
|
|
69
|
+
startAngle: sa,
|
|
70
|
+
endAngle: ea
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
kind: "line",
|
|
74
|
+
from: toWorld(rect, geo, sectorPolarPoint(outerRadius, end)),
|
|
75
|
+
to: apex
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* sector 注册项:环楔(内外半径 + 起止角围成的可填充 2D 区域)
|
|
81
|
+
* @description 四何函数共用 `sectorGeometry`(单一真源):circumscribe 返回含圆心 + 内外弧的精确 AABB 半轴
|
|
82
|
+
* (含弧跨过 90°·k 轴向的 outerRadius 极值点),node position = AABB 中心;anchor 含 apex(圆心)/ centroid /
|
|
83
|
+
* inner-arc-mid / outer-arc-mid / start-edge-mid / end-edge-mid + 角度边界点;emit 出外弧 + 两径向边 + 内弧
|
|
84
|
+
* 闭合 path(innerRadius=0 时径向边交于圆心、无内弧)。scaleParams 只缩半径、不缩角度。
|
|
85
|
+
*/
|
|
86
|
+
var sector = defineShape({
|
|
87
|
+
paramsSchema: z.strictObject({
|
|
88
|
+
innerRadius: z.number().finite().nonnegative().describe("Inner radius (user units); 0 = solid pie slice."),
|
|
89
|
+
outerRadius: z.number().finite().positive().describe("Outer radius (user units); must be > innerRadius."),
|
|
90
|
+
startAngle: z.number().finite().describe("Start angle in degrees; polar convention 0°=+x, 90°=+y (screen y-down), matching core polar."),
|
|
91
|
+
endAngle: z.number().finite().describe("End angle in degrees; swept counterclockwise in screen space from startAngle."),
|
|
92
|
+
cornerRadius: z.number().finite().nonnegative().optional().describe("Corner radius in user units; 0 / omitted = sharp corners. Clamped per corner to the largest non-self-intersecting fillet.")
|
|
93
|
+
}).refine((p) => p.outerRadius > p.innerRadius, { message: "outerRadius must be greater than innerRadius" }),
|
|
94
|
+
circumscribe: (_hw, _hh, params) => sectorGeometry(params).aabbHalfAxes,
|
|
95
|
+
circumscribeOffset: (params) => {
|
|
96
|
+
const { apexOffset } = sectorGeometry(params);
|
|
97
|
+
return [-apexOffset[0], -apexOffset[1]];
|
|
98
|
+
},
|
|
99
|
+
boundaryPoint: (rect, toward, params) => {
|
|
100
|
+
const geo = sectorGeometry(params);
|
|
101
|
+
const centroidWorld = localToWorld(rect, geo.centroidOffset);
|
|
102
|
+
return boundaryFromContour(sectorSegments(rect, geo, params), params.cornerRadius, centroidWorld, toward) ?? centroidWorld;
|
|
103
|
+
},
|
|
104
|
+
anchor: (rect, name, params) => {
|
|
105
|
+
const geo = sectorGeometry(params);
|
|
106
|
+
const { innerRadius, outerRadius } = params;
|
|
107
|
+
const { start, end, mid } = geo.range;
|
|
108
|
+
switch (name) {
|
|
109
|
+
case "apex":
|
|
110
|
+
case "center": return toWorld(rect, geo, [0, 0]);
|
|
111
|
+
case "centroid": return localToWorld(rect, geo.centroidOffset);
|
|
112
|
+
case "outer-arc-mid": return toWorld(rect, geo, sectorPolarPoint(outerRadius, mid));
|
|
113
|
+
case "inner-arc-mid": return toWorld(rect, geo, sectorPolarPoint(innerRadius, mid));
|
|
114
|
+
case "start-edge-mid": return toWorld(rect, geo, sectorPolarPoint((innerRadius + outerRadius) / 2, start));
|
|
115
|
+
case "end-edge-mid": return toWorld(rect, geo, sectorPolarPoint((innerRadius + outerRadius) / 2, end));
|
|
116
|
+
default: return;
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
*emit(rect, style, round, params) {
|
|
120
|
+
yield {
|
|
121
|
+
type: "path",
|
|
122
|
+
commands: contourToPathCommands(contourCommands(sectorSegments(rect, sectorGeometry(params), params), params.cornerRadius), round),
|
|
123
|
+
fill: style.fill ?? "transparent",
|
|
124
|
+
fillOpacity: style.fillOpacity,
|
|
125
|
+
stroke: style.stroke ?? "currentColor",
|
|
126
|
+
strokeOpacity: style.strokeOpacity,
|
|
127
|
+
strokeWidth: style.strokeWidth ?? 1,
|
|
128
|
+
dashPattern: style.dashPattern,
|
|
129
|
+
opacity: style.opacity
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
scaleParams: (params, sx, sy) => {
|
|
133
|
+
const factor = Math.sqrt(sx * sy);
|
|
134
|
+
return {
|
|
135
|
+
...params,
|
|
136
|
+
innerRadius: params.innerRadius * factor,
|
|
137
|
+
outerRadius: params.outerRadius * factor,
|
|
138
|
+
...params.cornerRadius === void 0 ? {} : { cornerRadius: params.cornerRadius * factor }
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
//#endregion
|
|
143
|
+
export { sector };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* star 注册项:星形(外径尖角 / 内径凹角交替的 2×points 顶点闭合多边形)
|
|
3
|
+
* @description params-半径驱动的纯几何形状(像 sector,尺寸由 outerRadius 定、忽略文本内框):四何函数共用
|
|
4
|
+
* `starGeometry`(单一真源)。circumscribe 返回含全部尖角的精确 AABB 半轴(随 rotate 变,不随 cornerRadius 变);
|
|
5
|
+
* 星形关于中心对称 → AABB 中心 = 星形中心 = node position,无需 circumscribeOffset。emit / boundaryPoint 把
|
|
6
|
+
* `2×points` 顶点环构造成折线段,委托 rounded-contour 模块:cornerRadius 省略 / 0 出原尖角轮廓、>0 在每个顶点
|
|
7
|
+
* 插逐角夹紧的 fillet 弧——凸尖与凹角(notch)由模块按接缝转向叉积统一处理(凹角弧 sweep 反向、圆心在凸侧),
|
|
8
|
+
* emit 与 boundaryPoint 共用同一份 fillet 结果。emit 收轴对齐 rect(旋转由外层 group 施加)、boundaryPoint
|
|
9
|
+
* 收带 rotate 的 rect 且 rayOrigin = 星形几何中心(关于中心对称,AABB 中心 = 形心 = node position)。
|
|
10
|
+
* anchor 含 center / tip-N(第 N 尖角)/ notch-N(第 N 凹角)——恒在原尖角 / 凹角逻辑顶点,不随 cornerRadius 移;
|
|
11
|
+
* self-rotate(params.rotate)与 Node.rotate 叠加。scaleParams 只缩 inner/outerRadius / cornerRadius(长度)、
|
|
12
|
+
* 不缩 points(计数)/ rotate(角度)。
|
|
13
|
+
*/
|
|
14
|
+
export declare const star: import('./types').ShapeDefinition;
|
|
15
|
+
//# sourceMappingURL=star.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"star.d.ts","sourceRoot":"","sources":["../../../src/shapes/star.ts"],"names":[],"mappings":"AAsFA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,IAAI,mCA2Ff,CAAC"}
|