Skip to content

Commit

Permalink
merge branch v3.8.0-aot (cocos#15421)
Browse files Browse the repository at this point in the history
* PR1: add explicit function return type (cocos#15311)

* PR4: add explicit function return type (cocos#15314)

* [ci skip][AUTO]: Automated code generating update: 8843bfe  (cocos#15314) (cocos#15357)

Co-authored-by: cocos-robot <[email protected]>

* add function return type

* fix version checking

* fix return type

---------

Co-authored-by: Cocos Robot <[email protected]>
Co-authored-by: cocos-robot <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2023
1 parent aedc32a commit 509d73b
Show file tree
Hide file tree
Showing 855 changed files with 10,398 additions and 10,220 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ rules:
# TODO: this is just too much work
'@typescript-eslint/explicit-module-boundary-types': off

# NOTE: We don't want to rely on TS automatic type inference
'@typescript-eslint/no-inferrable-types': off

# TODO: sadly we still rely heavily on legacyCC
'@typescript-eslint/no-unsafe-assignment': off
'@typescript-eslint/no-unsafe-call': off
Expand Down Expand Up @@ -143,3 +146,4 @@ rules:

# Prefer the interface style.
'@typescript-eslint/consistent-type-definitions': [error, interface]
'@typescript-eslint/explicit-function-return-type': [error]
8 changes: 4 additions & 4 deletions cocos/2d/assembler/graphics/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const sign = Math.sign;

const KAPPA90 = 0.5522847493;

export function arc (ctx: Impl, cx: number, cy: number, r: number, startAngle: number, endAngle: number, counterclockwise: boolean) {
export function arc (ctx: Impl, cx: number, cy: number, r: number, startAngle: number, endAngle: number, counterclockwise: boolean): void {
counterclockwise = counterclockwise || false;

let a = 0;
Expand Down Expand Up @@ -97,7 +97,7 @@ export function arc (ctx: Impl, cx: number, cy: number, r: number, startAngle: n
}
}

export function ellipse (ctx: Impl, cx: number, cy: number, rx: number, ry: number) {
export function ellipse (ctx: Impl, cx: number, cy: number, rx: number, ry: number): void {
ctx.moveTo(cx - rx, cy);
ctx.bezierCurveTo(cx - rx, cy + ry * KAPPA90, cx - rx * KAPPA90, cy + ry, cx, cy + ry);
ctx.bezierCurveTo(cx + rx * KAPPA90, cy + ry, cx + rx, cy + ry * KAPPA90, cx + rx, cy);
Expand All @@ -106,7 +106,7 @@ export function ellipse (ctx: Impl, cx: number, cy: number, rx: number, ry: numb
ctx.close();
}

export function roundRect (ctx: Impl, x: number, y: number, w: number, h: number, r: number) {
export function roundRect (ctx: Impl, x: number, y: number, w: number, h: number, r: number): void {
if (r < 0.1) {
ctx.rect(x, y, w, h);
} else {
Expand All @@ -132,7 +132,7 @@ export function tesselateBezier (
x3: number, y3: number,
x4: number, y4: number,
level: number, type: number,
) {
): void {
let x12 = 0;
let y12 = 0;
let x23 = 0;
Expand Down
56 changes: 28 additions & 28 deletions cocos/2d/assembler/graphics/webgl/earcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Aim {
}

// create a circular doubly linked list from polygon points in the specified winding order
function linkedList (datas: number[], start: number, end: number, dim: number, clockwise: boolean) {
function linkedList (datas: number[], start: number, end: number, dim: number, clockwise: boolean): Aim | null {
let i = 0;
let last: Aim | null = null;

Expand All @@ -75,7 +75,7 @@ function linkedList (datas: number[], start: number, end: number, dim: number, c
}

// eliminate colinear or duplicate points
function filterPoints (start: Aim | null, end: Aim | null = null) {
function filterPoints (start: Aim | null, end: Aim | null = null): Aim | null {
if (!start) {
return start;
}
Expand Down Expand Up @@ -105,7 +105,7 @@ function filterPoints (start: Aim | null, end: Aim | null = null) {
}

// main ear slicing loop which triangulates a polygon (given as a linked list)
function earcutLinked (ear: Aim | null, triangles: number[], dim: number, minX: number, minY: number, size: number, pass = 0) {
function earcutLinked (ear: Aim | null, triangles: number[], dim: number, minX: number, minY: number, size: number, pass = 0): void {
if (!ear) {
return;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ function earcutLinked (ear: Aim | null, triangles: number[], dim: number, minX:
}

// check whether a polygon node forms a valid ear with adjacent nodes
function isEar (ear: Aim) {
function isEar (ear: Aim): boolean {
const a = ear.prev!;
const b = ear;
const c = ear.next!;
Expand All @@ -182,7 +182,7 @@ function isEar (ear: Aim) {
return true;
}

function isEarHashed (ear: Aim, minX: number, minY: number, size) {
function isEarHashed (ear: Aim, minX: number, minY: number, size): boolean {
const a = ear.prev!;
const b = ear;
const c = ear.next!;
Expand Down Expand Up @@ -226,7 +226,7 @@ function isEarHashed (ear: Aim, minX: number, minY: number, size) {
}

// go through all polygon nodes and cure small local self-intersections
function cureLocalIntersections (start: Aim, triangles: number[], dim: number) {
function cureLocalIntersections (start: Aim, triangles: number[], dim: number): Aim {
let p = start;
do {
const a = p.prev!;
Expand All @@ -250,7 +250,7 @@ function cureLocalIntersections (start: Aim, triangles: number[], dim: number) {
}

// try splitting polygon into two and triangulate them independently
function splitEarcut (start: Aim | null, triangles: number[], dim: number, minX: number, minY: number, size: number) {
function splitEarcut (start: Aim | null, triangles: number[], dim: number, minX: number, minY: number, size: number): void {
// look for a valid diagonal that divides the polygon into two
let a = start!;
do {
Expand All @@ -276,7 +276,7 @@ function splitEarcut (start: Aim | null, triangles: number[], dim: number, minX:
}

// link every hole into the outer loop, producing a single-ring polygon without holes
function eliminateHoles (datas: number[], holeIndices: number[], outerNode: Aim | null, dim: number) {
function eliminateHoles (datas: number[], holeIndices: number[], outerNode: Aim | null, dim: number): Aim | null {
const queue: Aim[] = [];
let i = 0;
let len = 0;
Expand Down Expand Up @@ -313,12 +313,12 @@ function eliminateHoles (datas: number[], holeIndices: number[], outerNode: Aim
return outerNode;
}

function compareX (a, b) {
function compareX (a, b): number {
return a.x - b.x;
}

// find a bridge between vertices that connects hole with an outer ring and and link it
function eliminateHole (hole: Aim, outerNode: Aim | null) {
function eliminateHole (hole: Aim, outerNode: Aim | null): void {
outerNode = findHoleBridge(hole, outerNode!);
if (outerNode) {
const b = splitPolygon(outerNode, hole);
Expand All @@ -327,7 +327,7 @@ function eliminateHole (hole: Aim, outerNode: Aim | null) {
}

// David Eberly's algorithm for finding a bridge between hole and outer polygon
function findHoleBridge (hole: Aim, outerNode: Aim) {
function findHoleBridge (hole: Aim, outerNode: Aim): Aim | null {
let p = outerNode;
const hx = hole.x;
const hy = hole.y;
Expand Down Expand Up @@ -389,7 +389,7 @@ function findHoleBridge (hole: Aim, outerNode: Aim) {
}

// interlink polygon nodes in z-order
function indexCurve (start: Aim, minX: number, minY: number, size: number) {
function indexCurve (start: Aim, minX: number, minY: number, size: number): void {
let p = start;
do {
if (p.z === null) {
Expand All @@ -409,7 +409,7 @@ function indexCurve (start: Aim, minX: number, minY: number, size: number) {

// Simon Tatham's linked list merge sort algorithm
// http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
function sortLinked (list: Aim | null) {
function sortLinked (list: Aim | null): Aim | null {
let i = 0;
let p: Aim | null = null;
let q: Aim | null = null;
Expand Down Expand Up @@ -474,7 +474,7 @@ function sortLinked (list: Aim | null) {
}

// z-order of a point given coords and size of the data bounding box
function zOrder (x: number, y: number, minX: number, minY: number, size: number) {
function zOrder (x: number, y: number, minX: number, minY: number, size: number): number {
// coords are transformed into non-negative 15-bit integer range
x = 32767 * (x - minX) / size;
y = 32767 * (y - minY) / size;
Expand All @@ -493,7 +493,7 @@ function zOrder (x: number, y: number, minX: number, minY: number, size: number)
}

// find the leftmost node of a polygon ring
function getLeftmost (start: Aim) {
function getLeftmost (start: Aim): Aim {
let p = start;
let leftmost = start;
do {
Expand All @@ -508,30 +508,30 @@ function getLeftmost (start: Aim) {
}

// check if a point lies within a convex triangle
function pointInTriangle (ax: number, ay: number, bx: number, by: number, cx: number, cy: number, px: number, py: number) {
function pointInTriangle (ax: number, ay: number, bx: number, by: number, cx: number, cy: number, px: number, py: number): boolean {
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0
&& (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0
&& (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
}

// check if a diagonal between two polygon nodes is valid (lies in polygon interior)
function isValidDiagonal (a: Aim, b: Aim) {
function isValidDiagonal (a: Aim, b: Aim): boolean {
return a.next!.i !== b.i && a.prev!.i !== b.i && !intersectsPolygon(a, b)
&& locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
}

// signed area of a triangle
function area (p: Aim, q: Aim, r: Aim) {
function area (p: Aim, q: Aim, r: Aim): number {
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
}

// check if two points are equal
function equals (p1: Aim, p2: Aim) {
function equals (p1: Aim, p2: Aim): boolean {
return p1.x === p2.x && p1.y === p2.y;
}

// check if two segments intersect
function intersects (p1: Aim, q1: Aim, p2: Aim, q2: Aim) {
function intersects (p1: Aim, q1: Aim, p2: Aim, q2: Aim): boolean {
if ((equals(p1, q1) && equals(p2, q2))
|| (equals(p1, q2) && equals(p2, q1))) {
return true;
Expand All @@ -542,7 +542,7 @@ function intersects (p1: Aim, q1: Aim, p2: Aim, q2: Aim) {
}

// check if a polygon diagonal intersects any polygon segments
function intersectsPolygon (a: Aim, b: Aim) {
function intersectsPolygon (a: Aim, b: Aim): boolean {
let p = a;
do {
if (p.i !== a.i && p.next!.i !== a.i && p.i !== b.i && p.next!.i !== b.i
Expand All @@ -554,14 +554,14 @@ function intersectsPolygon (a: Aim, b: Aim) {
}

// check if a polygon diagonal is locally inside the polygon
function locallyInside (a: Aim, b: Aim) {
function locallyInside (a: Aim, b: Aim): boolean {
return area(a.prev!, a, a.next!) < 0
? area(a, b, a.next!) >= 0 && area(a, a.prev!, b) >= 0
: area(a, b, a.prev!) < 0 || area(a, a.next!, b) < 0;
}

// check if the middle point of a polygon diagonal is inside the polygon
function middleInside (a: Aim, b: Aim) {
function middleInside (a: Aim, b: Aim): boolean {
let p = a;
let inside = false;
const px = (a.x + b.x) / 2;
Expand All @@ -578,7 +578,7 @@ function middleInside (a: Aim, b: Aim) {

// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
// if one belongs to the outer ring and another to a hole, it merges it into a single ring
function splitPolygon (a: Aim, b: Aim) {
function splitPolygon (a: Aim, b: Aim): Aim {
const a2 = new Aim(a.i, a.x, a.y);
const b2 = new Aim(b.i, b.x, b.y);
const an = a.next!;
Expand All @@ -600,7 +600,7 @@ function splitPolygon (a: Aim, b: Aim) {
}

// create a node and optionally link it with previous one (in a circular doubly linked list)
function insertNode (i: number, x: number, y: number, last: Aim | null) {
function insertNode (i: number, x: number, y: number, last: Aim | null): Aim {
const p = new Aim(i, x, y);

if (!last) {
Expand All @@ -616,7 +616,7 @@ function insertNode (i: number, x: number, y: number, last: Aim | null) {
return p;
}

function removeNode (p: Aim) {
function removeNode (p: Aim): void {
p.next!.prev = p.prev;
p.prev!.next = p.next;

Expand All @@ -629,7 +629,7 @@ function removeNode (p: Aim) {
}
}

function signedArea (datas: number[], start: number, end: number, dim: number) {
function signedArea (datas: number[], start: number, end: number, dim: number): number {
let sum = 0;
for (let i = start, j = end - dim; i < end; i += dim) {
sum += (datas[j] - datas[i]) * (datas[i + 1] + datas[j + 1]);
Expand All @@ -638,7 +638,7 @@ function signedArea (datas: number[], start: number, end: number, dim: number) {
return sum;
}

export function earcut (datas: number[], holeIndices: number[] | null, dim: number) {
export function earcut (datas: number[], holeIndices: number[] | null, dim: number): number[] {
dim = dim || 3;

const hasHoles = holeIndices ? holeIndices.length : 0;
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/assembler/graphics/webgl/graphics-assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ for (let i = 0; i < 4; i++) {
vec3_temps.push(new Vec3());
}

function curveDivs (r: number, arc: number, tol: number) {
function curveDivs (r: number, arc: number, tol: number): number {
const da = acos(r / (r + tol)) * 2.0;
return max(2, ceil(arc / da));
}

function clamp (v: number, minNum: number, maxNum: number) {
function clamp (v: number, minNum: number, maxNum: number): number {
if (v < minNum) {
return minNum;
} else if (v > maxNum) {
Expand Down
Loading

0 comments on commit 509d73b

Please sign in to comment.