How to use transform1 method in wpt

Best JavaScript code snippet using wpt

engine.js

Source:engine.js Github

copy

Full Screen

1//jshint maxerr: 100002//CONSTRUCT DOCUMENT3document.body.innerHTML = "<canvas id=\"canvas\"></canvas>" + document.body.innerHTML;4document.head.innerHTML += "<meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width\"><style>canvas{margin:0;border:0;padding:0;}body{margin:0;overflow:hidden;}</style>";5//CLASSES6class Transform {7 constructor(x, y, r) {8 this.x = x;9 this.y = y;10 this.r = r;11 }12}13class FillRenderer {14 constructor(color1, color2, alpha, dir) {15 this.type = "fillRenderer";16 this.color1 = color1;17 this.color2 = color2;18 this.dir = dir;19 this.alpha = alpha;20 }21}22class ImageRenderer {23 constructor(image, alpha, x, y, w, h, hf, vf) {24 this.type = "imageRenderer";25 this.image = image;26 this.x = x;27 this.y = y;28 this.w = w;29 this.h = h;30 this.hf = hf;31 this.vf = vf;32 this.alpha = alpha;33 }34}35class BorderRenderer {36 constructor(color, alpha, lw) {37 this.type = "borderRenderer";38 this.color = color;39 this.lw = lw;40 this.alpha = alpha;41 }42}43class Text {44 constructor(font, text, size) {45 this.type = "text";46 this.text = text;47 this.font = font;48 this.x = x;49 this.y = y;50 this.size = size;51 }52}53class Polygon {54 constructor(tris) {55 this.type = "polygon";56 this.tris = tris;57 }58}59class Tri {60 constructor(points, borders) {61 this.type = "tri";62 this.borders = borders;63 this.points = points;64 }65}66var e = {67 methods: {68 setDimensions: null,69 renderImage: null,70 renderText: null,71 renderPolygon: null,72 calcDistance: null,73 randomNum: null,74 calcAngle: null,75 calcRotationalX: null,76 calcRotationalY: null,77 detectCollision: null,78 clearCanvas: null79 },80 data: {81 w: window.innerWidth,82 h: window.innerHeight,83 element: document.getElementById("canvas"),84 cx: document.getElementById("canvas").getContext("2d"),85 cw: window.innerWidth,86 ch: window.innerHeight,87 mouse: {88 x: 0,89 y: 0,90 clicking: false91 },92 pressedKeys: [93 ],94 camera: {95 x: 0,96 y: 0,97 zoom: 198 }99 }100};101//FUNCTIONS102e.methods.setDimensions = (w, h) => {103 if(w === "full") {104 e.data.element.width = window.innerWidth;105 e.data.w = window.innerWidth;106 e.data.element.height = window.innerHeight;107 e.data.h = window.innerHeight;108 } else {109 e.data.w = w;110 e.data.h = h;111 e.data.element.width = w;112 e.data.element.height = h;113 }114},115e.methods.renderImage = (transform, imageRenderer) => {116 if(transform.x + (imageRenderer.w / 2) >= e.data.camera.x && e.data.camera.x + (e.data.w * e.data.camera.zoom) >= transform.x - (imageRenderer.w / 2) && transform.y - (imageRenderer.h / 2) <= e.data.camera.y && e.data.camera.y - (e.data.h * e.data.camera.zoom) <= transform.y + (imageRenderer.h / 2)) {117 var fc = {118 x: 1,119 y: -1120 };121 e.data.cx.save();122 if(imageRenderer.hf) {123 e.data.cx.scale(-1, 1);124 fc.x = -1;125 } else {126 e.data.cx.scale(1, 1);127 }128 if(imageRenderer.vf) {129 e.data.cx.scale(1, 1);130 fc.y = 1;131 } else {132 e.data.cx.scale(1, -1);133 }134 e.data.cx.globalAlpha = imageRenderer.alpha;135 e.data.cx.translate(((transform.x - e.data.camera.x) / e.data.camera.zoom) * fc.x, ((transform.y - e.data.camera.y) / e.data.camera.zoom) * fc.y);136 e.data.cx.rotate(transform.r * fc.x * fc.y * (Math.PI / 180));137 e.data.cx.drawImage(imageRenderer.image, ((imageRenderer.x / e.data.camera.zoom) * fc.x) - ((imageRenderer.w / e.data.camera.zoom) / 2), ((imageRenderer.y / e.data.camera.zoom) * fc.y) - ((imageRenderer.h / e.data.camera.zoom) / 2), imageRenderer.w / e.data.camera.zoom, imageRenderer.h / e.data.camera.zoom);138 e.data.cx.restore();139 }140},141e.methods.renderText = (transform, text, fillRenderer) => {142 if(transform.x + (text.text.length * text.size) >= e.data.camera.x && e.data.camera.x + (e.data.w * e.data.camera.zoom) >= transform.x && transform.y <= e.data.camera.y && e.data.camera.y - (e.data.h * e.data.camera.zoom) <= transform.y) {143 e.data.cx.save();144 e.data.cx.translate((transform.x - e.data.camera.x) / e.data.camera.zoom, (transform.y - e.data.camera.y) / e.data.camera.zoom);145 e.data.cx.rotate(transform.r * (Math.PI / 180));146 e.data.cx.globalAlpha = fillRenderer.alpha;147 e.data.cx.font = (text.size / e.data.camera.zoom) + "px " + text.font;148 e.data.cx.fillStyle = fillRenderer.color1;149 e.data.cx.fillText(text.text, text.x / e.data.camera.zoom, text.y / e.data.camera.zoom);150 e.data.cx.restore();151 }152},153e.methods.renderPolygon = (transform, polygon, fillRenderer, borderRenderer) => {154 e.data.cx.save();155 e.data.cx.translate((transform.x - e.data.camera.x) / e.data.camera.zoom, (transform.y - e.data.camera.y) / e.data.camera.zoom);156 e.data.cx.rotate(transform.r * (Math.PI / 180));157 let tri = 0;158 for(tri = 0; tri < polygon.tris.length; tri++) {159 e.data.cx.beginPath();160 e.data.cx.moveTo(polygon.tris[tri].points[0].x / e.data.camera.zoom, polygon.tris[tri].points[0].y / e.data.camera.zoom);161 let point = 0;162 for(point = 0; point < polygon.tris[tri].borders; point++) {163 if(point === 2) {164 e.data.cx.lineTo(polygon.tris[tri].points[0].x / e.data.camera.zoom, polygon.tris[tri].points[0].y / e.data.camera.zoom);165 } else {166 e.data.cx.lineTo(polygon.tris[tri].points[point + 1].x / e.data.camera.zoom, polygon.tris[tri].points[point + 1].y / e.data.camera.zoom);167 }168 if(borderRenderer !== null) {169 e.data.cx.globalAlpha = borderRenderer.alpha;170 e.data.cx.lineWidth = borderRenderer.lw / e.data.camera.zoom;171 e.data.cx.strokeStyle = borderRenderer.color;172 e.data.cx.stroke();173 } else {174 e.data.cx.globalAlpha = 0;175 e.data.cx.lineWidth = 0;176 e.data.cx.stroke();177 }178 }179 e.data.cx.beginPath();180 for(point = 0; point < 3; point++) {181 if(point === 2) {182 e.data.cx.lineTo(polygon.tris[tri].points[0].x / e.data.camera.zoom, polygon.tris[tri].points[0].y / e.data.camera.zoom);183 } else {184 e.data.cx.lineTo(polygon.tris[tri].points[point + 1].x / e.data.camera.zoom, polygon.tris[tri].points[point + 1].y / e.data.camera.zoom);185 }186 e.data.cx.globalAlpha = 0;187 e.data.cx.lineWidth = 0;188 e.data.cx.stroke();189 }190 if(fillRenderer !== null) {191 e.data.cx.globalAlpha = fillRenderer.alpha;192 e.data.cx.fillStyle = fillRenderer.color1;193 e.data.cx.fill();194 }195 }196 e.data.cx.restore();197};198e.methods.calcDistance = (transform1, transform2) => {199 return Math.sqrt(Math.pow(transform1.x - transform2.x, 2) + Math.pow(transform1.y - transform2.y, 2));200},201e.methods.randomNum = (min, max) => {202 return Math.floor((Math.random() * (Math.abs(min - max) + 1)) + min);203},204e.methods.calcAngle = (transform1, transform2) => {205 return Math.round(Math.atan2(transform1.y - transform2.y, transform1.x - transform2.x) * 57.2958) + 180;206},207e.methods.calcRotationalVector = (angle) => {208 return new Transform(Math.cos((angle) / 57.2958), Math.sin((angle) / 57.2958));209},210e.methods.addTransform = (transform1, transform2) => {211 return new Transform(transform1.x + transform2.x, transform1.y + transform2.y, transform1.r + transform2.r);212};213e.methods.detectCollision = (transform1, polygon1, transform2, polygon2) => {214 if(polygon1 === null) {215 let tri = 0;216 for(tri = 0; tri < polygon2.tris.length; tri++) {217 let angleTotal = 0;218 let point = 0;219 for(point = 0; point < 3; point++) {220 if(point < 2) {221 if(Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y))) > 180) {222 if(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) < 180) {223 angleTotal += Math.abs((e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) + 360) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));224 } else {225 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - (e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)) + 360));226 }227 } else {228 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));229 }230 } else {231 if(Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y))) > 180) {232 if(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) < 180) {233 angleTotal += Math.abs((e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) + 360) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));234 } else {235 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - (e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)) + 360));236 }237 } else {238 angleTotal += Math.abs(e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(transform1, new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));239 }240 }241 }242 if(angleTotal === 360) {243 return true;244 }245 }246 return false;247 } else {248 let testTri = 0;249 for(testTri = 0; testTri < polygon1.tris.length; testTri++) {250 let testPoint = 0;251 for(testPoint = 0; testPoint < polygon1.tris[testTri].points.length; testPoint++) {252 let tri = 0;253 for(tri = 0; tri < polygon2.tris.length; tri++) {254 let angleTotal = 0;255 let point = 0;256 for(point = 0; point < 3; point++) {257 if(point < 2) {258 if(Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y))) > 180) {259 if(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) < 180) {260 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) + 360) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));261 } else {262 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - (e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)) + 360));263 }264 } else {265 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point].x, transform2.y + polygon2.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[point + 1].x, transform2.y + polygon2.tris[tri].points[point + 1].y)));266 }267 } else {268 if(Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y))) > 180) {269 if(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) < 180) {270 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) + 360) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));271 } else {272 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - (e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)) + 360));273 }274 } else {275 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[2].x, transform2.y + polygon2.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform1.x + polygon1.tris[testTri].points[testPoint].x, transform1.y + polygon1.tris[testTri].points[testPoint].y), new Transform(transform2.x + polygon2.tris[tri].points[0].x, transform2.y + polygon2.tris[tri].points[0].y)));276 }277 }278 }279 if(angleTotal === 360) {280 return true;281 }282 }283 }284 }285 for(testTri = 0; testTri < polygon2.tris.length; testTri++) {286 let testPoint = 0;287 for(testPoint = 0; testPoint < polygon2.tris[testTri].points.length; testPoint++) {288 let tri = 0;289 for(tri = 0; tri < polygon1.tris.length; tri++) {290 let angleTotal = 0;291 let point = 0;292 for(point = 0; point < 3; point++) {293 if(point < 2) {294 if(Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y))) > 180) {295 if(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) < 180) {296 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) + 360) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y)));297 } else {298 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) - (e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y)) + 360));299 }300 } else {301 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point].x, transform1.y + polygon1.tris[tri].points[point].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[point + 1].x, transform1.y + polygon1.tris[tri].points[point + 1].y)));302 }303 } else {304 if(Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y))) > 180) {305 if(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) < 180) {306 angleTotal += Math.abs((e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) + 360) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y)));307 } else {308 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) - (e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y)) + 360));309 }310 } else {311 angleTotal += Math.abs(e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[2].x, transform1.y + polygon1.tris[tri].points[2].y)) - e.methods.calcAngle(new Transform(transform2.x + polygon2.tris[testTri].points[testPoint].x, transform2.y + polygon2.tris[testTri].points[testPoint].y), new Transform(transform1.x + polygon1.tris[tri].points[0].x, transform1.y + polygon1.tris[tri].points[0].y)));312 }313 }314 }315 if(angleTotal === 360) {316 return true;317 }318 }319 }320 }321 return false;322 }323};324e.methods.clearCanvas = (fillRenderer) => {325 e.data.cx.fillStyle = fillRenderer.color1;326 e.data.cx.globalAlpha = 1;327 e.data.cx.fillRect(0, 0, e.data.w, e.data.h);328};329//ADD EVENT LISTENERS330document.addEventListener("keydown", (eObj) => {331 if(!e.data.pressedKeys.includes(eObj.key)) {332 e.data.pressedKeys.push(eObj.key);333 }334});335document.addEventListener("keyup", (eObj) => {336 e.data.pressedKeys.splice(e.data.pressedKeys.indexOf(eObj.key), 1);337});338document.addEventListener("mousemove", (eObj) => {339 e.data.mouse.x = eObj.clientX;340 e.data.mouse.y = eObj.clientY * -1;341});342document.addEventListener("mousedown", () => {343 e.data.mouse.clicking = true;344});345document.addEventListener("mouseup", () => {346 e.data.mouse.clicking = false;347});348//SET FULL CANVAS DIMENSIONS349e.data.element.width = window.innerWidth;350e.data.element.height = window.innerHeight;351//RESCALE CANVAS TO PROPER Y...

Full Screen

Full Screen

transform.js

Source:transform.js Github

copy

Full Screen

1goog.provide('ol.transform');2goog.require('ol.asserts');3/**4 * Collection of affine 2d transformation functions. The functions work on an5 * array of 6 elements. The element order is compatible with the [SVGMatrix6 * interface](https://developer.mozilla.org/en-US/docs/Web/API/SVGMatrix) and is7 * a subset (elements a to f) of a 3x3 martrix:8 * ```9 * [ a c e ]10 * [ b d f ]11 * [ 0 0 1 ]12 * ```13 */14/**15 * @private16 * @type {ol.Transform}17 */18ol.transform.tmp_ = new Array(6);19/**20 * Create an identity transform.21 * @return {!ol.Transform} Identity transform.22 */23ol.transform.create = function() {24 return [1, 0, 0, 1, 0, 0];25};26/**27 * Resets the given transform to an identity transform.28 * @param {!ol.Transform} transform Transform.29 * @return {!ol.Transform} Transform.30 */31ol.transform.reset = function(transform) {32 return ol.transform.set(transform, 1, 0, 0, 1, 0, 0);33};34/**35 * Multiply the underlying matrices of two transforms and return the result in36 * the first transform.37 * @param {!ol.Transform} transform1 Transform parameters of matrix 1.38 * @param {!ol.Transform} transform2 Transform parameters of matrix 2.39 * @return {!ol.Transform} transform1 multiplied with transform2.40 */41ol.transform.multiply = function(transform1, transform2) {42 var a1 = transform1[0];43 var b1 = transform1[1];44 var c1 = transform1[2];45 var d1 = transform1[3];46 var e1 = transform1[4];47 var f1 = transform1[5];48 var a2 = transform2[0];49 var b2 = transform2[1];50 var c2 = transform2[2];51 var d2 = transform2[3];52 var e2 = transform2[4];53 var f2 = transform2[5];54 transform1[0] = a1 * a2 + c1 * b2;55 transform1[1] = b1 * a2 + d1 * b2;56 transform1[2] = a1 * c2 + c1 * d2;57 transform1[3] = b1 * c2 + d1 * d2;58 transform1[4] = a1 * e2 + c1 * f2 + e1;59 transform1[5] = b1 * e2 + d1 * f2 + f1;60 return transform1;61};62/**63 * Set the transform components a-f on a given transform.64 * @param {!ol.Transform} transform Transform.65 * @param {number} a The a component of the transform.66 * @param {number} b The b component of the transform.67 * @param {number} c The c component of the transform.68 * @param {number} d The d component of the transform.69 * @param {number} e The e component of the transform.70 * @param {number} f The f component of the transform.71 * @return {!ol.Transform} Matrix with transform applied.72 */73ol.transform.set = function(transform, a, b, c, d, e, f) {74 transform[0] = a;75 transform[1] = b;76 transform[2] = c;77 transform[3] = d;78 transform[4] = e;79 transform[5] = f;80 return transform;81};82/**83 * Set transform on one matrix from another matrix.84 * @param {!ol.Transform} transform1 Matrix to set transform to.85 * @param {!ol.Transform} transform2 Matrix to set transform from.86 * @return {!ol.Transform} transform1 with transform from transform2 applied.87 */88ol.transform.setFromArray = function(transform1, transform2) {89 transform1[0] = transform2[0];90 transform1[1] = transform2[1];91 transform1[2] = transform2[2];92 transform1[3] = transform2[3];93 transform1[4] = transform2[4];94 transform1[5] = transform2[5];95 return transform1;96};97/**98 * Transforms the given coordinate with the given transform returning the99 * resulting, transformed coordinate. The coordinate will be modified in-place.100 *101 * @param {ol.Transform} transform The transformation.102 * @param {ol.Coordinate|ol.Pixel} coordinate The coordinate to transform.103 * @return {ol.Coordinate|ol.Pixel} return coordinate so that operations can be104 * chained together.105 */106ol.transform.apply = function(transform, coordinate) {107 var x = coordinate[0], y = coordinate[1];108 coordinate[0] = transform[0] * x + transform[2] * y + transform[4];109 coordinate[1] = transform[1] * x + transform[3] * y + transform[5];110 return coordinate;111};112/**113 * Applies rotation to the given transform.114 * @param {!ol.Transform} transform Transform.115 * @param {number} angle Angle in radians.116 * @return {!ol.Transform} The rotated transform.117 */118ol.transform.rotate = function(transform, angle) {119 var cos = Math.cos(angle);120 var sin = Math.sin(angle);121 return ol.transform.multiply(transform,122 ol.transform.set(ol.transform.tmp_, cos, sin, -sin, cos, 0, 0));123};124/**125 * Applies scale to a given transform.126 * @param {!ol.Transform} transform Transform.127 * @param {number} x Scale factor x.128 * @param {number} y Scale factor y.129 * @return {!ol.Transform} The scaled transform.130 */131ol.transform.scale = function(transform, x, y) {132 return ol.transform.multiply(transform,133 ol.transform.set(ol.transform.tmp_, x, 0, 0, y, 0, 0));134};135/**136 * Applies translation to the given transform.137 * @param {!ol.Transform} transform Transform.138 * @param {number} dx Translation x.139 * @param {number} dy Translation y.140 * @return {!ol.Transform} The translated transform.141 */142ol.transform.translate = function(transform, dx, dy) {143 return ol.transform.multiply(transform,144 ol.transform.set(ol.transform.tmp_, 1, 0, 0, 1, dx, dy));145};146/**147 * Creates a composite transform given an initial translation, scale, rotation, and148 * final translation (in that order only, not commutative).149 * @param {!ol.Transform} transform The transform (will be modified in place).150 * @param {number} dx1 Initial translation x.151 * @param {number} dy1 Initial translation y.152 * @param {number} sx Scale factor x.153 * @param {number} sy Scale factor y.154 * @param {number} angle Rotation (in counter-clockwise radians).155 * @param {number} dx2 Final translation x.156 * @param {number} dy2 Final translation y.157 * @return {!ol.Transform} The composite transform.158 */159ol.transform.compose = function(transform, dx1, dy1, sx, sy, angle, dx2, dy2) {160 var sin = Math.sin(angle);161 var cos = Math.cos(angle);162 transform[0] = sx * cos;163 transform[1] = sy * sin;164 transform[2] = -sx * sin;165 transform[3] = sy * cos;166 transform[4] = dx2 * sx * cos - dy2 * sx * sin + dx1;167 transform[5] = dx2 * sy * sin + dy2 * sy * cos + dy1;168 return transform;169};170/**171 * Invert the given transform.172 * @param {!ol.Transform} transform Transform.173 * @return {!ol.Transform} Inverse of the transform.174 */175ol.transform.invert = function(transform) {176 var det = ol.transform.determinant(transform);177 ol.asserts.assert(det !== 0, 32); // Transformation matrix cannot be inverted178 var a = transform[0];179 var b = transform[1];180 var c = transform[2];181 var d = transform[3];182 var e = transform[4];183 var f = transform[5];184 transform[0] = d / det;185 transform[1] = -b / det;186 transform[2] = -c / det;187 transform[3] = a / det;188 transform[4] = (c * f - d * e) / det;189 transform[5] = -(a * f - b * e) / det;190 return transform;191};192/**193 * Returns the determinant of the given matrix.194 * @param {!ol.Transform} mat Matrix.195 * @return {number} Determinant.196 */197ol.transform.determinant = function(mat) {198 return mat[0] * mat[3] - mat[1] * mat[2];...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.error(err);6 wpt.getTestResults(data.data.testId, function(err, data) {7 if (err) return console.error(err);8 console.log(data.data.median.firstView.SpeedIndex);9 });10});11### WebPageTest(options)12### .runTest(url, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var test = new wpt('API_KEY');3var options = {4};5test.runTest(options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test status:', data.statusText);8 test.getTestResults(data.data.testId, function(err, data) {9 if (err) return console.error(err);10 console.log('First View:', data.data.average.firstView);11 console.log('Repeat View:', data.data.average.repeatView);12 });13});14* **Aditya Bhat** - *Initial work* - [adityabhat24](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', '<API KEY>');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9This module was created in 2018 by [Bhavesh Balani](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org', options.key);5 if (err) return console.error(err);6 console.log('Test submitted successfully. View your test at: %s%sresult/%s/', wpt.options.host, wpt.options.path, data.data.testId);7});

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