Merge pull request #20354 from Aditi-1400/use-enum

Use enums instead of string for mesh shading figure type
This commit is contained in:
calixteman 2025-10-10 18:49:50 +02:00 committed by GitHub
commit 30fdf16071
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 9 deletions

View File

@ -18,6 +18,7 @@ import {
FormatError, FormatError,
info, info,
MathClamp, MathClamp,
MeshFigureType,
unreachable, unreachable,
Util, Util,
warn, warn,
@ -582,7 +583,7 @@ class MeshShading extends BaseShading {
reader.align(); reader.align();
} }
this.figures.push({ this.figures.push({
type: "triangles", type: MeshFigureType.TRIANGLES,
coords: new Int32Array(ps), coords: new Int32Array(ps),
colors: new Int32Array(ps), colors: new Int32Array(ps),
}); });
@ -600,7 +601,7 @@ class MeshShading extends BaseShading {
colors.push(color); colors.push(color);
} }
this.figures.push({ this.figures.push({
type: "lattice", type: MeshFigureType.LATTICE,
coords: new Int32Array(ps), coords: new Int32Array(ps),
colors: new Int32Array(ps), colors: new Int32Array(ps),
verticesPerRow, verticesPerRow,
@ -732,7 +733,7 @@ class MeshShading extends BaseShading {
9, 9,
]); ]);
this.figures.push({ this.figures.push({
type: "patch", type: MeshFigureType.PATCH,
coords: new Int32Array(ps), // making copies of ps and cs coords: new Int32Array(ps), // making copies of ps and cs
colors: new Int32Array(cs), colors: new Int32Array(cs),
}); });
@ -802,7 +803,7 @@ class MeshShading extends BaseShading {
break; break;
} }
this.figures.push({ this.figures.push({
type: "patch", type: MeshFigureType.PATCH,
coords: new Int32Array(ps), // making copies of ps and cs coords: new Int32Array(ps), // making copies of ps and cs
colors: new Int32Array(cs), colors: new Int32Array(cs),
}); });
@ -811,7 +812,10 @@ class MeshShading extends BaseShading {
_buildFigureFromPatch(index) { _buildFigureFromPatch(index) {
const figure = this.figures[index]; const figure = this.figures[index];
assert(figure.type === "patch", "Unexpected patch mesh figure"); assert(
figure.type === MeshFigureType.PATCH,
"Unexpected patch mesh figure"
);
const coords = this.coords, const coords = this.coords,
colors = this.colors; colors = this.colors;
@ -919,7 +923,7 @@ class MeshShading extends BaseShading {
figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3]; figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
this.figures[index] = { this.figures[index] = {
type: "lattice", type: MeshFigureType.LATTICE,
coords: figureCoords, coords: figureCoords,
colors: figureColors, colors: figureColors,
verticesPerRow, verticesPerRow,

View File

@ -13,7 +13,13 @@
* limitations under the License. * limitations under the License.
*/ */
import { FormatError, info, unreachable, Util } from "../shared/util.js"; import {
FormatError,
info,
MeshFigureType,
unreachable,
Util,
} from "../shared/util.js";
import { getCurrentTransform } from "./display_utils.js"; import { getCurrentTransform } from "./display_utils.js";
const PathType = { const PathType = {
@ -261,7 +267,7 @@ function drawFigure(data, figure, context) {
const cs = figure.colors; const cs = figure.colors;
let i, ii; let i, ii;
switch (figure.type) { switch (figure.type) {
case "lattice": case MeshFigureType.LATTICE:
const verticesPerRow = figure.verticesPerRow; const verticesPerRow = figure.verticesPerRow;
const rows = Math.floor(ps.length / verticesPerRow) - 1; const rows = Math.floor(ps.length / verticesPerRow) - 1;
const cols = verticesPerRow - 1; const cols = verticesPerRow - 1;
@ -291,7 +297,7 @@ function drawFigure(data, figure, context) {
} }
} }
break; break;
case "triangles": case MeshFigureType.TRIANGLES:
for (i = 0, ii = ps.length; i < ii; i += 3) { for (i = 0, ii = ps.length; i < ii; i += 3) {
drawTriangle( drawTriangle(
data, data,

View File

@ -108,6 +108,12 @@ const PermissionFlag = {
PRINT_HIGH_QUALITY: 0x800, PRINT_HIGH_QUALITY: 0x800,
}; };
const MeshFigureType = {
TRIANGLES: 1,
LATTICE: 2,
PATCH: 3,
};
const TextRenderingMode = { const TextRenderingMode = {
FILL: 0, FILL: 0,
STROKE: 1, STROKE: 1,
@ -1327,6 +1333,7 @@ export {
LINE_DESCENT_FACTOR, LINE_DESCENT_FACTOR,
LINE_FACTOR, LINE_FACTOR,
MathClamp, MathClamp,
MeshFigureType,
normalizeUnicode, normalizeUnicode,
objectSize, objectSize,
OPS, OPS,