Best JavaScript code snippet using wpt
shape.js
Source:shape.js
...25 angle: angle26 };27 this.vertices.push(vertex);28 }29 this.updateBounds();30 }31 updateBounds() {32 let x = [];33 let y = [];34 for (var i = 0; i < this.vertices.length; i++) {35 let vertex = this.vertices[i];36 x.push(vertex.x);37 y.push(vertex.y);38 }39 this.bounds = {40 min: {41 x: Math.min(...x),42 y: Math.min(...y)43 },44 max: {45 x: Math.max(...x),46 y: Math.max(...y)47 }48 }49 }50 setRadius(radius) {51 if (radius == this.radius) return;52 this.radius = radius;53 for (var i = 0; i < this.vertices.length; i++) {54 let vertex = this.vertices[i];55 vertex.x = this.position.x + Math.cos(vertex.angle + this.angle) * this.radius;56 vertex.y = this.position.y + Math.sin(vertex.angle + this.angle) * this.radius;57 }58 this.updateBounds();59 }60 scale(x, y) {61 if (x == this.size.x && y == this.size.y) return;62 let sizeDelta = {63 x: x - this.size.x,64 y: y - this.size.y65 }66 this.size.x = x;67 this.size.y = y;68 for (var i = 0; i < this.vertices.length; i++) {69 let vertex = this.vertices[i];70 let vertexDelta = {71 x: vertex.x - this.position.x,72 y: vertex.y - this.position.y73 };74 vertex.x = this.position.x + vertexDelta.x * (1 + sizeDelta.x);75 vertex.y = this.position.y + vertexDelta.y * (1 + sizeDelta.y);76 }77 this.updateBounds();78 }79 translate(x, y) {80 if (x == this.position.x && y == this.position.y) return;81 let delta = {82 x: x - this.position.x,83 y: y - this.position.y84 };85 this.position.x = x;86 this.position.y = y;87 for (var i = 0; i < this.vertices.length; i++) {88 let vertex = this.vertices[i];89 vertex.x += delta.x;90 vertex.y += delta.y;91 }92 this.updateBounds();93 }94 rotate(angle) {95 if (angle == this.angle) return;96 let delta = angle - this.angle;97 this.angle = angle;98 for (var i = 0; i < this.vertices.length; i++) {99 let vertex = this.vertices[i];100 let x = (vertex.x - this.position.x) * Math.cos(delta) - (vertex.y - this.position.y) * Math.sin(delta);101 let y = (vertex.x - this.position.x) * Math.sin(delta) + (vertex.y - this.position.y) * Math.cos(delta);102 vertex.x = this.position.x + x;103 vertex.y = this.position.y + y;104 }105 this.updateBounds();106 }107}108class Rectangle {109 constructor(x, y, width, height) {110 this.position = {111 x: x,112 y: y113 };114 this.size = {115 x: 1,116 y: 1117 };118 this.bounds = {};119 this.angle = 0;120 this.vertices = [];121 this.updateVertices(width, height);122 }123 updateVertices(width, height) {124 this.vertices = [{125 x: this.position.x - width * 0.5,126 y: this.position.y - height * 0.5127 }, {128 x: this.position.x + width * 0.5,129 y: this.position.y - height * 0.5130 }, {131 x: this.position.x + width * 0.5,132 y: this.position.y + height * 0.5133 }, {134 x: this.position.x - width * 0.5,135 y: this.position.y + height * 0.5136 }];137 this.updateBounds();138 }139 updateBounds() {140 let x = [];141 let y = [];142 for (var i = 0; i < this.vertices.length; i++) {143 let vertex = this.vertices[i];144 x.push(vertex.x);145 y.push(vertex.y);146 }147 this.bounds = {148 min: {149 x: Math.min(...x),150 y: Math.min(...y)151 },152 max: {153 x: Math.max(...x),154 y: Math.max(...y)155 }156 }157 }158 scale(x, y) {159 if (x == this.size.x && y == this.size.y) return;160 let sizeDelta = {161 x: x - this.size.x,162 y: y - this.size.y163 }164 this.size.x = x;165 this.size.y = y;166 for (var i = 0; i < this.vertices.length; i++) {167 let vertex = this.vertices[i];168 let vertexDelta = {169 x: vertex.x - this.position.x,170 y: vertex.y - this.position.y171 };172 vertex.x = this.position.x + vertexDelta.x * (1 + sizeDelta.x);173 vertex.y = this.position.y + vertexDelta.y * (1 + sizeDelta.y);174 }175 this.updateBounds();176 }177 translate(x, y) {178 if (x == this.position.x && y == this.position.y) return;179 let delta = {180 x: x - this.position.x,181 y: y - this.position.y182 };183 this.position.x = x;184 this.position.y = y;185 for (var i = 0; i < this.vertices.length; i++) {186 let vertex = this.vertices[i];187 vertex.x += delta.x;188 vertex.y += delta.y;189 }190 this.updateBounds();191 }192 rotate(angle) {193 if (angle == this.angle) return;194 let delta = angle - this.angle;195 this.angle = angle;196 for (var i = 0; i < this.vertices.length; i++) {197 let vertex = this.vertices[i];198 let x = (vertex.x - this.position.x) * Math.cos(delta) - (vertex.y - this.position.y) * Math.sin(delta);199 let y = (vertex.x - this.position.x) * Math.sin(delta) + (vertex.y - this.position.y) * Math.cos(delta);200 vertex.x = this.position.x + x;201 vertex.y = this.position.y + y;202 }203 this.updateBounds();204 }205}206class Polygon {207 constructor(x, y, radius, sides) {208 this.position = {209 x: x,210 y: y211 };212 this.size = {213 x: 1,214 y: 1215 };216 this.bounds = {};217 this.radius = radius;218 this.angle = 0;219 this.vertices = [];220 this.sides = sides;221 this.updateVertices();222 }223 updateVertices(sides) {224 this.sides = sides ? sides : this.sides;225 this.vertices = [];226 for (var angle = -Math.PI; angle < Math.PI; angle += (Math.PI * 2) / this.sides) {227 let vertex = {228 x: this.position.x + Math.cos(angle) * this.radius,229 y: this.position.y + Math.sin(angle) * this.radius,230 angle: angle231 };232 this.vertices.push(vertex);233 }234 this.updateBounds();235 }236 updateBounds() {237 let x = [];238 let y = [];239 for (var i = 0; i < this.vertices.length; i++) {240 let vertex = this.vertices[i];241 x.push(vertex.x);242 y.push(vertex.y);243 }244 this.bounds = {245 min: {246 x: Math.min(...x),247 y: Math.min(...y)248 },249 max: {250 x: Math.max(...x),251 y: Math.max(...y)252 }253 }254 }255 setRadius(radius) {256 if (radius == this.radius) return;257 this.radius = radius;258 for (var i = 0; i < this.vertices.length; i++) {259 let vertex = this.vertices[i];260 vertex.x = this.position.x + Math.cos(vertex.angle + this.angle) * this.radius;261 vertex.y = this.position.y + Math.sin(vertex.angle + this.angle) * this.radius;262 }263 this.updateBounds();264 }265 scale(x, y) {266 if (x == this.size.x && y == this.size.y) return;267 let sizeDelta = {268 x: x - this.size.x,269 y: y - this.size.y270 }271 this.size.x = x;272 this.size.y = y;273 for (var i = 0; i < this.vertices.length; i++) {274 let vertex = this.vertices[i];275 let vertexDelta = {276 x: vertex.x - this.position.x,277 y: vertex.y - this.position.y278 };279 vertex.x = this.position.x + vertexDelta.x * (1 + sizeDelta.x);280 vertex.y = this.position.y + vertexDelta.y * (1 + sizeDelta.y);281 }282 this.updateBounds();283 }284 translate(x, y) {285 if (x == this.position.x && y == this.position.y) return;286 let delta = {287 x: x - this.position.x,288 y: y - this.position.y289 };290 this.position.x = x;291 this.position.y = y;292 for (var i = 0; i < this.vertices.length; i++) {293 let vertex = this.vertices[i];294 vertex.x += delta.x;295 vertex.y += delta.y;296 }297 this.updateBounds();298 }299 rotate(angle) {300 if (angle == this.angle) return;301 let delta = angle - this.angle;302 this.angle = angle;303 for (var i = 0; i < this.vertices.length; i++) {304 let vertex = this.vertices[i];305 let x = (vertex.x - this.position.x) * Math.cos(delta) - (vertex.y - this.position.y) * Math.sin(delta);306 let y = (vertex.x - this.position.x) * Math.sin(delta) + (vertex.y - this.position.y) * Math.cos(delta);307 vertex.x = this.position.x + x;308 vertex.y = this.position.y + y;309 }310 this.updateBounds();311 }312}313module.exports = {314 circle: function(x, y, radius) {315 x = x || 0;316 y = y || 0;317 radius = radius || 0;318 return new Circle(x, y, radius)319 },320 rect: function(x, y, width, height) {321 x = x || 0;322 y = y || 0;323 width = width || 0;324 height = height || 0;...
AbstractRealMaskPoint.js
Source:AbstractRealMaskPoint.js
1(function(){var P$=Clazz.newPackage("net.imglib2.roi.util"),I$=[];2/*c*/var C$=Clazz.newClass(P$, "AbstractRealMaskPoint", null, 'net.imglib2.RealPoint', 'net.imglib2.roi.util.RealLocalizableRealPositionable');3C$.$clinit$=2;4Clazz.newMeth(C$, '$init$', function () {5}, 1);6Clazz.newMeth(C$, 'c$$I', function (n) {7;C$.superclazz.c$$I.apply(this,[n]);C$.$init$.apply(this);8}, 1);9Clazz.newMeth(C$, 'c$$DA', function (pos) {10;C$.superclazz.c$$DA$Z.apply(this,[pos, false]);C$.$init$.apply(this);11}, 1);12Clazz.newMeth(C$, 'c$$net_imglib2_RealLocalizable', function (pos) {13;C$.superclazz.c$$net_imglib2_RealLocalizable.apply(this,[pos]);C$.$init$.apply(this);14}, 1);15Clazz.newMeth(C$, 'move$F$I', function (distance, d) {16C$.superclazz.prototype.move$F$I.apply(this, [distance, d]);17this.updateBounds$();18});19Clazz.newMeth(C$, 'move$D$I', function (distance, d) {20C$.superclazz.prototype.move$D$I.apply(this, [distance, d]);21this.updateBounds$();22});23Clazz.newMeth(C$, 'move$net_imglib2_RealLocalizable', function (distance) {24C$.superclazz.prototype.move$net_imglib2_RealLocalizable.apply(this, [distance]);25this.updateBounds$();26});27Clazz.newMeth(C$, 'move$FA', function (distance) {28C$.superclazz.prototype.move$FA.apply(this, [distance]);29this.updateBounds$();30});31Clazz.newMeth(C$, 'move$DA', function (distance) {32C$.superclazz.prototype.move$DA.apply(this, [distance]);33this.updateBounds$();34});35Clazz.newMeth(C$, 'setPosition$net_imglib2_RealLocalizable', function (position) {36C$.superclazz.prototype.setPosition$net_imglib2_RealLocalizable.apply(this, [position]);37this.updateBounds$();38});39Clazz.newMeth(C$, 'setPosition$FA', function (position) {40C$.superclazz.prototype.setPosition$FA.apply(this, [position]);41this.updateBounds$();42});43Clazz.newMeth(C$, 'setPosition$DA', function (position) {44C$.superclazz.prototype.setPosition$DA.apply(this, [position]);45this.updateBounds$();46});47Clazz.newMeth(C$, 'setPosition$F$I', function (position, d) {48C$.superclazz.prototype.setPosition$F$I.apply(this, [position, d]);49this.updateBounds$();50});51Clazz.newMeth(C$, 'setPosition$D$I', function (position, d) {52C$.superclazz.prototype.setPosition$D$I.apply(this, [position, d]);53this.updateBounds$();54});55Clazz.newMeth(C$, 'fwd$I', function (d) {56C$.superclazz.prototype.fwd$I.apply(this, [d]);57this.updateBounds$();58});59Clazz.newMeth(C$, 'bck$I', function (d) {60C$.superclazz.prototype.bck$I.apply(this, [d]);61this.updateBounds$();62});63Clazz.newMeth(C$, 'move$I$I', function (distance, d) {64C$.superclazz.prototype.move$I$I.apply(this, [distance, d]);65this.updateBounds$();66});67Clazz.newMeth(C$, 'move$J$I', function (distance, d) {68C$.superclazz.prototype.move$J$I.apply(this, [distance, d]);69this.updateBounds$();70});71Clazz.newMeth(C$, 'move$net_imglib2_Localizable', function (localizable) {72C$.superclazz.prototype.move$net_imglib2_Localizable.apply(this, [localizable]);73this.updateBounds$();74});75Clazz.newMeth(C$, 'move$IA', function (distance) {76C$.superclazz.prototype.move$IA.apply(this, [distance]);77this.updateBounds$();78});79Clazz.newMeth(C$, 'move$JA', function (distance) {80C$.superclazz.prototype.move$JA.apply(this, [distance]);81this.updateBounds$();82});83Clazz.newMeth(C$, 'setPosition$net_imglib2_Localizable', function (localizable) {84C$.superclazz.prototype.setPosition$net_imglib2_Localizable.apply(this, [localizable]);85this.updateBounds$();86});87Clazz.newMeth(C$, 'setPosition$IA', function (position) {88C$.superclazz.prototype.setPosition$IA.apply(this, [position]);89this.updateBounds$();90});91Clazz.newMeth(C$, 'setPosition$JA', function (position) {92C$.superclazz.prototype.setPosition$JA.apply(this, [position]);93this.updateBounds$();94});95Clazz.newMeth(C$, 'setPosition$I$I', function (position, d) {96C$.superclazz.prototype.setPosition$I$I.apply(this, [position, d]);97this.updateBounds$();98});99Clazz.newMeth(C$, 'setPosition$J$I', function (position, d) {100C$.superclazz.prototype.setPosition$J$I.apply(this, [position, d]);101this.updateBounds$();102});103Clazz.newMeth(C$);104})();...
useResizeObserver.ts
Source:useResizeObserver.ts
...22 maxY: rect.top + rect.height,23 width: rect.width,24 height: rect.height,25 }26 app.viewport.updateBounds(bounds)27 onBoundsChange?.(bounds)28 }29 } else {30 // Skip the first mount31 rIsMounted.current = true32 }33 }, [app, ref, onBoundsChange])34 React.useEffect(() => {35 window.addEventListener('scroll', updateBounds)36 window.addEventListener('resize', updateBounds)37 return () => {38 window.removeEventListener('scroll', updateBounds)39 window.removeEventListener('resize', updateBounds)40 }41 }, [])42 React.useLayoutEffect(() => {43 const resizeObserver = new ResizeObserver((entries) => {44 if (entries[0].contentRect) {45 updateBounds()46 }47 })48 if (ref.current) {49 resizeObserver.observe(ref.current)50 }51 return () => {52 resizeObserver.disconnect()53 }54 }, [ref])55 React.useLayoutEffect(() => {56 updateBounds()57 }, [ref])...
Using AI Code Generation
1var wptools = require('wptools');2var wp = wptools.page('Albert Einstein');3wp.updateBounds(10, 10, 10, 10, function(err, resp){4 if(err){5 console.log(err);6 }7 else{8 console.log(resp);9 }10});11var wptools = require('wptools');12var wp = wptools.page('Albert Einstein');13wp.getBounds(function(err, resp){14 if(err){15 console.log(err);16 }17 else{18 console.log(resp);19 }20});21var wptools = require('wptools');22var wp = wptools.page('Albert Einstein');23wp.getCoordinates(function(err, resp){24 if(err){25 console.log(err);26 }27 else{28 console.log(resp);29 }30});31var wptools = require('wptools');32var wp = wptools.page('Albert Einstein');33wp.setCoordinates(10, 10, function(err, resp){34 if(err){35 console.log(err);36 }37 else{38 console.log(resp);39 }40});41var wptools = require('wptools');42var wp = wptools.page('Albert Einstein');43wp.getLinks(function(err, resp){44 if(err){45 console.log(err);46 }47 else{48 console.log(resp);49 }50});51var wptools = require('wptools');52var wp = wptools.page('Albert Einstein');53wp.getTemplates(function(err, resp){54 if(err){55 console.log(err);56 }57 else{58 console.log(resp);59 }60});61var wptools = require('wptools');62var wp = wptools.page('Albert Einstein');63wp.getCategories(function(err, resp){64 if(err){65 console.log(err);66 }67 else{68 console.log(resp);69 }70});
Using AI Code Generation
1var wptoolkit = require('wptoolkit')2var bounds = {top: 10, left: 10, bottom: 10, right: 10}3wptoolkit.updateBounds(bounds)4var wptoolkit = require('wptoolkit')5var bounds = {top: 10, left: 10, bottom: 10, right: 10}6wptoolkit.updateBounds(bounds)7var bounds = wptoolkit.getBounds()8console.log(bounds)9var bounds = wptoolkit.getBounds()
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var wpt = new wptoolkit();3wpt.updateBounds(4 {5 },6 function (err, data) {7 if (err) {8 console.log(err);9 }10 else {11 console.log(data);12 }13 }14);15{16}17The updateBounds() method is used to update the bounds of the world. The following methods are used to get the bounds of the world:18getBounds()19getBoundsByToken()
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!!