How to use buildFigureFromPatch method in wpt

Best JavaScript code snippet using wpt

pattern.js

Source:pattern.js Github

copy

Full Screen

...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;690 case PatternType.TENSOR_PATCH_MESH:691 decodeType7Shading(this, reader);692 patchMesh = true;693 break;694 default:695 error('Unsupported mesh type.');696 break;697 }698 if (patchMesh) {699 // dirty bounds calculation for determining, how dense shall be triangles700 updateBounds(this);701 for (var i = 0, ii = this.figures.length; i < ii; i++) {702 buildFigureFromPatch(this, i);703 }704 }705 // calculate bounds706 updateBounds(this);707 packData(this);708 }709 Mesh.prototype = {710 getIR: function Mesh_getIR() {711 return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,712 this.bounds, this.matrix, this.bbox, this.background];713 }714 };715 return Mesh;716})();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var patch = fs.readFileSync(path.join(__dirname, 'patch.json'));5var figure = wptools.buildFigureFromPatch(patch);6console.log(figure);7var fs = require('fs');8var path = require('path');9var patch = {10 "image": {11 },12 "originalimage": {13 }14};15fs.writeFileSync(path.join(__dirname, 'patch.json'), JSON.stringify(patch, null, 2));16{17 "image": {18 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var util = require('util');5var wp = new wptools.page('Eiffel Tower');6wp.buildFigureFromPatch(function(err, resp){7 if (err) {8 console.log(err);9 } else {10 console.log(resp);11 }12});13{14 "dependencies": {15 },16 "devDependencies": {},17 "scripts": {18 },19}20{ [Error: ENOENT: no such file or directory, open 'C:\Users\user\AppData\Roaming21pm\\node_modules\\wptools\\patch.png' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var figure = wptools.buildFigureFromPatch('en', 'Barack_Obama', 1, 2, 3, 4, 'Obama.jpg');3console.log(figure);4var wptools = require('wptools');5var figure = wptools.buildFigureFromPatch('en', 'Barack_Obama', 1, 2, 3, 4, 'Obama.jpg', 'Obama');6console.log(figure);7var wptools = require('wptools');8var figure = wptools.buildFigureFromPatch('en', 'Barack_Obama', 1, 2, 3, 4, 'Obama.jpg', 'Obama', 'Obama');9console.log(figure);10var wptools = require('wptools');11var figure = wptools.buildFigureFromPatch('en', 'Barack_Obama', 1, 2, 3, 4, 'Obama.jpg', 'Obama', 'Obama', 'Obama');12console.log(figure);13var wptools = require('wptools');14var figure = wptools.buildFigureFromPatch('en', 'Barack_Obama', 1, 2, 3, 4, 'Obama.jpg', 'Obama', 'Obama', 'Obama', 'Obama');15console.log(figure);16var wptools = require('wptools');17var figure = wptools.buildFigureFromPatch('en', 'Barack_Obama', 1, 2, 3, 4, 'Obama.jpg', 'Obama', 'Obama', 'Obama', 'Obama', 'Obama');18console.log(figure);19var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require("wptools");2var patch = require("patch");3var path = require("path");4var patchObj = patch.newPatch();5patchObj.addPoint(0, 0);6patchObj.addPoint(0, 1);7patchObj.addPoint(1, 1);8patchObj.addPoint(1, 0);9patchObj.addPoint(0, 0);10var figureObj = wptools.buildFigureFromPatch(patchObj);11var pathObj = path.newPath();12pathObj.addPoint(0, 0);13pathObj.addPoint(0, 1);14pathObj.addPoint(1, 1);15pathObj.addPoint(1, 0);16pathObj.addPoint(0, 0);17var figureObj2 = wptools.buildFigureFromPath(pathObj);18var isEqual = wptools.isEqual(figureObj, figureObj2);19console.log("isEqual: " + isEqual);20var isSame = wptools.isSame(figureObj, figureObj2);21console.log("isSame: " + isSame);22var isSame2 = wptools.isSame(figureObj, figureObj);23console.log("isSame2: " + isSame2);24var isEqual2 = wptools.isEqual(figureObj, figureObj2);25console.log("isEqual2: " + isEqual2);26var isSame3 = wptools.isSame(figureObj, figureObj2);27console.log("isSame3: " + isSame3);28var isSame4 = wptools.isSame(figureObj, figureObj);29console.log("isSame4: " + isSame4);30var isEqual3 = wptools.isEqual(figureObj, figureObj2);31console.log("isEqual3: " + isEqual3);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fig = new Figure("testFig");2fig.setAxes(0,100,0,100);3fig.setAxesLabels("x","y");4fig.setAxesTicks(20,20);5fig.setAxesTickLabels(10,10);6fig.setAxesTickLabelOffsets(10,10);7fig.setAxesTickLabelOrientations("horizontal","vertical");8fig.setAxesTickLabelFonts("normal 12px Arial","normal 12px Arial");9fig.setAxesTickLabelColors("black","black");10fig.setAxesTickLabelBackgroundColors("white","white");11fig.setAxesTickLabelBackgroundOpacity(1);12fig.setAxesTickLabelBackgroundPadding(5,5);13fig.setAxesTickLabelBackgroundBorder("black",1);14fig.setAxesTickLabelBackgroundBorderRadius(5);15fig.setAxesTickLabelBackgroundBorderOpacity(1);16fig.setAxesTickLabelBackgroundBorderDashes(0);17fig.setAxesTickLabelBackgroundBorderDashOffset(0);

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful