Best JavaScript code snippet using wpt
pattern.ts
Source:pattern.ts
...534 colorFn: fn,535 colorSpace: cs,536 numComps: fn ? 1 : cs.numComps,537 };538 const reader = new MeshStreamReader( stream, decodeContext );539 let patchMesh = false;540 switch( this.shadingType )541 {542 case ShadingType.FREE_FORM_MESH:543 this._decodeType4Shading( reader );544 break;545 case ShadingType.LATTICE_FORM_MESH:546 const verticesPerRow = <any>dict.get("VerticesPerRow") | 0;547 if (verticesPerRow < 2) {548 throw new FormatError("Invalid VerticesPerRow");549 }550 this._decodeType5Shading( reader, verticesPerRow );551 break;552 case ShadingType.COONS_PATCH_MESH:...
pattern.js
Source:pattern.js
...189})();190// All mesh shading. For now, they will be presented as set of the triangles191// to be drawn on the canvas and rgb color for each vertex.192Shadings.Mesh = (function MeshClosure() {193 function MeshStreamReader(stream, context) {194 this.stream = stream;195 this.context = context;196 this.buffer = 0;197 this.bufferLength = 0;198 var numComps = context.numComps;199 this.tmpCompsBuf = new Float32Array(numComps);200 var csNumComps = context.colorSpace;201 this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :202 this.tmpCompsBuf;203 }204 MeshStreamReader.prototype = {205 get hasData() {206 if (this.stream.end) {207 return this.stream.pos < this.stream.end;208 }209 if (this.bufferLength > 0) {210 return true;211 }212 var nextByte = this.stream.getByte();213 if (nextByte < 0) {214 return false;215 }216 this.buffer = nextByte;217 this.bufferLength = 8;218 return true;219 },220 readBits: function MeshStreamReader_readBits(n) {221 var buffer = this.buffer;222 var bufferLength = this.bufferLength;223 if (n === 32) {224 if (bufferLength === 0) {225 return ((this.stream.getByte() << 24) |226 (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |227 this.stream.getByte()) >>> 0;228 }229 buffer = (buffer << 24) | (this.stream.getByte() << 16) |230 (this.stream.getByte() << 8) | this.stream.getByte();231 var nextByte = this.stream.getByte();232 this.buffer = nextByte & ((1 << bufferLength) - 1);233 return ((buffer << (8 - bufferLength)) |234 ((nextByte & 0xFF) >> bufferLength)) >>> 0;235 }236 if (n === 8 && bufferLength === 0) {237 return this.stream.getByte();238 }239 while (bufferLength < n) {240 buffer = (buffer << 8) | this.stream.getByte();241 bufferLength += 8;242 }243 bufferLength -= n;244 this.bufferLength = bufferLength;245 this.buffer = buffer & ((1 << bufferLength) - 1);246 return buffer >> bufferLength;247 },248 align: function MeshStreamReader_align() {249 this.buffer = 0;250 this.bufferLength = 0;251 },252 readFlag: function MeshStreamReader_readFlag() {253 return this.readBits(this.context.bitsPerFlag);254 },255 readCoordinate: function MeshStreamReader_readCoordinate() {256 var bitsPerCoordinate = this.context.bitsPerCoordinate;257 var xi = this.readBits(bitsPerCoordinate);258 var yi = this.readBits(bitsPerCoordinate);259 var decode = this.context.decode;260 var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :261 2.3283064365386963e-10; // 2 ^ -32262 return [263 xi * scale * (decode[1] - decode[0]) + decode[0],264 yi * scale * (decode[3] - decode[2]) + decode[2]265 ];266 },267 readComponents: function MeshStreamReader_readComponents() {268 var numComps = this.context.numComps;269 var bitsPerComponent = this.context.bitsPerComponent;270 var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :271 2.3283064365386963e-10; // 2 ^ -32272 var decode = this.context.decode;273 var components = this.tmpCompsBuf;274 for (var i = 0, j = 4; i < numComps; i++, j += 2) {275 var ci = this.readBits(bitsPerComponent);276 components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];277 }278 var color = this.tmpCsCompsBuf;279 if (this.context.colorFn) {280 this.context.colorFn(components, 0, color, 0);281 }282 return this.context.colorSpace.getRgb(color, 0);283 }284 };285 function decodeType4Shading(mesh, reader) {286 var coords = mesh.coords;287 var colors = mesh.colors;288 var operators = [];289 var ps = []; // not maintaining cs since that will match ps290 var verticesLeft = 0; // assuming we have all data to start a new triangle291 while (reader.hasData) {292 var f = reader.readFlag();293 var coord = reader.readCoordinate();294 var color = reader.readComponents();295 if (verticesLeft === 0) { // ignoring flags if we started a triangle296 assert(0 <= f && f <= 2, 'Unknown type4 flag');297 switch (f) {298 case 0:299 verticesLeft = 3;300 break;301 case 1:302 ps.push(ps[ps.length - 2], ps[ps.length - 1]);303 verticesLeft = 1;304 break;305 case 2:306 ps.push(ps[ps.length - 3], ps[ps.length - 1]);307 verticesLeft = 1;308 break;309 }310 operators.push(f);311 }312 ps.push(coords.length);313 coords.push(coord);314 colors.push(color);315 verticesLeft--;316 reader.align();317 }318 var psPacked = new Int32Array(ps);319 mesh.figures.push({320 type: 'triangles',321 coords: psPacked,322 colors: psPacked323 });324 }325 function decodeType5Shading(mesh, reader, verticesPerRow) {326 var coords = mesh.coords;327 var colors = mesh.colors;328 var ps = []; // not maintaining cs since that will match ps329 while (reader.hasData) {330 var coord = reader.readCoordinate();331 var color = reader.readComponents();332 ps.push(coords.length);333 coords.push(coord);334 colors.push(color);335 }336 var psPacked = new Int32Array(ps);337 mesh.figures.push({338 type: 'lattice',339 coords: psPacked,340 colors: psPacked,341 verticesPerRow: verticesPerRow342 });343 }344 var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;345 var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;346 var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds347 var getB = (function getBClosure() {348 function buildB(count) {349 var lut = [];350 for (var i = 0; i <= count; i++) {351 var t = i / count, t_ = 1 - t;352 lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,353 3 * t * t * t_, t * t * t]));354 }355 return lut;356 }357 var cache = [];358 return function getB(count) {359 if (!cache[count]) {360 cache[count] = buildB(count);361 }362 return cache[count];363 };364 })();365 function buildFigureFromPatch(mesh, index) {366 var figure = mesh.figures[index];367 assert(figure.type === 'patch', 'Unexpected patch mesh figure');368 var coords = mesh.coords, colors = mesh.colors;369 var pi = figure.coords;370 var ci = figure.colors;371 var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],372 coords[pi[12]][0], coords[pi[15]][0]);373 var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],374 coords[pi[12]][1], coords[pi[15]][1]);375 var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],376 coords[pi[12]][0], coords[pi[15]][0]);377 var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],378 coords[pi[12]][1], coords[pi[15]][1]);379 var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /380 (mesh.bounds[2] - mesh.bounds[0]));381 splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,382 Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));383 var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /384 (mesh.bounds[3] - mesh.bounds[1]));385 splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,386 Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));387 var verticesPerRow = splitXBy + 1;388 var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);389 var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);390 var k = 0;391 var cl = new Uint8Array(3), cr = new Uint8Array(3);392 var c0 = colors[ci[0]], c1 = colors[ci[1]],393 c2 = colors[ci[2]], c3 = colors[ci[3]];394 var bRow = getB(splitYBy), bCol = getB(splitXBy);395 for (var row = 0; row <= splitYBy; row++) {396 cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;397 cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;398 cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;399 cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;400 cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;401 cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;402 for (var col = 0; col <= splitXBy; col++, k++) {403 if ((row === 0 || row === splitYBy) &&404 (col === 0 || col === splitXBy)) {405 continue;406 }407 var x = 0, y = 0;408 var q = 0;409 for (var i = 0; i <= 3; i++) {410 for (var j = 0; j <= 3; j++, q++) {411 var m = bRow[row][i] * bCol[col][j];412 x += coords[pi[q]][0] * m;413 y += coords[pi[q]][1] * m;414 }415 }416 figureCoords[k] = coords.length;417 coords.push([x, y]);418 figureColors[k] = colors.length;419 var newColor = new Uint8Array(3);420 newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;421 newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;422 newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;423 colors.push(newColor);424 }425 }426 figureCoords[0] = pi[0];427 figureColors[0] = ci[0];428 figureCoords[splitXBy] = pi[3];429 figureColors[splitXBy] = ci[1];430 figureCoords[verticesPerRow * splitYBy] = pi[12];431 figureColors[verticesPerRow * splitYBy] = ci[2];432 figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];433 figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];434 mesh.figures[index] = {435 type: 'lattice',436 coords: figureCoords,437 colors: figureColors,438 verticesPerRow: verticesPerRow439 };440 }441 function decodeType6Shading(mesh, reader) {442 // A special case of Type 7. The p11, p12, p21, p22 automatically filled443 var coords = mesh.coords;444 var colors = mesh.colors;445 var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33446 var cs = new Int32Array(4); // c00, c30, c03, c33447 while (reader.hasData) {448 var f = reader.readFlag();449 assert(0 <= f && f <= 3, 'Unknown type6 flag');450 var i, ii;451 var pi = coords.length;452 for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {453 coords.push(reader.readCoordinate());454 }455 var ci = colors.length;456 for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {457 colors.push(reader.readComponents());458 }459 var tmp1, tmp2, tmp3, tmp4;460 switch (f) {461 case 0:462 ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;463 ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;464 ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;465 ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;466 cs[2] = ci + 1; cs[3] = ci + 2;467 cs[0] = ci; cs[1] = ci + 3;468 break;469 case 1:470 tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];471 ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;472 ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;473 ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;474 ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;475 tmp1 = cs[2]; tmp2 = cs[3];476 cs[2] = ci + 1; cs[3] = ci;477 cs[0] = tmp1; cs[1] = tmp2;478 break;479 case 2:480 ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;481 ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;482 ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;483 ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;484 cs[2] = cs[3]; cs[3] = ci + 1;485 cs[0] = cs[1]; cs[1] = ci;486 break;487 case 3:488 ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];489 ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;490 ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;491 ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;492 cs[2] = cs[0]; cs[3] = cs[1];493 cs[0] = ci; cs[1] = ci + 1;494 break;495 }496 // set p11, p12, p21, p22497 ps[5] = coords.length;498 coords.push([499 (-4 * coords[ps[0]][0] - coords[ps[15]][0] +500 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -501 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +502 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,503 (-4 * coords[ps[0]][1] - coords[ps[15]][1] +504 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -505 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +506 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9507 ]);508 ps[6] = coords.length;509 coords.push([510 (-4 * coords[ps[3]][0] - coords[ps[12]][0] +511 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -512 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +513 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,514 (-4 * coords[ps[3]][1] - coords[ps[12]][1] +515 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -516 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +517 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9518 ]);519 ps[9] = coords.length;520 coords.push([521 (-4 * coords[ps[12]][0] - coords[ps[3]][0] +522 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -523 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +524 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,525 (-4 * coords[ps[12]][1] - coords[ps[3]][1] +526 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -527 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +528 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9529 ]);530 ps[10] = coords.length;531 coords.push([532 (-4 * coords[ps[15]][0] - coords[ps[0]][0] +533 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -534 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +535 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,536 (-4 * coords[ps[15]][1] - coords[ps[0]][1] +537 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -538 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +539 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9540 ]);541 mesh.figures.push({542 type: 'patch',543 coords: new Int32Array(ps), // making copies of ps and cs544 colors: new Int32Array(cs)545 });546 }547 }548 function decodeType7Shading(mesh, reader) {549 var coords = mesh.coords;550 var colors = mesh.colors;551 var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33552 var cs = new Int32Array(4); // c00, c30, c03, c33553 while (reader.hasData) {554 var f = reader.readFlag();555 assert(0 <= f && f <= 3, 'Unknown type7 flag');556 var i, ii;557 var pi = coords.length;558 for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {559 coords.push(reader.readCoordinate());560 }561 var ci = colors.length;562 for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {563 colors.push(reader.readComponents());564 }565 var tmp1, tmp2, tmp3, tmp4;566 switch (f) {567 case 0:568 ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;569 ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;570 ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;571 ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;572 cs[2] = ci + 1; cs[3] = ci + 2;573 cs[0] = ci; cs[1] = ci + 3;574 break;575 case 1:576 tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];577 ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;578 ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;579 ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;580 ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;581 tmp1 = cs[2]; tmp2 = cs[3];582 cs[2] = ci + 1; cs[3] = ci;583 cs[0] = tmp1; cs[1] = tmp2;584 break;585 case 2:586 ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;587 ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;588 ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;589 ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;590 cs[2] = cs[3]; cs[3] = ci + 1;591 cs[0] = cs[1]; cs[1] = ci;592 break;593 case 3:594 ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];595 ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;596 ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;597 ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;598 cs[2] = cs[0]; cs[3] = cs[1];599 cs[0] = ci; cs[1] = ci + 1;600 break;601 }602 mesh.figures.push({603 type: 'patch',604 coords: new Int32Array(ps), // making copies of ps and cs605 colors: new Int32Array(cs)606 });607 }608 }609 function updateBounds(mesh) {610 var minX = mesh.coords[0][0], minY = mesh.coords[0][1],611 maxX = minX, maxY = minY;612 for (var i = 1, ii = mesh.coords.length; i < ii; i++) {613 var x = mesh.coords[i][0], y = mesh.coords[i][1];614 minX = minX > x ? x : minX;615 minY = minY > y ? y : minY;616 maxX = maxX < x ? x : maxX;617 maxY = maxY < y ? y : maxY;618 }619 mesh.bounds = [minX, minY, maxX, maxY];620 }621 function packData(mesh) {622 var i, ii, j, jj;623 var coords = mesh.coords;624 var coordsPacked = new Float32Array(coords.length * 2);625 for (i = 0, j = 0, ii = coords.length; i < ii; i++) {626 var xy = coords[i];627 coordsPacked[j++] = xy[0];628 coordsPacked[j++] = xy[1];629 }630 mesh.coords = coordsPacked;631 var colors = mesh.colors;632 var colorsPacked = new Uint8Array(colors.length * 3);633 for (i = 0, j = 0, ii = colors.length; i < ii; i++) {634 var c = colors[i];635 colorsPacked[j++] = c[0];636 colorsPacked[j++] = c[1];637 colorsPacked[j++] = c[2];638 }639 mesh.colors = colorsPacked;640 var figures = mesh.figures;641 for (i = 0, ii = figures.length; i < ii; i++) {642 var figure = figures[i], ps = figure.coords, cs = figure.colors;643 for (j = 0, jj = ps.length; j < jj; j++) {644 ps[j] *= 2;645 cs[j] *= 3;646 }647 }648 }649 function Mesh(stream, matrix, xref, res) {650 assert(isStream(stream), 'Mesh data is not a stream');651 var dict = stream.dict;652 this.matrix = matrix;653 this.shadingType = dict.get('ShadingType');654 this.type = 'Pattern';655 this.bbox = dict.get('BBox');656 var cs = dict.get('ColorSpace', 'CS');657 cs = ColorSpace.parse(cs, xref, res);658 this.cs = cs;659 this.background = dict.has('Background') ?660 cs.getRgb(dict.get('Background'), 0) : null;661 var fnObj = dict.get('Function');662 var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;663 this.coords = [];664 this.colors = [];665 this.figures = [];666 var decodeContext = {667 bitsPerCoordinate: dict.get('BitsPerCoordinate'),668 bitsPerComponent: dict.get('BitsPerComponent'),669 bitsPerFlag: dict.get('BitsPerFlag'),670 decode: dict.get('Decode'),671 colorFn: fn,672 colorSpace: cs,673 numComps: fn ? 1 : cs.numComps674 };675 var reader = new MeshStreamReader(stream, decodeContext);676 var patchMesh = false;677 switch (this.shadingType) {678 case PatternType.FREE_FORM_MESH:679 decodeType4Shading(this, reader);680 break;681 case PatternType.LATTICE_FORM_MESH:682 var verticesPerRow = dict.get('VerticesPerRow') | 0;683 assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');684 decodeType5Shading(this, reader, verticesPerRow);685 break;686 case PatternType.COONS_PATCH_MESH:687 decodeType6Shading(this, reader);688 patchMesh = true;689 break;...
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var meshstreamreader = require('wptools/lib/meshstreamreader');4var meshstreamwriter = require('wptools/lib/meshstreamwriter');5var msh = new meshstreamreader();6var mshw = new meshstreamwriter();7var wps = new wptools();8var wp = new wptools();9var mesh = fs.readFileSync('testmesh2.msh');10var mesh2 = fs.readFileSync('testmesh2.msh');
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var stream = fs.createReadStream('test.msh');4var reader = new wptools.MeshStreamReader(stream);5reader.on('header', function(header) {6 console.log('header', header);7});8reader.on('data', function(data) {9 console.log('data', data);10});11reader.on('end', function() {12 console.log('end');13});14reader.on('error', function(err) {15 console.log('error', err);16});17reader.read();18#### writeObject(obj, done)19var wptools = require('wptools');20var fs = require('fs');21var stream = fs.createWriteStream('test.msh');22var writer = new wptools.MeshStreamWriter(stream);23writer.typeMap['header'] = function(header, done) {24 done();25};26writer.typeMap['data'] = function(data, done) {27 done();28};29writer.writeObject({type: 'header', version: 1}, function(err) {30 if (err) {31 }
Using AI Code Generation
1var fs = require('fs');2var wptools = require('wptools');3var mesh = new wptools.MeshStreamReader();4mesh.on('data', function(data) {5 console.log(data);6});7fs.createReadStream('mesh.dmp').pipe(mesh);
Using AI Code Generation
1var wptools = require('wp-tools');2var fs = require('fs');3var request = require('request');4var path = require('path');5var async = require('async');6var http = require('http');7var https = require('https');8var _ = require('lodash');9var mesh = new wptools.MeshStreamReader();10var meshFile = fs.createReadStream('msh.txt');11meshFile.pipe(mesh);12mesh.on('data', function(data) {13 console.log(data);14});15mesh.on('error', function(err) {16 console.log(err);17});18mesh.on('end', function() {19 console.log('done');20});21var wptools = require('wp-tools');22var fs = require('fs');23var request = require('request');24var path = require('path');25var async = require('async');26var http = require('http');27var https = require('https');28var _ = require('lodash');29var mesh = new wptools.MeshStreamReader();30var meshFile = fs.createReadStream('msh.txt');31meshFile.pipe(mesh);32mesh.on('data', function(data) {33 console.log(data);34});35mesh.on('error', function(err) {36 console.log(err);37});38mesh.on('end', function() {39 console.log('done');40});41var wptools = require('wp-tools');42var fs = require('fs');43var request = require('request');44var path = require('path');45var async = require('async');46var http = require('http');47var https = require('https');48var _ = require('lodash');49var mesh = new wptools.MeshStreamReader();50var meshFile = fs.createReadStream('msh.txt');51meshFile.pipe(mesh);52mesh.on('data', function(data) {53 console.log(data);54});55mesh.on('error', function(err) {56 console.log(err);57});58mesh.on('end', function() {59 console.log('done');60});61var wptools = require('wp-tools');62var fs = require('fs');63var request = require('request');64var path = require('path');65var async = require('async');66var http = require('http');67var https = require('
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var stream = fs.createWriteStream("output.txt");4var reader = new wptools.MeshStreamReader(stream);5var mesh = new wptools.Mesh();6mesh.addVertex(new wptools.Vertex(0, 0, 0));7mesh.addVertex(new wptools.Vertex(1, 0, 0));8mesh.addVertex(new wptools.Vertex(1, 1, 0));9mesh.addVertex(new wptools.Vertex(0, 1, 0));10mesh.addFace(new wptools.Face(0, 1, 2));11mesh.addFace(new wptools.Face(0, 2, 3));12reader.writeMesh(mesh);13stream.end();
Using AI Code Generation
1var fs = require('fs');2var wptools = require('wptools');3var path = require('path');4var mesh = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000001.bin'));5var mesh2 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000002.bin'));6var mesh3 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000003.bin'));7var mesh4 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000004.bin'));8var mesh5 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000005.bin'));9var mesh6 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000006.bin'));10var mesh7 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000007.bin'));11var mesh8 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000008.bin'));12var mesh9 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000009.bin'));13var mesh10 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000010.bin'));14var mesh11 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000011.bin'));15var mesh12 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000012.bin'));16var mesh13 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000013.bin'));17var mesh14 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000014.bin'));18var mesh15 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000015.bin'));19var mesh16 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000016.bin'));20var mesh17 = new wptools.MeshStreamReader(path.join(__dirname, 'data', 'mesh', 'd000017.bin'));21var mesh18 = new wptools.MeshStreamReader(path.join(__dirname
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var stream = fs.createWriteStream("test2.png");4var mesh = wptools.meshStream("00000000-0000-0000-0000-000000000000", "test2.png");5mesh.on("error", function(err) {6 console.log(err);7});8mesh.on("end", function() {9 console.log("finished");10});11mesh.pipe(stream);
Using AI Code Generation
1const wptools = require('wptools');2const fs = require('fs');3const csv = require('csv-parser');4const createCsvWriter = require('csv-writer').createObjectCsvWriter;5var csvWriter = createCsvWriter({6 {id: 'drug', title: 'Drug'},7 {id: 'mesh', title: 'mesh'}8});9let drugMesh = [];10fs.createReadStream('drug.csv')11 .pipe(csv())12 .on('data', (row) => {13 wptools.page(row.drug).get().then(function(doc) {14 drugMesh.push({drug: row.drug, mesh: doc.data.mesh});15 console.log(drugMesh);16 });17 })18 .on('end', () => {19 console.log('CSV file successfully processed');20 .writeRecords(drugMesh)21 .then(()=> console.log('The CSV file was written successfully'));22 });
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!