@wcardinal/wcardinal-ui 0.467.1 → 0.469.0-beta.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/dist/types/wcardinal/ui/d-diagram-serialized.d.ts +1 -1
- package/dist/types/wcardinal/ui/shape/e-shape-capability.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/e-shape-defaults.d.ts +2 -0
- package/dist/types/wcardinal/ui/shape/e-shape-type.d.ts +3 -0
- package/dist/types/wcardinal/ui/shape/e-shape.d.ts +1 -0
- package/dist/types/wcardinal/ui/shape/load/index.d.ts +3 -0
- package/dist/types/wcardinal/ui/shape/load/load-shape-fan.d.ts +1 -0
- package/dist/types/wcardinal/ui/shape/load/load-shape-semicircle-legacy.d.ts +1 -0
- package/dist/types/wcardinal/ui/shape/load/load-shape-triangle-rounded-legacy.d.ts +1 -0
- package/dist/types/wcardinal/ui/shape/variant/build-semicircle-legacy.d.ts +9 -0
- package/dist/types/wcardinal/ui/shape/variant/build-semicircle.d.ts +1 -9
- package/dist/types/wcardinal/ui/shape/variant/build-triangle-rounded-legacy.d.ts +10 -0
- package/dist/types/wcardinal/ui/shape/variant/build-triangle-rounded.d.ts +1 -10
- package/dist/types/wcardinal/ui/shape/variant/builder-semicircle-legacy.d.ts +10 -0
- package/dist/types/wcardinal/ui/shape/variant/builder-semicircle.d.ts +1 -10
- package/dist/types/wcardinal/ui/shape/variant/builder-triangle-rounded-legacy.d.ts +12 -0
- package/dist/types/wcardinal/ui/shape/variant/builder-triangle-rounded.d.ts +1 -12
- package/dist/types/wcardinal/ui/shape/variant/create-semicircle-legacy-uploaded.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/create-semicircle-uploaded.d.ts +1 -4
- package/dist/types/wcardinal/ui/shape/variant/create-triangle-rounded-legacy-uploaded.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/create-triangle-rounded-uploaded.d.ts +1 -4
- package/dist/types/wcardinal/ui/shape/variant/deserialize-fan.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/deserialize-semicircle-legacy.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/deserialize-triangle-rounded-legacy.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-base.d.ts +1 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-button.d.ts +2 -1
- package/dist/types/wcardinal/ui/shape/variant/e-shape-circle-triangulated-impl.d.ts +2 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-fan-triangulated-impl.d.ts +200 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-fan-triangulated.d.ts +3 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-fan.d.ts +26 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-group-viewer.d.ts +2 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-group.d.ts +2 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-line-of-triangle-roundeds.d.ts +2 -2
- package/dist/types/wcardinal/ui/shape/variant/e-shape-primitive.d.ts +2 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-rectangle-rounded-triangulated-impl.d.ts +18 -18
- package/dist/types/wcardinal/ui/shape/variant/e-shape-semicircle-legacy.d.ts +10 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-semicircle.d.ts +9 -2
- package/dist/types/wcardinal/ui/shape/variant/e-shape-triangle-rounded-legacy.d.ts +7 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-triangle-rounded-triangulated-impl.d.ts +42 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-triangle-rounded-triangulated.d.ts +3 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-triangle-rounded.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/e-shape-triangle-triangulated-impl.d.ts +1 -1
- package/dist/types/wcardinal/ui/shape/variant/hit-test-fan.d.ts +2 -0
- package/dist/types/wcardinal/ui/shape/variant/hit-test-triangle-rounded.d.ts +1 -0
- package/dist/types/wcardinal/ui/shape/variant/index.d.ts +18 -0
- package/dist/types/wcardinal/ui/shape/variant/to-fan-angle-centric.d.ts +4 -0
- package/dist/types/wcardinal/ui/shape/variant/to-fan-angle-eccentric.d.ts +5 -0
- package/dist/types/wcardinal/ui/theme/dark/e-theme-dark-shape.d.ts +1 -0
- package/dist/types/wcardinal/ui/theme/white/e-theme-white-shape.d.ts +1 -0
- package/dist/wcardinal/ui/d-diagram-serialized.js.map +1 -1
- package/dist/wcardinal/ui/shape/e-shape-capability.js +6 -1
- package/dist/wcardinal/ui/shape/e-shape-capability.js.map +1 -1
- package/dist/wcardinal/ui/shape/e-shape-defaults.js +7 -0
- package/dist/wcardinal/ui/shape/e-shape-defaults.js.map +1 -1
- package/dist/wcardinal/ui/shape/e-shape-type.js +3 -0
- package/dist/wcardinal/ui/shape/e-shape-type.js.map +1 -1
- package/dist/wcardinal/ui/shape/e-shape.js.map +1 -1
- package/dist/wcardinal/ui/shape/load/index.js +3 -0
- package/dist/wcardinal/ui/shape/load/index.js.map +1 -1
- package/dist/wcardinal/ui/shape/load/load-shape-all.js +6 -0
- package/dist/wcardinal/ui/shape/load/load-shape-all.js.map +1 -1
- package/dist/wcardinal/ui/shape/load/load-shape-fan.js +17 -0
- package/dist/wcardinal/ui/shape/load/load-shape-fan.js.map +1 -0
- package/dist/wcardinal/ui/shape/load/load-shape-semicircle-legacy.js +14 -0
- package/dist/wcardinal/ui/shape/load/load-shape-semicircle-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/load/load-shape-semicircle.js +5 -2
- package/dist/wcardinal/ui/shape/load/load-shape-semicircle.js.map +1 -1
- package/dist/wcardinal/ui/shape/load/load-shape-triangle-rounded-legacy.js +17 -0
- package/dist/wcardinal/ui/shape/load/load-shape-triangle-rounded-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/load/load-shape-triangle-rounded.js +2 -2
- package/dist/wcardinal/ui/shape/load/load-shape-triangle-rounded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/build-rectangle-legacy.js +4 -0
- package/dist/wcardinal/ui/shape/variant/build-rectangle-legacy.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/build-rectangle-rounded-legacy.js +20 -19
- package/dist/wcardinal/ui/shape/variant/build-rectangle-rounded-legacy.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/build-semicircle-legacy.js +137 -0
- package/dist/wcardinal/ui/shape/variant/build-semicircle-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/build-semicircle.js +1 -139
- package/dist/wcardinal/ui/shape/variant/build-semicircle.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/build-triangle-legacy.js +4 -0
- package/dist/wcardinal/ui/shape/variant/build-triangle-legacy.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/build-triangle-rounded-legacy.js +538 -0
- package/dist/wcardinal/ui/shape/variant/build-triangle-rounded-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/build-triangle-rounded.js +5 -536
- package/dist/wcardinal/ui/shape/variant/build-triangle-rounded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/builder-semicircle-legacy.js +76 -0
- package/dist/wcardinal/ui/shape/variant/builder-semicircle-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/builder-semicircle.js +1 -71
- package/dist/wcardinal/ui/shape/variant/builder-semicircle.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/builder-triangle-rounded-legacy.js +84 -0
- package/dist/wcardinal/ui/shape/variant/builder-triangle-rounded-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/builder-triangle-rounded.js +1 -79
- package/dist/wcardinal/ui/shape/variant/builder-triangle-rounded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/create-semicircle-legacy-uploaded.js +24 -0
- package/dist/wcardinal/ui/shape/variant/create-semicircle-legacy-uploaded.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/create-semicircle-uploaded.js +1 -19
- package/dist/wcardinal/ui/shape/variant/create-semicircle-uploaded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/create-triangle-rounded-legacy-uploaded.js +24 -0
- package/dist/wcardinal/ui/shape/variant/create-triangle-rounded-legacy-uploaded.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/create-triangle-rounded-uploaded.js +1 -19
- package/dist/wcardinal/ui/shape/variant/create-triangle-rounded-uploaded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/deserialize-fan.js +12 -0
- package/dist/wcardinal/ui/shape/variant/deserialize-fan.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/deserialize-semicircle-legacy.js +10 -0
- package/dist/wcardinal/ui/shape/variant/deserialize-semicircle-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/deserialize-triangle-rounded-legacy.js +10 -0
- package/dist/wcardinal/ui/shape/variant/deserialize-triangle-rounded-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-base.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-button.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-circle-triangulated-impl.js +134 -199
- package/dist/wcardinal/ui/shape/variant/e-shape-circle-triangulated-impl.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-connector-line.js +0 -2
- package/dist/wcardinal/ui/shape/variant/e-shape-connector-line.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-embedded-acceptor-edge.js +0 -2
- package/dist/wcardinal/ui/shape/variant/e-shape-embedded-acceptor-edge.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-fan-triangulated-impl.js +724 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-fan-triangulated-impl.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-fan-triangulated.js +6 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-fan-triangulated.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-fan.js +85 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-fan.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-group-viewer.js +10 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-group-viewer.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-group.js +18 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-group.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-line-of-triangle-roundeds.js +2 -2
- package/dist/wcardinal/ui/shape/variant/e-shape-line-of-triangle-roundeds.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-polygon.js +3 -4
- package/dist/wcardinal/ui/shape/variant/e-shape-polygon.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-primitive.js +10 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-primitive.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-rectangle-rounded-triangulated-impl.js +62 -64
- package/dist/wcardinal/ui/shape/variant/e-shape-rectangle-rounded-triangulated-impl.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-semicircle-legacy.js +33 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-semicircle-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-semicircle.js +36 -6
- package/dist/wcardinal/ui/shape/variant/e-shape-semicircle.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded-legacy.js +27 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded-legacy.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded-triangulated-impl.js +437 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded-triangulated-impl.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded-triangulated.js +6 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded-triangulated.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded.js +15 -2
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-rounded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-triangulated-impl.js +31 -30
- package/dist/wcardinal/ui/shape/variant/e-shape-triangle-triangulated-impl.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/hit-test-fan.js +79 -0
- package/dist/wcardinal/ui/shape/variant/hit-test-fan.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/hit-test-triangle-rounded.js +71 -11
- package/dist/wcardinal/ui/shape/variant/hit-test-triangle-rounded.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/index.js +18 -0
- package/dist/wcardinal/ui/shape/variant/index.js.map +1 -1
- package/dist/wcardinal/ui/shape/variant/to-fan-angle-centric.js +11 -0
- package/dist/wcardinal/ui/shape/variant/to-fan-angle-centric.js.map +1 -0
- package/dist/wcardinal/ui/shape/variant/to-fan-angle-eccentric.js +12 -0
- package/dist/wcardinal/ui/shape/variant/to-fan-angle-eccentric.js.map +1 -0
- package/dist/wcardinal/ui/theme/dark/e-theme-dark-shape.js +3 -0
- package/dist/wcardinal/ui/theme/dark/e-theme-dark-shape.js.map +1 -1
- package/dist/wcardinal/ui/theme/white/e-theme-white-shape.js +3 -0
- package/dist/wcardinal/ui/theme/white/e-theme-white-shape.js.map +1 -1
- package/dist/wcardinal-ui-theme-dark-en-us.js +4 -1
- package/dist/wcardinal-ui-theme-dark-en-us.min.js +2 -2
- package/dist/wcardinal-ui-theme-dark-en-us.min.js.map +1 -1
- package/dist/wcardinal-ui-theme-dark-ja-jp.js +4 -1
- package/dist/wcardinal-ui-theme-dark-ja-jp.min.js +2 -2
- package/dist/wcardinal-ui-theme-dark-ja-jp.min.js.map +1 -1
- package/dist/wcardinal-ui-theme-dark.js +4 -1
- package/dist/wcardinal-ui-theme-dark.min.js +2 -2
- package/dist/wcardinal-ui-theme-white-en-us.js +4 -1
- package/dist/wcardinal-ui-theme-white-en-us.min.js +2 -2
- package/dist/wcardinal-ui-theme-white-en-us.min.js.map +1 -1
- package/dist/wcardinal-ui-theme-white-ja-jp.js +4 -1
- package/dist/wcardinal-ui-theme-white-ja-jp.min.js +2 -2
- package/dist/wcardinal-ui-theme-white-ja-jp.min.js.map +1 -1
- package/dist/wcardinal-ui-theme-white.js +4 -1
- package/dist/wcardinal-ui-theme-white.min.js +2 -2
- package/dist/wcardinal-ui.cjs.js +2050 -487
- package/dist/wcardinal-ui.js +2044 -487
- package/dist/wcardinal-ui.min.js +2 -2
- package/dist/wcardinal-ui.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019-2026 Toshiba Corporation
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { EShapeDefaults } from "../e-shape-defaults";
|
|
6
|
+
import { EShapeStrokeSide } from "../e-shape-stroke-side";
|
|
7
|
+
import { toFanAngleCentric } from "./to-fan-angle-centric";
|
|
8
|
+
import { toFanAngleEccentric } from "./to-fan-angle-eccentric";
|
|
9
|
+
/**
|
|
10
|
+
* Triangulates a fan whose arc is on the ellipse with the semi-axes (w, h) centered at the origin O.
|
|
11
|
+
* The vertices are computed in the frame where w and h are positive and flipped at the end.
|
|
12
|
+
*
|
|
13
|
+
* ## Points
|
|
14
|
+
*
|
|
15
|
+
* - O: the apex of the fan, the origin
|
|
16
|
+
* - A, B: the end points of the arc, (-w sin(ea), -h cos(ea)) and (+w sin(ea), -h cos(ea))
|
|
17
|
+
* - C: the point where the area of the fan becomes zero when the fan shrinks, (0, -h / (1 + sin(ca)))
|
|
18
|
+
* - P[k]: the points on the arc, k in [0, 2N] (P[0] = A, P[N] is the top, P[2N] = B)
|
|
19
|
+
* - Q[k]: the points on the medial axis of the fan, which are on the normal of the arc at P[k]
|
|
20
|
+
* and equidistant from the arc and the straight sides (Q[0] = A, Q[N] = C, Q[2N] = B)
|
|
21
|
+
* - R[k]: the points P[k] shifted outward for the anti-aliasing
|
|
22
|
+
* - O': the point O shifted outward for the anti-aliasing
|
|
23
|
+
*
|
|
24
|
+
* ## Stroke sides
|
|
25
|
+
*
|
|
26
|
+
* The clipping of a vertex is 1 on the outline and decreases toward the inside by (the distance from the outline) * fd,
|
|
27
|
+
* where the outline is the arc and/or the straight sides depending on the stroke side.
|
|
28
|
+
*
|
|
29
|
+
* - ALL (and NONE): the stroke is at the arc and the straight sides.
|
|
30
|
+
* The fan is triangulated into the strip P[k], P[k + 1], Q[k + 1], Q[k] and
|
|
31
|
+
* the two polygons O', A', Q[0], ..., Q[N] and O', B', Q[2N], ..., Q[N] at the bottom.
|
|
32
|
+
* - TOP: the stroke is only at the arc.
|
|
33
|
+
* For a circle and a semi-ellipse, Q[k] are the points on the axis, which gives the exact fan with the strip only.
|
|
34
|
+
* For the other ellipses, Q[k] are on the medial axis as ALL, and the two polygons
|
|
35
|
+
* O, Q[0], ..., Q[N] and O, Q[2N], ..., Q[N] are added at the bottom without the stroke and the anti-aliasing.
|
|
36
|
+
* - BOTTOM: the stroke is only at the straight sides.
|
|
37
|
+
* It is the same as a polygon. Two triangle fans from C cover the area between the arc and the segments CA and CB,
|
|
38
|
+
* and two quads O', A', A, C and O', B', B, C cover the rest.
|
|
39
|
+
*/
|
|
40
|
+
var EShapeFanTriangulatedImpl = /** @class */ (function () {
|
|
41
|
+
function EShapeFanTriangulatedImpl(parent) {
|
|
42
|
+
this._id = 0;
|
|
43
|
+
this._parent = parent;
|
|
44
|
+
this._width = 0;
|
|
45
|
+
this._height = 0;
|
|
46
|
+
this._strokeAlign = 0;
|
|
47
|
+
this._strokeWidth = 0;
|
|
48
|
+
this._strokeSideTop = true;
|
|
49
|
+
this._strokeSideBottom = true;
|
|
50
|
+
this._angle = 0;
|
|
51
|
+
this._sizeX = 0;
|
|
52
|
+
this._sizeY = 0;
|
|
53
|
+
this._vertices = [];
|
|
54
|
+
this._nvertices = 0;
|
|
55
|
+
this._distances = [];
|
|
56
|
+
this._lengths = [];
|
|
57
|
+
this._clippings = [];
|
|
58
|
+
this._uvs = [];
|
|
59
|
+
this._indices = [];
|
|
60
|
+
this._nindices = 0;
|
|
61
|
+
this._boundary = [0, 0, 0, 0];
|
|
62
|
+
}
|
|
63
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "id", {
|
|
64
|
+
get: function () {
|
|
65
|
+
this.triangulate();
|
|
66
|
+
return this._id;
|
|
67
|
+
},
|
|
68
|
+
enumerable: false,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "vertices", {
|
|
72
|
+
get: function () {
|
|
73
|
+
this.triangulate();
|
|
74
|
+
return this._vertices;
|
|
75
|
+
},
|
|
76
|
+
enumerable: false,
|
|
77
|
+
configurable: true
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "nvertices", {
|
|
80
|
+
get: function () {
|
|
81
|
+
this.triangulate();
|
|
82
|
+
return this._nvertices;
|
|
83
|
+
},
|
|
84
|
+
enumerable: false,
|
|
85
|
+
configurable: true
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "distances", {
|
|
88
|
+
get: function () {
|
|
89
|
+
this.triangulate();
|
|
90
|
+
return this._distances;
|
|
91
|
+
},
|
|
92
|
+
enumerable: false,
|
|
93
|
+
configurable: true
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "lengths", {
|
|
96
|
+
get: function () {
|
|
97
|
+
this.triangulate();
|
|
98
|
+
return this._lengths;
|
|
99
|
+
},
|
|
100
|
+
enumerable: false,
|
|
101
|
+
configurable: true
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "clippings", {
|
|
104
|
+
get: function () {
|
|
105
|
+
this.triangulate();
|
|
106
|
+
return this._clippings;
|
|
107
|
+
},
|
|
108
|
+
enumerable: false,
|
|
109
|
+
configurable: true
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "uvs", {
|
|
112
|
+
get: function () {
|
|
113
|
+
this.triangulate();
|
|
114
|
+
return this._uvs;
|
|
115
|
+
},
|
|
116
|
+
enumerable: false,
|
|
117
|
+
configurable: true
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "indices", {
|
|
120
|
+
get: function () {
|
|
121
|
+
this.triangulate();
|
|
122
|
+
return this._indices;
|
|
123
|
+
},
|
|
124
|
+
enumerable: false,
|
|
125
|
+
configurable: true
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "nindices", {
|
|
128
|
+
get: function () {
|
|
129
|
+
this.triangulate();
|
|
130
|
+
return this._nindices;
|
|
131
|
+
},
|
|
132
|
+
enumerable: false,
|
|
133
|
+
configurable: true
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(EShapeFanTriangulatedImpl.prototype, "boundary", {
|
|
136
|
+
get: function () {
|
|
137
|
+
this.triangulate();
|
|
138
|
+
return this._boundary;
|
|
139
|
+
},
|
|
140
|
+
enumerable: false,
|
|
141
|
+
configurable: true
|
|
142
|
+
});
|
|
143
|
+
EShapeFanTriangulatedImpl.prototype.triangulate = function () {
|
|
144
|
+
var isNotInitialized = this._id === 0;
|
|
145
|
+
var parent = this._parent;
|
|
146
|
+
var size = parent.size;
|
|
147
|
+
var width = size.x;
|
|
148
|
+
var height = size.y;
|
|
149
|
+
var isRectChanged = this._width !== width || this._height !== height;
|
|
150
|
+
var stroke = parent.stroke;
|
|
151
|
+
var strokeAlign = stroke.align;
|
|
152
|
+
var strokeSideTop = (stroke.side & EShapeStrokeSide.TOP) !== 0;
|
|
153
|
+
var strokeSideBottom = (stroke.side & EShapeStrokeSide.BOTTOM) !== 0;
|
|
154
|
+
var strokeWidth = stroke.enable && (strokeSideTop || strokeSideBottom) ? stroke.width : 0;
|
|
155
|
+
var isStrokeChanged = this._strokeAlign !== strokeAlign || this._strokeWidth !== strokeWidth;
|
|
156
|
+
var isStrokeSideChanged = this._strokeSideTop !== strokeSideTop || this._strokeSideBottom !== strokeSideBottom;
|
|
157
|
+
var angle = parent.angle;
|
|
158
|
+
var isAngleChanged = this._angle !== angle;
|
|
159
|
+
var isSizeChanged = false;
|
|
160
|
+
var sizeX = this._sizeX;
|
|
161
|
+
var sizeY = this._sizeY;
|
|
162
|
+
if (isRectChanged || isStrokeChanged) {
|
|
163
|
+
this._width = width;
|
|
164
|
+
this._height = height;
|
|
165
|
+
this._strokeAlign = strokeAlign;
|
|
166
|
+
this._strokeWidth = strokeWidth;
|
|
167
|
+
var s = strokeAlign * strokeWidth;
|
|
168
|
+
sizeX = width * 0.5 + (0 <= width ? +s : -s);
|
|
169
|
+
sizeY = height * 0.5 + (0 <= height ? +s : -s);
|
|
170
|
+
isSizeChanged = this._sizeX !== sizeX || this._sizeY !== sizeY;
|
|
171
|
+
}
|
|
172
|
+
if (isNotInitialized || isSizeChanged || isStrokeSideChanged || isAngleChanged) {
|
|
173
|
+
this._sizeX = sizeX;
|
|
174
|
+
this._sizeY = sizeY;
|
|
175
|
+
this._strokeSideTop = strokeSideTop;
|
|
176
|
+
this._strokeSideBottom = strokeSideBottom;
|
|
177
|
+
this._angle = angle;
|
|
178
|
+
this.update(sizeX, sizeY, angle, strokeSideTop, strokeSideBottom);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
EShapeFanTriangulatedImpl.prototype.update = function (sx, sy, angle, sst, ssb) {
|
|
182
|
+
// The number of the arc segments is 2n and the number of the points on the arc is m.
|
|
183
|
+
var n = EShapeDefaults.CIRCLE_SEGMENT_COUNT >> 2;
|
|
184
|
+
var m = 2 * n + 1;
|
|
185
|
+
var nv = 2 * m + 2 * (n + 3);
|
|
186
|
+
var ni = 4 * n + 2 * (n + 1);
|
|
187
|
+
this._nvertices = nv;
|
|
188
|
+
this._nindices = ni;
|
|
189
|
+
this._id += 1;
|
|
190
|
+
// The eccentric angle ea of A and B, and the sine and cosine of it
|
|
191
|
+
var ax = Math.abs(sx);
|
|
192
|
+
var ay = Math.abs(sy);
|
|
193
|
+
if (ax <= 0 || ay <= 0) {
|
|
194
|
+
this.updateEmpty(ax, ay, nv, ni);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
var ca = toFanAngleCentric(angle);
|
|
198
|
+
var ea = toFanAngleEccentric(ax, ay, ca);
|
|
199
|
+
var sea = Math.sin(ea);
|
|
200
|
+
var cea = Math.cos(ea);
|
|
201
|
+
var bx = ax * sea;
|
|
202
|
+
var by = ay * cea;
|
|
203
|
+
var bz = bx * bx + by * by;
|
|
204
|
+
if (bx <= 0 || bz <= 0) {
|
|
205
|
+
this.updateEmpty(ax, ay, nv, ni);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// The sine and cosine of the geometric half central angle
|
|
209
|
+
var oa = Math.sqrt(bz);
|
|
210
|
+
var st = bx / oa;
|
|
211
|
+
var ct = by / oa;
|
|
212
|
+
// The factors of the UVs and the signs of the flipping
|
|
213
|
+
var fx = 1 / bx;
|
|
214
|
+
var fy = 1 / ay;
|
|
215
|
+
var gx = Math.sign(sx);
|
|
216
|
+
var gy = Math.sign(sy);
|
|
217
|
+
if (!sst && ssb) {
|
|
218
|
+
this.updateBottom(ax, ay, n, ea, sea, cea, bx, by, st, ct, fx, fy, gx, gy, nv, ni);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.updateArc(ax, ay, n, ea, sea, cea, bx, oa, st, ct, fx, fy, gx, gy, sst, ssb, nv, ni);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Fills the empty fan, which has no vertices to draw.
|
|
226
|
+
*/
|
|
227
|
+
EShapeFanTriangulatedImpl.prototype.updateEmpty = function (w, h, nv, ni) {
|
|
228
|
+
var boundary = this._boundary;
|
|
229
|
+
boundary[0] = -w;
|
|
230
|
+
boundary[1] = -h;
|
|
231
|
+
boundary[2] = +w;
|
|
232
|
+
boundary[3] = +h;
|
|
233
|
+
this.pad(0, 0, nv, ni, 0);
|
|
234
|
+
};
|
|
235
|
+
EShapeFanTriangulatedImpl.prototype.updateArc = function (w, h, n, ea, sea, cea, bx, oa, st, ct, fx, fy, gx, gy, sst, ssb, nv, ni) {
|
|
236
|
+
var m = 2 * n + 1;
|
|
237
|
+
// sided: the straight sides are the outline, which has the stroke and the anti-aliasing
|
|
238
|
+
// capped: the polygons are added at the bottom to cover the sector with the hard straight sides
|
|
239
|
+
// chained: Q is on the medial axis. Otherwise, Q is on the axis x = 0 (w <= h) or y = 0 (h < w)
|
|
240
|
+
// For a circle and a semi-ellipse, Q on the axis gives the exact fan.
|
|
241
|
+
var sided = !sst || ssb;
|
|
242
|
+
var isExact = Math.abs(w - h) <= 1e-9 * w || Math.PI * 0.5 <= ea;
|
|
243
|
+
var capped = !sided && !isExact;
|
|
244
|
+
var chained = sided || capped;
|
|
245
|
+
this.computeArcPoints(w, h, n, ea, sea, cea);
|
|
246
|
+
this.computeArcNormals(w, h, n, ea);
|
|
247
|
+
var dmax = this.computeMedialPoints(w, h, n, st, ct, chained);
|
|
248
|
+
if (capped) {
|
|
249
|
+
// The distance field of the arc must cover O, which is the farthest point from the arc,
|
|
250
|
+
// because the clipping in the polygons at the bottom is interpolated from the arc to O.
|
|
251
|
+
dmax = Math.max(dmax, h <= w ? h : oa);
|
|
252
|
+
}
|
|
253
|
+
if (dmax <= 0) {
|
|
254
|
+
this.updateEmpty(w, h, nv, ni);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
var boundary = this._boundary;
|
|
258
|
+
boundary[0] = -bx;
|
|
259
|
+
boundary[1] = -h;
|
|
260
|
+
boundary[2] = +bx;
|
|
261
|
+
boundary[3] = 0;
|
|
262
|
+
var fd = 1 / dmax;
|
|
263
|
+
var fs = (EShapeFanTriangulatedImpl.SCALE - 1) * dmax;
|
|
264
|
+
this.computeRimPoints(w, h, n, fs, st, ct, sea, cea, sided);
|
|
265
|
+
// Strip: 2m vertices and 2 * 3 * (m - 1) indices
|
|
266
|
+
this.writeStrip(m, fd, fx, fy, gx, gy);
|
|
267
|
+
var iv = 2 * m;
|
|
268
|
+
var ii = 6 * (m - 1);
|
|
269
|
+
// Polygons at the bottom: left (sign = -1) and right (sign = +1)
|
|
270
|
+
if (sided) {
|
|
271
|
+
for (var sign = -1; sign <= 1; sign += 2) {
|
|
272
|
+
var count = this.writeSidePolygon(iv, ii, sign, n, w, oa, st, ct, fs, fd, fx, fy, gx, gy);
|
|
273
|
+
iv += count;
|
|
274
|
+
ii += 3 * (count - 2);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
else if (capped) {
|
|
278
|
+
var co = Math.max(0, 1 - (w >= h ? h : oa) * fd);
|
|
279
|
+
for (var sign = -1; sign <= 1; sign += 2) {
|
|
280
|
+
var count = this.writeCapPolygon(iv, ii, sign, n, w, co, fd, fx, fy, gx, gy);
|
|
281
|
+
iv += count;
|
|
282
|
+
ii += 3 * (count - 2);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
this.pad(iv, ii, nv, ni, fd);
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Computes P[k], the points on the arc, in the work arrays.
|
|
289
|
+
*
|
|
290
|
+
* The sine and cosine of the angle are updated by the rotation to avoid calling Math.sin and Math.cos in the loop.
|
|
291
|
+
* The points are symmetric with respect to the axis x = 0, so only the left half is computed
|
|
292
|
+
* and the right half is mirrored from it.
|
|
293
|
+
*/
|
|
294
|
+
EShapeFanTriangulatedImpl.prototype.computeArcPoints = function (w, h, n, ea, sea, cea) {
|
|
295
|
+
var m = 2 * n + 1;
|
|
296
|
+
var px = EShapeFanTriangulatedImpl.WORK_ARC_X;
|
|
297
|
+
var py = EShapeFanTriangulatedImpl.WORK_ARC_Y;
|
|
298
|
+
var da = ea / n;
|
|
299
|
+
var cda = Math.cos(da);
|
|
300
|
+
var sda = Math.sin(da);
|
|
301
|
+
var s = -sea;
|
|
302
|
+
var c = cea;
|
|
303
|
+
for (var k = 0; k <= n; ++k) {
|
|
304
|
+
// Use the exact values at the center to prevent the accumulation of the errors.
|
|
305
|
+
if (k === n) {
|
|
306
|
+
s = 0;
|
|
307
|
+
c = 1;
|
|
308
|
+
}
|
|
309
|
+
px[k] = w * s;
|
|
310
|
+
py[k] = -h * c;
|
|
311
|
+
// Rotate by da
|
|
312
|
+
var ns = s * cda + c * sda;
|
|
313
|
+
c = c * cda - s * sda;
|
|
314
|
+
s = ns;
|
|
315
|
+
}
|
|
316
|
+
for (var k = 0; k < n; ++k) {
|
|
317
|
+
px[m - 1 - k] = -px[k];
|
|
318
|
+
py[m - 1 - k] = py[k];
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Computes the unit inward normals of the arc, the speeds of the arc, and the arc lengths at P[k].
|
|
323
|
+
*
|
|
324
|
+
* The normal at P is Np = (-h x / w, -w y / h), whose magnitude is the speed of the arc.
|
|
325
|
+
* The speed is used to approximate the arc length without extra square roots.
|
|
326
|
+
*/
|
|
327
|
+
EShapeFanTriangulatedImpl.prototype.computeArcNormals = function (w, h, n, ea) {
|
|
328
|
+
var m = 2 * n + 1;
|
|
329
|
+
var px = EShapeFanTriangulatedImpl.WORK_ARC_X;
|
|
330
|
+
var py = EShapeFanTriangulatedImpl.WORK_ARC_Y;
|
|
331
|
+
var nx = EShapeFanTriangulatedImpl.WORK_NORMAL_X;
|
|
332
|
+
var ny = EShapeFanTriangulatedImpl.WORK_NORMAL_Y;
|
|
333
|
+
var speeds = EShapeFanTriangulatedImpl.WORK_SPEED;
|
|
334
|
+
var ls = EShapeFanTriangulatedImpl.WORK_ARC_L;
|
|
335
|
+
var da = ea / n;
|
|
336
|
+
var hw = h / w;
|
|
337
|
+
var wh = w / h;
|
|
338
|
+
var l = 0;
|
|
339
|
+
var previous = 0;
|
|
340
|
+
for (var k = 0; k <= n; ++k) {
|
|
341
|
+
var dx = -hw * px[k];
|
|
342
|
+
var dy = -wh * py[k];
|
|
343
|
+
var speed = Math.sqrt(dx * dx + dy * dy);
|
|
344
|
+
nx[k] = dx / speed;
|
|
345
|
+
ny[k] = dy / speed;
|
|
346
|
+
speeds[k] = speed;
|
|
347
|
+
if (0 < k) {
|
|
348
|
+
l += 0.5 * da * (previous + speed);
|
|
349
|
+
}
|
|
350
|
+
previous = speed;
|
|
351
|
+
ls[k] = l;
|
|
352
|
+
}
|
|
353
|
+
for (var k = 0; k < n; ++k) {
|
|
354
|
+
var j = m - 1 - k;
|
|
355
|
+
nx[j] = -nx[k];
|
|
356
|
+
ny[j] = ny[k];
|
|
357
|
+
speeds[j] = speeds[k];
|
|
358
|
+
ls[j] = 2 * ls[n] - ls[k];
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Computes Q[k], the points on the normals, and their distances from P[k], and returns the maximum distance.
|
|
363
|
+
*
|
|
364
|
+
* If chained is true, Q is the point on the medial axis, that is, the point on the normal
|
|
365
|
+
* whose distance to the arc is equal to the distance to the straight sides.
|
|
366
|
+
* The distance delta is obtained from delta = -(n . P) - delta (n . normal) for the outward unit normals n of the sides.
|
|
367
|
+
* The clamps keep Q on the same side of the axis x = 0 as P and before the center of curvature,
|
|
368
|
+
* otherwise adjacent normals cross each other, which happens for tall ellipses.
|
|
369
|
+
*
|
|
370
|
+
* Otherwise, the normal is extended until it reaches x = 0 if w <= h, otherwise y = 0.
|
|
371
|
+
*/
|
|
372
|
+
EShapeFanTriangulatedImpl.prototype.computeMedialPoints = function (w, h, n, st, ct, chained) {
|
|
373
|
+
var m = 2 * n + 1;
|
|
374
|
+
var px = EShapeFanTriangulatedImpl.WORK_ARC_X;
|
|
375
|
+
var py = EShapeFanTriangulatedImpl.WORK_ARC_Y;
|
|
376
|
+
var nx = EShapeFanTriangulatedImpl.WORK_NORMAL_X;
|
|
377
|
+
var ny = EShapeFanTriangulatedImpl.WORK_NORMAL_Y;
|
|
378
|
+
var speeds = EShapeFanTriangulatedImpl.WORK_SPEED;
|
|
379
|
+
var qx = EShapeFanTriangulatedImpl.WORK_MEDIAL_X;
|
|
380
|
+
var qy = EShapeFanTriangulatedImpl.WORK_MEDIAL_Y;
|
|
381
|
+
var qd = EShapeFanTriangulatedImpl.WORK_MEDIAL_D;
|
|
382
|
+
var u = w <= h ? w / h : h / w;
|
|
383
|
+
var dmax = 0;
|
|
384
|
+
for (var k = 0; k <= n; ++k) {
|
|
385
|
+
var x = px[k];
|
|
386
|
+
var y = py[k];
|
|
387
|
+
var nnx = nx[k];
|
|
388
|
+
var nny = ny[k];
|
|
389
|
+
var speed = speeds[k];
|
|
390
|
+
var delta = Infinity;
|
|
391
|
+
if (chained) {
|
|
392
|
+
var da = 1 + -ct * nnx + st * nny;
|
|
393
|
+
if (1e-9 < da) {
|
|
394
|
+
delta = Math.min(delta, (ct * x - st * y) / da);
|
|
395
|
+
}
|
|
396
|
+
var db = 1 + ct * nnx + st * nny;
|
|
397
|
+
if (1e-9 < db) {
|
|
398
|
+
delta = Math.min(delta, (-ct * x - st * y) / db);
|
|
399
|
+
}
|
|
400
|
+
if (k !== n && 1e-12 < Math.abs(nnx)) {
|
|
401
|
+
delta = Math.min(delta, -x / nnx);
|
|
402
|
+
}
|
|
403
|
+
delta = Math.max(0, Math.min(delta, (speed * speed * speed) / (w * h)));
|
|
404
|
+
}
|
|
405
|
+
// The distance between P and Q
|
|
406
|
+
var d = void 0;
|
|
407
|
+
if (Number.isFinite(delta)) {
|
|
408
|
+
d = delta;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
d = u * speed;
|
|
412
|
+
}
|
|
413
|
+
qx[k] = x + d * nnx;
|
|
414
|
+
qy[k] = y + d * nny;
|
|
415
|
+
qd[k] = d;
|
|
416
|
+
dmax = Math.max(dmax, d);
|
|
417
|
+
}
|
|
418
|
+
for (var k = 0; k < n; ++k) {
|
|
419
|
+
var j = m - 1 - k;
|
|
420
|
+
qx[j] = -qx[k];
|
|
421
|
+
qy[j] = qy[k];
|
|
422
|
+
qd[j] = qd[k];
|
|
423
|
+
}
|
|
424
|
+
return dmax;
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Computes R[k], the points on the arc shifted outward by fs, and their lengths.
|
|
428
|
+
* If the straight sides are the outline, the end points are shifted
|
|
429
|
+
* to the intersections of the shifted arc and the shifted straight sides.
|
|
430
|
+
*/
|
|
431
|
+
EShapeFanTriangulatedImpl.prototype.computeRimPoints = function (w, h, n, fs, st, ct, sea, cea, sided) {
|
|
432
|
+
var m = 2 * n + 1;
|
|
433
|
+
var px = EShapeFanTriangulatedImpl.WORK_ARC_X;
|
|
434
|
+
var py = EShapeFanTriangulatedImpl.WORK_ARC_Y;
|
|
435
|
+
var nx = EShapeFanTriangulatedImpl.WORK_NORMAL_X;
|
|
436
|
+
var ny = EShapeFanTriangulatedImpl.WORK_NORMAL_Y;
|
|
437
|
+
var ls = EShapeFanTriangulatedImpl.WORK_ARC_L;
|
|
438
|
+
var rx = EShapeFanTriangulatedImpl.WORK_RIM_X;
|
|
439
|
+
var ry = EShapeFanTriangulatedImpl.WORK_RIM_Y;
|
|
440
|
+
var rl = EShapeFanTriangulatedImpl.WORK_RIM_L;
|
|
441
|
+
for (var k = 0; k < m; ++k) {
|
|
442
|
+
var x = px[k] - fs * nx[k];
|
|
443
|
+
var y = py[k] - fs * ny[k];
|
|
444
|
+
var l = ls[k];
|
|
445
|
+
if (sided && (k === 0 || k === m - 1)) {
|
|
446
|
+
var sign = k === 0 ? -1 : +1;
|
|
447
|
+
// The miter of the outward normal of the arc (n1) and that of the straight side (n2)
|
|
448
|
+
var n1x = -nx[k];
|
|
449
|
+
var n1y = -ny[k];
|
|
450
|
+
var n2x = sign * ct;
|
|
451
|
+
var n2y = st;
|
|
452
|
+
var miter = fs / Math.max(1 + n1x * n2x + n1y * n2y, 0.05);
|
|
453
|
+
x = px[k] + miter * (n1x + n2x);
|
|
454
|
+
y = py[k] + miter * (n1y + n2y);
|
|
455
|
+
// The length is shifted along the tangent (tx, ty) / speed
|
|
456
|
+
var tx = w * cea;
|
|
457
|
+
var ty = sign * h * sea;
|
|
458
|
+
l +=
|
|
459
|
+
((x - px[k]) * tx + (y - py[k]) * ty) / EShapeFanTriangulatedImpl.WORK_SPEED[0];
|
|
460
|
+
}
|
|
461
|
+
rx[k] = x;
|
|
462
|
+
ry[k] = y;
|
|
463
|
+
rl[k] = l;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Writes the strip P[k], P[k + 1], Q[k + 1], Q[k] with the vertices R[k] and Q[k].
|
|
468
|
+
*/
|
|
469
|
+
EShapeFanTriangulatedImpl.prototype.writeStrip = function (m, fd, fx, fy, gx, gy) {
|
|
470
|
+
var qx = EShapeFanTriangulatedImpl.WORK_MEDIAL_X;
|
|
471
|
+
var qy = EShapeFanTriangulatedImpl.WORK_MEDIAL_Y;
|
|
472
|
+
var qd = EShapeFanTriangulatedImpl.WORK_MEDIAL_D;
|
|
473
|
+
var ls = EShapeFanTriangulatedImpl.WORK_ARC_L;
|
|
474
|
+
var rx = EShapeFanTriangulatedImpl.WORK_RIM_X;
|
|
475
|
+
var ry = EShapeFanTriangulatedImpl.WORK_RIM_Y;
|
|
476
|
+
var rl = EShapeFanTriangulatedImpl.WORK_RIM_L;
|
|
477
|
+
var scale = EShapeFanTriangulatedImpl.SCALE;
|
|
478
|
+
var indices = this._indices;
|
|
479
|
+
var iv = 0;
|
|
480
|
+
var ii = 0;
|
|
481
|
+
for (var k = 0; k < m; ++k) {
|
|
482
|
+
this.writeVertex(iv++, rx[k], ry[k], rl[k], scale, fd, fx, fy, gx, gy);
|
|
483
|
+
this.writeVertex(iv++, qx[k], qy[k], ls[k], 1 - qd[k] * fd, fd, fx, fy, gx, gy);
|
|
484
|
+
if (k < m - 1) {
|
|
485
|
+
var a = 2 * k;
|
|
486
|
+
indices[ii++] = a;
|
|
487
|
+
indices[ii++] = a + 2;
|
|
488
|
+
indices[ii++] = a + 3;
|
|
489
|
+
indices[ii++] = a;
|
|
490
|
+
indices[ii++] = a + 3;
|
|
491
|
+
indices[ii++] = a + 1;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
/**
|
|
496
|
+
* Writes the polygon O', R[end], Q[end], ..., Q[N] where the end is 0 for the left (sign = -1)
|
|
497
|
+
* and 2N for the right (sign = +1). The straight side OA (or OB) is the outline of the polygon.
|
|
498
|
+
* Returns the number of the written vertices.
|
|
499
|
+
*
|
|
500
|
+
* The chain of Q ends at the first point on the axis because the following points go back along the axis.
|
|
501
|
+
* Q is not always on the medial axis where it is clamped,
|
|
502
|
+
* so the clipping must not be less than the one of the arc.
|
|
503
|
+
*
|
|
504
|
+
* The clipping and the length are computed from the straight side:
|
|
505
|
+
* the outward unit normal is (sign * ct, st) and the length is oa + arc + (-st, sign * ct) . p.
|
|
506
|
+
*/
|
|
507
|
+
EShapeFanTriangulatedImpl.prototype.writeSidePolygon = function (iv, ii, sign, n, w, oa, st, ct, fs, fd, fx, fy, gx, gy) {
|
|
508
|
+
var m = 2 * n + 1;
|
|
509
|
+
var qx = EShapeFanTriangulatedImpl.WORK_MEDIAL_X;
|
|
510
|
+
var qy = EShapeFanTriangulatedImpl.WORK_MEDIAL_Y;
|
|
511
|
+
var qd = EShapeFanTriangulatedImpl.WORK_MEDIAL_D;
|
|
512
|
+
var rx = EShapeFanTriangulatedImpl.WORK_RIM_X;
|
|
513
|
+
var ry = EShapeFanTriangulatedImpl.WORK_RIM_Y;
|
|
514
|
+
var l0 = oa + EShapeFanTriangulatedImpl.WORK_ARC_L[m - 1];
|
|
515
|
+
var nx = sign * ct;
|
|
516
|
+
var ly = sign * ct;
|
|
517
|
+
var eps = 1e-9 * w;
|
|
518
|
+
var end = sign < 0 ? 0 : m - 1;
|
|
519
|
+
var count = 0;
|
|
520
|
+
this.writeSideVertex(iv + count++, 0, fs / st, -Infinity, nx, st, l0, -st, ly, fd, fx, fy, gx, gy);
|
|
521
|
+
this.writeSideVertex(iv + count++, rx[end], ry[end], -Infinity, nx, st, l0, -st, ly, fd, fx, fy, gx, gy);
|
|
522
|
+
for (var j = 0; j <= n; ++j) {
|
|
523
|
+
var k = sign < 0 ? j : m - 1 - j;
|
|
524
|
+
var floor = 1 - qd[k] * fd;
|
|
525
|
+
this.writeSideVertex(iv + count++, qx[k], qy[k], floor, nx, st, l0, -st, ly, fd, fx, fy, gx, gy);
|
|
526
|
+
if (Math.abs(qx[k]) <= eps) {
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
this.writeFan(ii, iv, count);
|
|
531
|
+
return count;
|
|
532
|
+
};
|
|
533
|
+
/**
|
|
534
|
+
* Writes the polygon O, Q[end], ..., Q[N] where the end is 0 for the left (sign = -1)
|
|
535
|
+
* and 2N for the right (sign = +1). The straight sides are hard edges without the stroke.
|
|
536
|
+
* Returns the number of the written vertices.
|
|
537
|
+
*
|
|
538
|
+
* The clipping of O is given by co, and the length of O is the one of the end point.
|
|
539
|
+
*/
|
|
540
|
+
EShapeFanTriangulatedImpl.prototype.writeCapPolygon = function (iv, ii, sign, n, w, co, fd, fx, fy, gx, gy) {
|
|
541
|
+
var m = 2 * n + 1;
|
|
542
|
+
var qx = EShapeFanTriangulatedImpl.WORK_MEDIAL_X;
|
|
543
|
+
var qy = EShapeFanTriangulatedImpl.WORK_MEDIAL_Y;
|
|
544
|
+
var qd = EShapeFanTriangulatedImpl.WORK_MEDIAL_D;
|
|
545
|
+
var ls = EShapeFanTriangulatedImpl.WORK_ARC_L;
|
|
546
|
+
var eps = 1e-9 * w;
|
|
547
|
+
var end = sign < 0 ? 0 : m - 1;
|
|
548
|
+
this.writeVertex(iv, 0, 0, ls[end], co, fd, fx, fy, gx, gy);
|
|
549
|
+
var count = 1;
|
|
550
|
+
for (var j = 0; j <= n; ++j) {
|
|
551
|
+
var k = sign < 0 ? j : m - 1 - j;
|
|
552
|
+
var clipping = 1 - qd[k] * fd;
|
|
553
|
+
this.writeVertex(iv + count++, qx[k], qy[k], ls[k], clipping, fd, fx, fy, gx, gy);
|
|
554
|
+
if (Math.abs(qx[k]) <= eps) {
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
this.writeFan(ii, iv, count);
|
|
559
|
+
return count;
|
|
560
|
+
};
|
|
561
|
+
/**
|
|
562
|
+
* The clipping is 1 - (the distance from the straight side) / d where d is the distance from C to OA (or OB).
|
|
563
|
+
*/
|
|
564
|
+
EShapeFanTriangulatedImpl.prototype.updateBottom = function (w, h, n, ea, sea, cea, bx, by, st, ct, fx, fy, gx, gy, nv, ni) {
|
|
565
|
+
var boundary = this._boundary;
|
|
566
|
+
boundary[0] = -bx;
|
|
567
|
+
boundary[1] = -h;
|
|
568
|
+
boundary[2] = +bx;
|
|
569
|
+
boundary[3] = 0;
|
|
570
|
+
var yc = h / (1 + st);
|
|
571
|
+
var fd = (1 + st) / (h * st);
|
|
572
|
+
var fs = (EShapeFanTriangulatedImpl.SCALE - 1) / fd;
|
|
573
|
+
this.computeArcPoints(w, h, n, ea, sea, cea);
|
|
574
|
+
// Triangle fans from C to the arc: left (sign = -1) and right (sign = +1)
|
|
575
|
+
var iv = 0;
|
|
576
|
+
var ii = 0;
|
|
577
|
+
for (var sign = -1; sign <= 1; sign += 2) {
|
|
578
|
+
var count = this.writeBottomFan(iv, ii, sign, n, yc, st, ct, fd, fx, fy, gx, gy);
|
|
579
|
+
iv += count;
|
|
580
|
+
ii += 3 * (count - 2);
|
|
581
|
+
}
|
|
582
|
+
// Quads at the bottom: O', A', A, C and O', B', B, C
|
|
583
|
+
for (var sign = -1; sign <= 1; sign += 2) {
|
|
584
|
+
var count = this.writeBottomQuad(iv, ii, sign, bx, by, yc, fs, st, ct, fd, fx, fy, gx, gy);
|
|
585
|
+
iv += count;
|
|
586
|
+
ii += 3 * (count - 2);
|
|
587
|
+
}
|
|
588
|
+
this.pad(iv, ii, nv, ni, fd);
|
|
589
|
+
};
|
|
590
|
+
/**
|
|
591
|
+
* Writes the triangle fan from C to the arc of the left half (sign = -1) or the right half (sign = +1).
|
|
592
|
+
* Returns the number of the written vertices.
|
|
593
|
+
*
|
|
594
|
+
* The clipping is 1 + fd * (n . p) where n is the outward unit normal of the straight side,
|
|
595
|
+
* and the length is the distance along the straight side measured from O.
|
|
596
|
+
* The side OA has n = (-ct, st) and l = (-st, -ct), and the side OB has n = (ct, st) and l = (st, -ct).
|
|
597
|
+
*/
|
|
598
|
+
EShapeFanTriangulatedImpl.prototype.writeBottomFan = function (iv, ii, sign, n, yc, st, ct, fd, fx, fy, gx, gy) {
|
|
599
|
+
var px = EShapeFanTriangulatedImpl.WORK_ARC_X;
|
|
600
|
+
var py = EShapeFanTriangulatedImpl.WORK_ARC_Y;
|
|
601
|
+
var nx = sign * ct;
|
|
602
|
+
var lx = sign * st;
|
|
603
|
+
var count = 0;
|
|
604
|
+
this.writeSideVertex(iv + count++, 0, -yc, 0, nx, st, 0, lx, -ct, fd, fx, fy, gx, gy);
|
|
605
|
+
for (var j = 0; j <= n; ++j) {
|
|
606
|
+
var k = sign < 0 ? j : n + j;
|
|
607
|
+
this.writeSideVertex(iv + count++, px[k], py[k], 0, nx, st, 0, lx, -ct, fd, fx, fy, gx, gy);
|
|
608
|
+
}
|
|
609
|
+
this.writeFan(ii, iv, count);
|
|
610
|
+
return count;
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* Writes the quad O', A', A, C (sign = -1) or O', B', B, C (sign = +1) at the bottom.
|
|
614
|
+
* O' is shifted outward by fs / st, and A' (B') is shifted outward by fs perpendicular to the straight side.
|
|
615
|
+
* Returns the number of the written vertices.
|
|
616
|
+
*/
|
|
617
|
+
EShapeFanTriangulatedImpl.prototype.writeBottomQuad = function (iv, ii, sign, bx, by, yc, fs, st, ct, fd, fx, fy, gx, gy) {
|
|
618
|
+
var nx = sign * ct;
|
|
619
|
+
var lx = sign * st;
|
|
620
|
+
this.writeSideVertex(iv, 0, fs / st, 0, nx, st, 0, lx, -ct, fd, fx, fy, gx, gy);
|
|
621
|
+
this.writeSideVertex(iv + 1, sign * (bx + fs * ct), -by + fs * st, 0, nx, st, 0, lx, -ct, fd, fx, fy, gx, gy);
|
|
622
|
+
this.writeSideVertex(iv + 2, sign * bx, -by, 0, nx, st, 0, lx, -ct, fd, fx, fy, gx, gy);
|
|
623
|
+
this.writeSideVertex(iv + 3, 0, -yc, 0, nx, st, 0, lx, -ct, fd, fx, fy, gx, gy);
|
|
624
|
+
this.writeFan(ii, iv, 4);
|
|
625
|
+
return 4;
|
|
626
|
+
};
|
|
627
|
+
// ----------------------------------------------------------------------------------------
|
|
628
|
+
// Writers
|
|
629
|
+
// ----------------------------------------------------------------------------------------
|
|
630
|
+
/**
|
|
631
|
+
* Writes a vertex whose clipping and length are computed from the parameters of a straight side.
|
|
632
|
+
* The clipping is 1 + fd * (nx * x + ny * y), which is not less than the given floor,
|
|
633
|
+
* and the length is l0 + lx * x + ly * y.
|
|
634
|
+
*/
|
|
635
|
+
EShapeFanTriangulatedImpl.prototype.writeSideVertex = function (vertex, x, y, floor, nx, ny, l0, lx, ly, fd, fx, fy, gx, gy) {
|
|
636
|
+
var clipping = Math.max(floor, 1 + fd * (nx * x + ny * y));
|
|
637
|
+
var length = l0 + lx * x + ly * y;
|
|
638
|
+
this.writeVertex(vertex, x, y, length, clipping, fd, fx, fy, gx, gy);
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Writes the indices of a triangle fan from the first vertex.
|
|
642
|
+
* The number of the written indices is 3 * (count - 2).
|
|
643
|
+
*/
|
|
644
|
+
EShapeFanTriangulatedImpl.prototype.writeFan = function (ii, iv, count) {
|
|
645
|
+
var indices = this._indices;
|
|
646
|
+
for (var i = 1; i < count - 1; ++i) {
|
|
647
|
+
indices[ii++] = iv;
|
|
648
|
+
indices[ii++] = iv + i;
|
|
649
|
+
indices[ii++] = iv + i + 1;
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
/**
|
|
653
|
+
* Writes a vertex.
|
|
654
|
+
*
|
|
655
|
+
* @param x - The X coordinate in the frame where the sizes are positive
|
|
656
|
+
* @param y - The Y coordinate in the frame where the sizes are positive
|
|
657
|
+
* @param fd - The inverse of the distance where the clipping decreases from 1 to 0
|
|
658
|
+
* @param fx - The factor to convert x to the UV
|
|
659
|
+
* @param fy - The factor to convert y to the UV
|
|
660
|
+
* @param gx - The sign of the X size, which flips the vertex
|
|
661
|
+
* @param gy - The sign of the Y size, which flips the vertex
|
|
662
|
+
*/
|
|
663
|
+
EShapeFanTriangulatedImpl.prototype.writeVertex = function (vertex, x, y, length, clipping, fd, fx, fy, gx, gy) {
|
|
664
|
+
var vertex2 = vertex << 1;
|
|
665
|
+
this._vertices[vertex2] = gx * x;
|
|
666
|
+
this._vertices[vertex2 + 1] = gy * y;
|
|
667
|
+
this._distances[vertex] = fd;
|
|
668
|
+
this._lengths[vertex] = length;
|
|
669
|
+
this._clippings[vertex] = clipping;
|
|
670
|
+
this._uvs[vertex2] = 0.5 * (x * fx + 1);
|
|
671
|
+
this._uvs[vertex2 + 1] = 1 + y * fy;
|
|
672
|
+
};
|
|
673
|
+
/**
|
|
674
|
+
* Fills the unused tail with degenerated triangles and trims the arrays
|
|
675
|
+
* so that the buffers always hold exactly `nv` vertices and `ni` triangles.
|
|
676
|
+
*/
|
|
677
|
+
EShapeFanTriangulatedImpl.prototype.pad = function (iv, ii, nv, ni, distance) {
|
|
678
|
+
for (var i = iv; i < nv; ++i) {
|
|
679
|
+
var vertex2 = i << 1;
|
|
680
|
+
this._vertices[vertex2] = 0;
|
|
681
|
+
this._vertices[vertex2 + 1] = 0;
|
|
682
|
+
this._distances[i] = distance;
|
|
683
|
+
this._lengths[i] = 0;
|
|
684
|
+
this._clippings[i] = 0;
|
|
685
|
+
this._uvs[vertex2] = 0.5;
|
|
686
|
+
this._uvs[vertex2 + 1] = 0.5;
|
|
687
|
+
}
|
|
688
|
+
for (var i = ii; i < ni * 3; ++i) {
|
|
689
|
+
this._indices[i] = 0;
|
|
690
|
+
}
|
|
691
|
+
this._vertices.length = nv * 2;
|
|
692
|
+
this._distances.length = nv;
|
|
693
|
+
this._lengths.length = nv;
|
|
694
|
+
this._clippings.length = nv;
|
|
695
|
+
this._uvs.length = nv * 2;
|
|
696
|
+
this._indices.length = ni * 3;
|
|
697
|
+
};
|
|
698
|
+
/** The ratio of the outer edge, where the clipping is 1, to the edge of the anti-aliasing */
|
|
699
|
+
EShapeFanTriangulatedImpl.SCALE = 1.1;
|
|
700
|
+
// Work arrays shared by all the instances because they are used only in a single synchronous triangulation.
|
|
701
|
+
// All of them are indexed by k, which is in [0, 2N].
|
|
702
|
+
/** P: the points on the arc */
|
|
703
|
+
EShapeFanTriangulatedImpl.WORK_ARC_X = [];
|
|
704
|
+
EShapeFanTriangulatedImpl.WORK_ARC_Y = [];
|
|
705
|
+
/** The arc lengths measured from P[0] */
|
|
706
|
+
EShapeFanTriangulatedImpl.WORK_ARC_L = [];
|
|
707
|
+
/** The unit inward normals of the arc */
|
|
708
|
+
EShapeFanTriangulatedImpl.WORK_NORMAL_X = [];
|
|
709
|
+
EShapeFanTriangulatedImpl.WORK_NORMAL_Y = [];
|
|
710
|
+
/** The magnitudes of the tangents, that is, the speeds of the arc */
|
|
711
|
+
EShapeFanTriangulatedImpl.WORK_SPEED = [];
|
|
712
|
+
/** Q: the points on the normals */
|
|
713
|
+
EShapeFanTriangulatedImpl.WORK_MEDIAL_X = [];
|
|
714
|
+
EShapeFanTriangulatedImpl.WORK_MEDIAL_Y = [];
|
|
715
|
+
/** The distances from P to Q */
|
|
716
|
+
EShapeFanTriangulatedImpl.WORK_MEDIAL_D = [];
|
|
717
|
+
/** R: the points on the arc shifted outward, and their lengths */
|
|
718
|
+
EShapeFanTriangulatedImpl.WORK_RIM_X = [];
|
|
719
|
+
EShapeFanTriangulatedImpl.WORK_RIM_Y = [];
|
|
720
|
+
EShapeFanTriangulatedImpl.WORK_RIM_L = [];
|
|
721
|
+
return EShapeFanTriangulatedImpl;
|
|
722
|
+
}());
|
|
723
|
+
export { EShapeFanTriangulatedImpl };
|
|
724
|
+
//# sourceMappingURL=e-shape-fan-triangulated-impl.js.map
|