Best JavaScript code snippet using tracetest
Geometry.js
Source:Geometry.js
1import utils from 'osg/utils';2import notify from 'osg/notify';3import Node from 'osg/Node';4import WebGLCaps from 'osg/WebGLCaps';5import DrawElements from 'osg/DrawElements';6import BufferArrayProxy from 'osg/BufferArrayProxy';7import VertexArrayObject from 'osg/VertexArrayObject';8/**9 * Geometry manage array and primitives to draw a geometry.10 * @class Geometry11 */12var Geometry = function() {13 Node.call(this);14 this._attributes = {};15 this._primitives = [];16 // function is generated for each Shader Program ID17 // which generates a a special "draw"18 // TODO: could be upon hash of combination of attributes19 // (as multiple shader Programs can use same combination of attributes)20 this._cacheDrawCall = {};21 // VAO cached data, per combination of vertex buffer22 // program id also the cache key23 this._useVAO = undefined;24 this._vao = {};25 this._cacheVertexAttributeBufferList = {};26 // null means the kdTree builder will skip the kdTree creation27 this._shape = undefined;28};29Geometry.enableVAO = true;30/** @lends Geometry.prototype */31utils.createPrototypeNode(32 Geometry,33 utils.objectInherit(Node.prototype, {34 releaseGLObjects: function() {35 if (this.stateset !== undefined) this.stateset.releaseGLObjects();36 for (var keyAttribute in this._attributes) {37 var value = this._attributes[keyAttribute];38 value.releaseGLObjects();39 }40 for (var i = 0, h = this._primitives.length; i < h; i++) {41 var prim = this._primitives[i];42 if (prim.getIndices !== undefined) {43 if (prim.getIndices() !== undefined && prim.getIndices() !== null) {44 prim.indices.releaseGLObjects();45 }46 }47 }48 this.releaseVAO();49 },50 releaseVAO: function() {51 if (!this._useVAO || !this._glContext) return;52 for (var prgID in this._vao) {53 if (this._vao[prgID]) {54 this._vao[prgID].releaseGLObjects();55 this._vao[prgID] = undefined;56 }57 }58 },59 dirty: function() {60 this._cacheDrawCall = {};61 this.releaseVAO();62 },63 getPrimitives: function() {64 // Notify.warn( 'deprecated use instead getPrimitiveSetList' );65 return this.getPrimitiveSetList();66 },67 getAttributes: function() {68 // Notify.warn( 'deprecated use instead getVertexAttributeList' );69 return this.getVertexAttributeList();70 },71 getShape: function() {72 return this._shape;73 },74 setShape: function(shape) {75 this._shape = shape;76 },77 getVertexAttributeList: function() {78 return this._attributes;79 },80 /**81 * Return the primitiveset list82 * If you modify something inside this array83 * you must call dirty() on the Geometry84 */85 getPrimitiveSetList: function() {86 return this._primitives;87 },88 /**89 * Set the buffer array on the attribute name key90 * key is often something like Vertex, Normal, Color, ...91 * for classic geometry92 *93 * if you change a buffer a dirty will be automatically94 * called to rebuild the VAO if needed.95 */96 setVertexAttribArray: function(key, array) {97 if (this._attributes[key] !== array) {98 this._attributes[key] = array;99 this.dirty();100 }101 },102 _generateVertexSetup: function(103 validAttributeKeyList,104 validAttributeIndexList,105 includeFirstIndexBuffer106 ) {107 // generate setup for vertex attribute108 // will be used as setup for vao or as is without vao109 var vertexAttributeSetup = [110 '//generated by Geometry::implementation',111 'state.lazyDisablingOfVertexAttributes();',112 'var attr;'113 ];114 for (var i = 0, l = validAttributeKeyList.length; i < l; i++) {115 vertexAttributeSetup.push(116 "attr = this._attributes['" + validAttributeKeyList[i] + "'];"117 );118 vertexAttributeSetup.push(119 'if ( attr.BufferArrayProxy ) attr = attr.getBufferArray();'120 );121 vertexAttributeSetup.push('if ( !attr.isValid() ) return;');122 vertexAttributeSetup.push(123 'state.setVertexAttribArray(' +124 validAttributeIndexList[i] +125 ', attr, attr.getNormalize() );'126 );127 }128 vertexAttributeSetup.push('state.applyDisablingOfVertexAttributes();');129 if (includeFirstIndexBuffer)130 vertexAttributeSetup.push(131 'state.setIndexArray( this._primitives[ 0 ].getIndices() );'132 );133 return vertexAttributeSetup;134 },135 _generatePrimitives: function(validPrimitives, hasVertexColor, optimizeVAO) {136 var primitiveSetup = [137 hasVertexColor ? 'state.enableVertexColor();' : 'state.disableVertexColor();'138 ];139 if (optimizeVAO) {140 return primitiveSetup.concat([141 'var primitive = this._primitives[ ' + validPrimitives[0] + ' ];',142 'var indexes = primitive.getIndices();',143 'if ( indexes.isDirty() ) {;',144 ' indexes.bind( gl );',145 ' indexes.compile( gl );',146 '};',147 'primitive.drawElements( state );'148 ]);149 }150 primitiveSetup.push('var primitives = this._primitives;');151 for (var j = 0, m = validPrimitives.length; j < m; j++) {152 primitiveSetup.push('primitives[' + validPrimitives[j] + '].draw(state);');153 }154 return primitiveSetup;155 },156 /**157 * Generate a function specific to the Geometry/Program158 * two version one using VAO and a regular one159 */160 generateDrawCommand: (function() {161 var validAttributeList = [];162 var validAttributeKeyList = [];163 return function(state, program, prgID, validPrimitives) {164 var attributesCacheMap = program._attributesCache;165 var geometryVertexAttributes = this.getVertexAttributeList();166 validAttributeKeyList.length = 0;167 validAttributeList.length = 0;168 // 1 - register valid vertex attributes and color flag169 var attribute, j, m, attr;170 var useVAO = this._useVAO;171 var listVABuff = useVAO ? [] : undefined;172 var hasVertexColor = false;173 for (var key in attributesCacheMap) {174 attribute = attributesCacheMap[key];175 attr = geometryVertexAttributes[key];176 if (attr === undefined) continue;177 var attributeBuffer = this._attributes[key];178 // dont use VAO if we have BufferArrayProxy179 // typically used for morphing180 if (attributeBuffer instanceof BufferArrayProxy) {181 attributeBuffer = attributeBuffer.getBufferArray();182 useVAO = false;183 }184 if (!attributeBuffer.isValid()) return undefined;185 // store for later usage at draw time/update186 if (useVAO) listVABuff.push(attributeBuffer);187 if (!hasVertexColor && key === 'Color') hasVertexColor = true;188 validAttributeKeyList.push(key);189 validAttributeList.push(attribute);190 }191 var autogeneratedFunction;192 var functionName;193 // generate specific function using VAO or standard194 if (useVAO) {195 this._cacheVertexAttributeBufferList[prgID] = listVABuff;196 // if there is only one drawElement we can put the index buffer197 // in the vao198 var optimizeIndexBufferVAO =199 validPrimitives.length === 1 &&200 this._primitives[validPrimitives[0]] instanceof DrawElements;201 var vertexAttributeSetup = this._generateVertexSetup(202 validAttributeKeyList,203 validAttributeList,204 optimizeIndexBufferVAO205 );206 state.clearVertexAttribCache();207 var gl = state.getGraphicContext();208 var vao = new VertexArrayObject(gl);209 vao.create(gl);210 state.setVertexArrayObject(vao);211 this._vao[prgID] = vao;212 // evaluate the vertexAttribute setup to register into the vao213 /*jshint evil: true */214 var vertexSetupCommand = new Function('state', vertexAttributeSetup.join('\n'));215 /*jshint evil: false */216 vertexSetupCommand.call(this, state);217 // setup the program218 var vaoSetup = [219 'var gl = state.getGraphicContext();',220 'var vao = this._vao[ ' + prgID + ' ] ',221 'var hasChanged = state.setVertexArrayObject( vao );',222 'if ( hasChanged ) {',223 ' var vaList = this._cacheVertexAttributeBufferList[ ' + prgID + ' ];',224 ' var va;'225 ];226 for (j = 0, m = listVABuff.length; j < m; j++) {227 vaoSetup.push(' va = vaList[ ' + j + '];');228 vaoSetup.push(' if ( va.isDirty() ) {;');229 vaoSetup.push(' va.bind( gl );');230 vaoSetup.push(' va.compile( gl );');231 vaoSetup.push(' };');232 }233 vaoSetup.push('}');234 autogeneratedFunction = vaoSetup235 .concat(236 this._generatePrimitives(237 validPrimitives,238 hasVertexColor,239 optimizeIndexBufferVAO240 )241 )242 .join('\n');243 functionName = 'GeometryDrawImplementationCacheVAO';244 } else {245 autogeneratedFunction = this._generateVertexSetup(246 validAttributeKeyList,247 validAttributeList,248 false249 )250 .concat(this._generatePrimitives(validPrimitives, hasVertexColor, false))251 .join('\n');252 functionName = 'GeometryDrawImplementationCache';253 }254 /*jshint evil: true */255 // name the function256 // http://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript257 var drawCommand = new Function(258 'state',259 'return function ' + functionName + '( state ) { ' + autogeneratedFunction + '}'260 )();261 /*jshint evil: false */262 this._cacheDrawCall[prgID] = drawCommand;263 return drawCommand;264 };265 })(),266 _getValidPrimitives: function() {267 var validPrimitives = [];268 for (var i = 0; i < this._primitives.length; i++) {269 var primitive = this._primitives[i];270 if (!primitive.getCount()) {271 if (!this._warnInvalidPrimitives) {272 notify.warn(273 'geometry with instanceID ' +274 this._instanceID +275 ' has invalid primitives'276 );277 this._warnInvalidPrimitives = true;278 }279 continue;280 }281 validPrimitives.push(i);282 }283 return validPrimitives;284 },285 drawImplementation: function(state) {286 var program = state.getLastProgramApplied();287 var prgID = program.getInstanceID();288 state.drawGeometry(this);289 var cachedDraw = this._cacheDrawCall[prgID];290 if (!this._vao[prgID]) {291 state.setVertexArrayObject(null);292 } else {293 if (this._vao[prgID].isDirty()) {294 // need vertex array recreation295 // ie: lost context296 cachedDraw = undefined;297 }298 }299 if (cachedDraw) {300 cachedDraw.call(this, state);301 return;302 }303 if (!this._primitives.length) {304 if (!this._warnNoPrimitives) {305 notify.warn(306 'geometry with instanceID ' + this._instanceID + ' has no primitives'307 );308 this._warnNoPrimitives = true;309 }310 return;311 }312 var validPrimitives = this._getValidPrimitives();313 if (!validPrimitives.length) return;314 // generate cachedDraw315 if (this._useVAO === undefined && Geometry.enableVAO) {316 // will be null if not supported317 this._useVAO = WebGLCaps.instance().hasVAO();318 this._glContext = state.getGraphicContext();319 }320 cachedDraw = this.generateDrawCommand(state, program, prgID, validPrimitives);321 cachedDraw.call(this, state);322 state.setVertexArrayObject(null);323 },324 setBound: function(bb) {325 this._boundingBox = bb;326 this._boundingBoxComputed = true;327 },328 computeBoundingBox: function(boundingBox) {329 boundingBox.init();330 var vertexArray = this.getVertexAttributeList().Vertex;331 if (vertexArray && vertexArray.getElements() && vertexArray.getItemSize() > 2) {332 var vertexes = vertexArray.getElements();333 var itemSize = vertexArray.getItemSize();334 var min = boundingBox.getMin();335 var max = boundingBox.getMax();336 var minx = min[0];337 var miny = min[1];338 var minz = min[2];339 var maxx = max[0];340 var maxy = max[1];341 var maxz = max[2];342 // if the box is un-initialized min=Inf and max=-Inf343 // we can't simply write if(x > min) [...] else (x < max) [...]344 // most of the time the else condition is run so it's a kinda useless345 // optimization anyway346 for (var idx = 0, l = vertexes.length; idx < l; idx += itemSize) {347 var v1 = vertexes[idx];348 var v2 = vertexes[idx + 1];349 var v3 = vertexes[idx + 2];350 if (v1 < minx) minx = v1;351 if (v1 > maxx) maxx = v1;352 if (v2 < miny) miny = v2;353 if (v2 > maxy) maxy = v2;354 if (v3 < minz) minz = v3;355 if (v3 > maxz) maxz = v3;356 }357 min[0] = minx;358 min[1] = miny;359 min[2] = minz;360 max[0] = maxx;361 max[1] = maxy;362 max[2] = maxz;363 }364 return boundingBox;365 },366 computeBoundingSphere: function(boundingSphere) {367 boundingSphere.init();368 var bb = this.getBoundingBox();369 boundingSphere.expandByBoundingBox(bb);370 return boundingSphere;371 }372 }),373 'osg',374 'Geometry'375);376Geometry.appendVertexAttributeToList = function(from, to, postfix) {377 for (var key in from) {378 var keyPostFix = key;379 if (postfix !== undefined) keyPostFix += '_' + postfix;380 to[keyPostFix] = from[key];381 }382};...
useLint.ts
Source:useLint.ts
1import {useCallback} from 'react';2import {uniqBy} from 'lodash';3import {syntaxTree} from '@codemirror/language';4import {Diagnostic, LintSource} from '@codemirror/lint';5import {useAppStore} from 'redux/hooks';6import AssertionSelectors from 'selectors/Assertion.selectors';7interface IProps {8 testId: string;9 runId: string;10}11const useLint = ({runId, testId}: IProps): LintSource => {12 const {getState} = useAppStore();13 const getValidAttributeList = useCallback(() => {14 const state = getState();15 const attributeList = uniqBy(AssertionSelectors.selectAllAttributeList(state, testId, runId), 'key');16 return attributeList.map(({key}) => key);17 }, [getState, runId, testId]);18 return useCallback(19 async view => {20 let diagnostics: Diagnostic[] = [];21 const validAttributeList = getValidAttributeList();22 syntaxTree(view.state)23 .cursor()24 .iterate(node => {25 if (node.name === 'Identifier') {26 const attributeName = view.state.doc.sliceString(node.from, node.to);27 if (!validAttributeList.includes(attributeName)) {28 diagnostics.push({29 from: node.from,30 to: node.to,31 severity: 'error',32 message: "Attribute doesn't exist",33 });34 }35 }36 });37 return diagnostics;38 },39 [getValidAttributeList]40 );41};...
Using AI Code Generation
1var tracetest = require('tracetest');2var validAttributeList = tracetest.validAttributeList();3var tracetest = require('tracetest');4var validAttributeList = tracetest.validAttributeList();5var tracetest = require('tracetest');6var validAttributeList = tracetest.validAttributeList();7var tracetest = require('tracetest');8var validAttributeList = tracetest.validAttributeList();9var tracetest = require('tracetest');10var validAttributeList = tracetest.validAttributeList();11var tracetest = require('tracetest');12var validAttributeList = tracetest.validAttributeList();13var tracetest = require('tracetest');14var validAttributeList = tracetest.validAttributeList();15var tracetest = require('tracetest');16var validAttributeList = tracetest.validAttributeList();17var tracetest = require('tracetest');18var validAttributeList = tracetest.validAttributeList();19var tracetest = require('tracetest');20var validAttributeList = tracetest.validAttributeList();21var tracetest = require('tracetest');22var validAttributeList = tracetest.validAttributeList();23var tracetest = require('tracetest');24var validAttributeList = tracetest.validAttributeList();25var tracetest = require('tracetest');26var validAttributeList = tracetest.validAttributeList();
Using AI Code Generation
1var tracetest = require('tracetest');2var valid = tracetest.validAttributeList(['a', 'b', 'c']);3console.log(valid);4exports.validAttributeList = function (attributes) {5 return attributes;6}7exports.validAttributeList = function (attributes) {8 return attributes;9}10exports.validAttributeList = function (attributes) {11 return attributes;12}13exports.validAttributeList = function (attributes) {14 return attributes;15}
Using AI Code Generation
1var traceTest = require('tracetest');2var list = traceTest.validAttributeList();3console.log(list);4exports.validAttributeList = function() {5 return ['a', 'b', 'c'];6};
Using AI Code Generation
1var tracetest = require('tracetest');2var validAttributeList = tracetest.validAttributeList;3var result = validAttributeList('test');4console.log(result);5var tracetest = require('tracetest');6var validAttributeList = tracetest.validAttributeList;7var result = validAttributeList('test');8console.log(result);9{ valid: true, message: 'valid' }10{ valid: true, message: 'valid' }11var tracetest = require('tracetest');12var validAttributeList = tracetest.validAttributeList;13var result = validAttributeList('test');14console.log(result);15{ valid: true, message: 'valid' }16function getItems() {17 {18 },19 {20 }21 ];22 return items;23}
Using AI Code Generation
1var tracetest = require('tracetest');2var trace = new tracetest();3trace.validAttributeList('elementName', 'attributeName', 'attributeValue', callback);4function callback(err, result) {5 if (err) {6 console.log('error');7 } else {8 console.log('result');9 }10}11validAttributeList(elementName, attributeName, attributeValue, callback)12{ 'status': 'success', 'message': 'attribute verified' }13{ 'status': 'error', 'message': 'attribute not verified' }14Copyright (c) 2016, Appium Committers15The software is licensed under the Apache License, Version 2.0 (the "License")
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!!