How to use collide method in storybook-root

Best JavaScript code snippet using storybook-root

p5.collide2d.js

Source:p5.collide2d.js Github

copy

Full Screen

1/*2Repo: https://github.com/bmoren/p5.collide2D/3Created by http://benmoren.com4Some functions and code modified version from http://www.jeffreythompson.org/collision-detection5Version v0.7.3 | June 22, 20206CC BY-NC-SA 4.07*/8console.log("### p5.collide v0.7.3 ###")9p5.prototype._collideDebug = false;10p5.prototype.collideDebug = function(debugMode){11 _collideDebug = debugMode;12}13/*~++~+~+~++~+~++~++~+~+~ 2D ~+~+~++~+~++~+~+~+~+~+~+~+~+~+~+*/14p5.prototype.collideRectRect = function (x, y, w, h, x2, y2, w2, h2) {15 //2d16 //add in a thing to detect rectMode CENTER17 if (x + w >= x2 && // r1 right edge past r2 left18 x <= x2 + w2 && // r1 left edge past r2 right19 y + h >= y2 && // r1 top edge past r2 bottom20 y <= y2 + h2) { // r1 bottom edge past r2 top21 return true;22 }23 return false;24};25// p5.vector version of collideRectRect26p5.prototype.collideRectRectVector = function(p1, sz, p2, sz2){27 return p5.prototype.collideRectRect(p1.x, p1.y, sz.x, sz.y, p2.x, p2.y, sz2.x,sz2.y)28}29p5.prototype.collideRectCircle = function (rx, ry, rw, rh, cx, cy, diameter) {30 //2d31 // temporary variables to set edges for testing32 var testX = cx;33 var testY = cy;34 // which edge is closest?35 if (cx < rx){ testX = rx // left edge36 }else if (cx > rx+rw){ testX = rx+rw } // right edge37 if (cy < ry){ testY = ry // top edge38 }else if (cy > ry+rh){ testY = ry+rh } // bottom edge39 // // get distance from closest edges40 var distance = this.dist(cx,cy,testX,testY)41 // if the distance is less than the radius, collision!42 if (distance <= diameter/2) {43 return true;44 }45 return false;46};47// p5.vector version of collideRectCircle48p5.prototype.collideRectCircleVector = function(r, sz, c, diameter){49 return p5.prototype.collideRectCircle(r.x,r.y, sz.x,sz.y, c.x,c.y, diameter)50}51p5.prototype.collideCircleCircle = function (x, y,d, x2, y2, d2) {52//2d53 if( this.dist(x,y,x2,y2) <= (d/2)+(d2/2) ){54 return true;55 }56 return false;57};58// p5.vector version of collideCircleCircle59p5.prototype.collideCircleCircleVector = function(p1,d, p2, d2){60 return p5.prototype.collideCircleCircle(p1.x,p1.y, d, p2.x,p2.y, d2)61}62p5.prototype.collidePointCircle = function (x, y, cx, cy, d) {63//2d64if( this.dist(x,y,cx,cy) <= d/2 ){65 return true;66}67return false;68};69// p5.vector version of collidePointCircle70p5.prototype.collidePointCircleVector = function(p, c, d){71 return p5.prototype.collidePointCircle(p.x,p.y,c.x,c.y, d)72}73p5.prototype.collidePointEllipse = function (x, y, cx, cy, dx, dy) {74 //2d75 var rx = dx/2, ry = dy/2;76 // Discarding the points outside the bounding box77 if (x > cx + rx || x < cx - rx ||y > cy + ry || y < cy - ry) {78 return false;79 }80 // Compare the point to its equivalent on the ellipse81 var xx = x - cx, yy = y - cy;82 var eyy = ry * this.sqrt(this.abs(rx * rx - xx * xx)) / rx;83 return yy <= eyy && yy >= -eyy;84};85// p5.vector version of collidePointEllipse86p5.prototype.collidePointEllipseVector = function(p, c, d){87 return p5.prototype.collidePointEllipse(p.x,p.y,c.x,c.y,d.x,d.y);88}89p5.prototype.collidePointRect = function (pointX, pointY, x, y, xW, yW) {90//2d91if (pointX >= x && // right of the left edge AND92 pointX <= x + xW && // left of the right edge AND93 pointY >= y && // below the top AND94 pointY <= y + yW) { // above the bottom95 return true;96}97return false;98};99// p5.vector version of collidePointRect100p5.prototype.collidePointRectVector = function(point, p1, sz){101 return p5.prototype.collidePointRect(point.x, point.y, p1.x, p1.y, sz.x, sz.y);102}103p5.prototype.collidePointLine = function(px,py,x1,y1,x2,y2, buffer){104 // get distance from the point to the two ends of the line105var d1 = this.dist(px,py, x1,y1);106var d2 = this.dist(px,py, x2,y2);107// get the length of the line108var lineLen = this.dist(x1,y1, x2,y2);109// since floats are so minutely accurate, add a little buffer zone that will give collision110if (buffer === undefined){ buffer = 0.1; } // higher # = less accurate111// if the two distances are equal to the line's length, the point is on the line!112// note we use the buffer here to give a range, rather than one #113if (d1+d2 >= lineLen-buffer && d1+d2 <= lineLen+buffer) {114 return true;115}116return false;117}118// p5.vector version of collidePointLine119p5.prototype.collidePointLineVector = function(point,p1,p2, buffer){120 return p5.prototype.collidePointLine(point.x,point.y, p1.x,p1.y, p2.x,p2.y, buffer);121}122p5.prototype.collideLineCircle = function( x1, y1, x2, y2, cx, cy, diameter) {123 // is either end INSIDE the circle?124 // if so, return true immediately125 var inside1 = this.collidePointCircle(x1,y1, cx,cy,diameter);126 var inside2 = this.collidePointCircle(x2,y2, cx,cy,diameter);127 if (inside1 || inside2) return true;128 // get length of the line129 var distX = x1 - x2;130 var distY = y1 - y2;131 var len = this.sqrt( (distX*distX) + (distY*distY) );132 // get dot product of the line and circle133 var dot = ( ((cx-x1)*(x2-x1)) + ((cy-y1)*(y2-y1)) ) / this.pow(len,2);134 // find the closest point on the line135 var closestX = x1 + (dot * (x2-x1));136 var closestY = y1 + (dot * (y2-y1));137 // is this point actually on the line segment?138 // if so keep going, but if not, return false139 var onSegment = this.collidePointLine(closestX,closestY,x1,y1,x2,y2);140 if (!onSegment) return false;141 // draw a debug circle at the closest point on the line142 if(this._collideDebug){143 this.ellipse(closestX, closestY,10,10);144 }145 // get distance to closest point146 distX = closestX - cx;147 distY = closestY - cy;148 var distance = this.sqrt( (distX*distX) + (distY*distY) );149 if (distance <= diameter/2) {150 return true;151 }152 return false;153}154// p5.vector version of collideLineCircle155p5.prototype.collideLineCircleVector = function( p1, p2, c, diameter){156 return p5.prototype.collideLineCircle( p1.x, p1.y, p2.x, p2.y, c.x, c.y, diameter);157}158p5.prototype.collideLineLine = function(x1, y1, x2, y2, x3, y3, x4, y4,calcIntersection) {159 var intersection;160 // calculate the distance to intersection point161 var uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));162 var uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));163 // if uA and uB are between 0-1, lines are colliding164 if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {165 if(this._collideDebug || calcIntersection){166 // calc the point where the lines meet167 var intersectionX = x1 + (uA * (x2-x1));168 var intersectionY = y1 + (uA * (y2-y1));169 }170 if(this._collideDebug){171 this.ellipse(intersectionX,intersectionY,10,10);172 }173 if(calcIntersection){174 intersection = {175 "x":intersectionX,176 "y":intersectionY177 }178 return intersection;179 }else{180 return true;181 }182 }183 if(calcIntersection){184 intersection = {185 "x":false,186 "y":false187 }188 return intersection;189 }190 return false;191}192// p5.vector version of collideLineLine193p5.prototype.collideLineLineVector = function(p1, p2, p3, p4, calcIntersection){194 return p5.prototype.collideLineLine(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, calcIntersection);195}196p5.prototype.collideLineRect = function(x1, y1, x2, y2, rx, ry, rw, rh, calcIntersection) {197 // check if the line has hit any of the rectangle's sides. uses the collideLineLine function above198 var left, right, top, bottom, intersection;199 if(calcIntersection){200 left = this.collideLineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh,true);201 right = this.collideLineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh,true);202 top = this.collideLineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry,true);203 bottom = this.collideLineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh,true);204 intersection = {205 "left" : left,206 "right" : right,207 "top" : top,208 "bottom" : bottom209 }210 }else{211 //return booleans212 left = this.collideLineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh);213 right = this.collideLineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh);214 top = this.collideLineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry);215 bottom = this.collideLineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh);216 }217 // if ANY of the above are true, the line has hit the rectangle218 if (left || right || top || bottom) {219 if(calcIntersection){220 return intersection;221 }222 return true;223 }224 return false;225}226// p5.vector version of collideLineRect227p5.prototype.collideLineRectVector = function(p1, p2, r, rsz, calcIntersection){228 return p5.prototype.collideLineRect(p1.x, p1.y, p2.x, p2.y, r.x, r.y, rsz.x, rsz.y, calcIntersection);229}230p5.prototype.collidePointPoly = function(px, py, vertices) {231 var collision = false;232 // go through each of the vertices, plus the next vertex in the list233 var next = 0;234 for (var current=0; current<vertices.length; current++) {235 // get next vertex in list if we've hit the end, wrap around to 0236 next = current+1;237 if (next === vertices.length) next = 0;238 // get the PVectors at our current position this makes our if statement a little cleaner239 var vc = vertices[current]; // c for "current"240 var vn = vertices[next]; // n for "next"241 // compare position, flip 'collision' variable back and forth242 if (((vc.y >= py && vn.y < py) || (vc.y < py && vn.y >= py)) &&243 (px < (vn.x-vc.x)*(py-vc.y) / (vn.y-vc.y)+vc.x)) {244 collision = !collision;245 }246 }247 return collision;248}249// p5.vector version of collidePointPoly250p5.prototype.collidePointPolyVector = function(p1, vertices){251 return p5.prototype.collidePointPoly(p1.x, p1.y, vertices);252}253// POLYGON/CIRCLE254p5.prototype.collideCirclePoly = function(cx, cy, diameter, vertices, interior) {255 if (interior === undefined){256 interior = false;257 }258 // go through each of the vertices, plus the next vertex in the list259 var next = 0;260 for (var current=0; current<vertices.length; current++) {261 // get next vertex in list if we've hit the end, wrap around to 0262 next = current+1;263 if (next === vertices.length) next = 0;264 // get the PVectors at our current position this makes our if statement a little cleaner265 var vc = vertices[current]; // c for "current"266 var vn = vertices[next]; // n for "next"267 // check for collision between the circle and a line formed between the two vertices268 var collision = this.collideLineCircle(vc.x,vc.y, vn.x,vn.y, cx,cy,diameter);269 if (collision) return true;270 }271 // test if the center of the circle is inside the polygon272 if(interior === true){273 var centerInside = this.collidePointPoly(cx,cy, vertices);274 if (centerInside) return true;275 }276 // otherwise, after all that, return false277 return false;278}279// p5.vector version of collideCirclePoly280p5.prototype.collideCirclePolyVector = function(c, diameter, vertices, interior){281 return p5.prototype.collideCirclePoly(c.x, c.y, diameter, vertices, interior);282}283p5.prototype.collideRectPoly = function( rx, ry, rw, rh, vertices, interior) {284 if (interior == undefined){285 interior = false;286 }287 // go through each of the vertices, plus the next vertex in the list288 var next = 0;289 for (var current=0; current<vertices.length; current++) {290 // get next vertex in list if we've hit the end, wrap around to 0291 next = current+1;292 if (next === vertices.length) next = 0;293 // get the PVectors at our current position this makes our if statement a little cleaner294 var vc = vertices[current]; // c for "current"295 var vn = vertices[next]; // n for "next"296 // check against all four sides of the rectangle297 var collision = this.collideLineRect(vc.x,vc.y,vn.x,vn.y, rx,ry,rw,rh);298 if (collision) return true;299 // optional: test if the rectangle is INSIDE the polygon note that this iterates all sides of the polygon again, so only use this if you need to300 if(interior === true){301 var inside = this.collidePointPoly(rx,ry, vertices);302 if (inside) return true;303 }304 }305 return false;306}307// p5.vector version of collideRectPoly308p5.prototype.collideRectPolyVector = function(r, rsz, vertices, interior){309 return p5.prototype.collideRectPoly(r.x, r.y, rsz.x, rsz.y, vertices, interior);310}311p5.prototype.collideLinePoly = function(x1, y1, x2, y2, vertices) {312 // go through each of the vertices, plus the next vertex in the list313 var next = 0;314 for (var current=0; current<vertices.length; current++) {315 // get next vertex in list if we've hit the end, wrap around to 0316 next = current+1;317 if (next === vertices.length) next = 0;318 // get the PVectors at our current position extract X/Y coordinates from each319 var x3 = vertices[current].x;320 var y3 = vertices[current].y;321 var x4 = vertices[next].x;322 var y4 = vertices[next].y;323 // do a Line/Line comparison if true, return 'true' immediately and stop testing (faster)324 var hit = this.collideLineLine(x1, y1, x2, y2, x3, y3, x4, y4);325 if (hit) {326 return true;327 }328 }329 // never got a hit330 return false;331}332// p5.vector version of collideLinePoly333p5.prototype.collideLinePolyVector = function(p1, p2, vertice){334 return p5.prototype.collideLinePoly(p1.x, p1.y, p2.x, p2.y, vertice);335}336p5.prototype.collidePolyPoly = function(p1, p2, interior) {337 if (interior === undefined){338 interior = false;339 }340 // go through each of the vertices, plus the next vertex in the list341 var next = 0;342 for (var current=0; current<p1.length; current++) {343 // get next vertex in list, if we've hit the end, wrap around to 0344 next = current+1;345 if (next === p1.length) next = 0;346 // get the PVectors at our current position this makes our if statement a little cleaner347 var vc = p1[current]; // c for "current"348 var vn = p1[next]; // n for "next"349 //use these two points (a line) to compare to the other polygon's vertices using polyLine()350 var collision = this.collideLinePoly(vc.x,vc.y,vn.x,vn.y,p2);351 if (collision) return true;352 //check if the either polygon is INSIDE the other353 if(interior === true){354 collision = this.collidePointPoly(p2[0].x, p2[0].y, p1);355 if (collision) return true;356 collision = this.collidePointPoly(p1[0].x, p1[0].y, p2);357 if (collision) return true;358 }359 }360 return false;361}362p5.prototype.collidePolyPolyVector = function(p1, p2, interior) {363 return p5.prototype.collidePolyPoly(p1, p2, interior);364}365p5.prototype.collidePointTriangle = function(px, py, x1, y1, x2, y2, x3, y3) {366 // get the area of the triangle367 var areaOrig = this.abs( (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1) );368 // get the area of 3 triangles made between the point and the corners of the triangle369 var area1 = this.abs( (x1-px)*(y2-py) - (x2-px)*(y1-py) );370 var area2 = this.abs( (x2-px)*(y3-py) - (x3-px)*(y2-py) );371 var area3 = this.abs( (x3-px)*(y1-py) - (x1-px)*(y3-py) );372 // if the sum of the three areas equals the original, we're inside the triangle!373 if (area1 + area2 + area3 === areaOrig) {374 return true;375 }376 return false;377}378// p5.vector version of collidePointTriangle379p5.prototype.collidePointTriangleVector = function(p, p1, p2, p3){380 return p5.prototype.collidePointTriangle(p.x, p.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);381}382p5.prototype.collidePointPoint = function (x,y,x2,y2, buffer) {383 if(buffer === undefined){384 buffer = 0;385 }386 if(this.dist(x,y,x2,y2) <= buffer){387 return true;388 }389 return false;390};391// p5.vector version of collidePointPoint392p5.prototype.collidePointPointVector = function(p1, p2, buffer){393 return p5.prototype.collidePointPoint(p1.x,p1.y,p2.x,p2.y, buffer);394}395p5.prototype.collidePointArc = function(px, py, ax, ay, arcRadius, arcHeading, arcAngle, buffer) {396 if (buffer === undefined) {397 buffer = 0;398 }399 // point400 var point = this.createVector(px, py);401 // arc center point402 var arcPos = this.createVector(ax, ay);403 // arc radius vector404 var radius = this.createVector(arcRadius, 0).rotate(arcHeading);405 var pointToArc = point.copy().sub(arcPos);406 if (point.dist(arcPos) <= (arcRadius + buffer)) {407 var dot = radius.dot(pointToArc);408 var angle = radius.angleBetween(pointToArc);409 if (dot > 0 && angle <= arcAngle / 2 && angle >= -arcAngle / 2) {410 return true;411 }412 }413 return false;414}415// p5.vector version of collidePointArc416p5.prototype.collidePointArcVector = function(p1, a, arcRadius, arcHeading, arcAngle, buffer){417 return p5.prototype.collidePointArc(p1.x, p1.y, a.x, a.y, arcRadius, arcHeading, arcAngle, buffer);...

Full Screen

Full Screen

Tile.js

Source:Tile.js Github

copy

Full Screen

1/**2* @author Richard Davey <rich@photonstorm.com>3* @copyright 2016 Photon Storm Ltd.4* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}5*/6/**7* A Tile is a representation of a single tile within the Tilemap.8*9* @class Phaser.Tile10* @constructor11* @param {object} layer - The layer in the Tilemap data that this tile belongs to.12* @param {number} index - The index of this tile type in the core map data.13* @param {number} x - The x coordinate of this tile.14* @param {number} y - The y coordinate of this tile.15* @param {number} width - Width of the tile.16* @param {number} height - Height of the tile.17*/18Phaser.Tile = function (layer, index, x, y, width, height) {19 /**20 * @property {object} layer - The layer in the Tilemap data that this tile belongs to.21 */22 this.layer = layer;23 /**24 * @property {number} index - The index of this tile within the map data corresponding to the tileset, or -1 if this represents a blank/null tile.25 */26 this.index = index;27 /**28 * @property {number} x - The x map coordinate of this tile.29 */30 this.x = x;31 /**32 * @property {number} y - The y map coordinate of this tile.33 */34 this.y = y;35 36 /**37 * @property {number} rotation - The rotation angle of this tile.38 */39 this.rotation = 0;40 /**41 * @property {boolean} flipped - Whether this tile is flipped (mirrored) or not.42 */43 this.flipped = false;44 45 /**46 * @property {number} x - The x map coordinate of this tile.47 */48 this.worldX = x * width;49 /**50 * @property {number} y - The y map coordinate of this tile.51 */52 this.worldY = y * height;53 /**54 * @property {number} width - The width of the tile in pixels.55 */56 this.width = width;57 /**58 * @property {number} height - The height of the tile in pixels.59 */60 this.height = height;61 /**62 * @property {number} width - The width of the tile in pixels.63 */64 this.centerX = Math.abs(width / 2);65 /**66 * @property {number} height - The height of the tile in pixels.67 */68 this.centerY = Math.abs(height / 2);69 /**70 * @property {number} alpha - The alpha value at which this tile is drawn to the canvas.71 */72 this.alpha = 1;73 /**74 * @property {object} properties - Tile specific properties.75 */76 this.properties = {};77 /**78 * @property {boolean} scanned - Has this tile been walked / turned into a poly?79 */80 this.scanned = false;81 /**82 * @property {boolean} faceTop - Is the top of this tile an interesting edge?83 */84 this.faceTop = false;85 /**86 * @property {boolean} faceBottom - Is the bottom of this tile an interesting edge?87 */88 this.faceBottom = false;89 /**90 * @property {boolean} faceLeft - Is the left of this tile an interesting edge?91 */92 this.faceLeft = false;93 /**94 * @property {boolean} faceRight - Is the right of this tile an interesting edge?95 */96 this.faceRight = false;97 /**98 * @property {boolean} collideLeft - Indicating collide with any object on the left.99 * @default100 */101 this.collideLeft = false;102 /**103 * @property {boolean} collideRight - Indicating collide with any object on the right.104 * @default105 */106 this.collideRight = false;107 /**108 * @property {boolean} collideUp - Indicating collide with any object on the top.109 * @default110 */111 this.collideUp = false;112 /**113 * @property {boolean} collideDown - Indicating collide with any object on the bottom.114 * @default115 */116 this.collideDown = false;117 /**118 * @property {function} collisionCallback - Tile collision callback.119 * @default120 */121 this.collisionCallback = null;122 /**123 * @property {object} collisionCallbackContext - The context in which the collision callback will be called.124 * @default125 */126 this.collisionCallbackContext = this;127};128Phaser.Tile.prototype = {129 /**130 * Check if the given x and y world coordinates are within this Tile.131 *132 * @method Phaser.Tile#containsPoint133 * @param {number} x - The x coordinate to test.134 * @param {number} y - The y coordinate to test.135 * @return {boolean} True if the coordinates are within this Tile, otherwise false.136 */137 containsPoint: function (x, y) {138 return !(x < this.worldX || y < this.worldY || x > this.right || y > this.bottom);139 },140 /**141 * Check for intersection with this tile.142 *143 * @method Phaser.Tile#intersects144 * @param {number} x - The x axis in pixels.145 * @param {number} y - The y axis in pixels.146 * @param {number} right - The right point.147 * @param {number} bottom - The bottom point.148 */149 intersects: function (x, y, right, bottom) {150 if (right <= this.worldX)151 {152 return false;153 }154 if (bottom <= this.worldY)155 {156 return false;157 }158 if (x >= this.worldX + this.width)159 {160 return false;161 }162 if (y >= this.worldY + this.height)163 {164 return false;165 }166 return true;167 },168 /**169 * Set a callback to be called when this tile is hit by an object.170 * The callback must true true for collision processing to take place.171 *172 * @method Phaser.Tile#setCollisionCallback173 * @param {function} callback - Callback function.174 * @param {object} context - Callback will be called within this context.175 */176 setCollisionCallback: function (callback, context) {177 this.collisionCallback = callback;178 this.collisionCallbackContext = context;179 },180 /**181 * Clean up memory.182 *183 * @method Phaser.Tile#destroy184 */185 destroy: function () {186 this.collisionCallback = null;187 this.collisionCallbackContext = null;188 this.properties = null;189 },190 /**191 * Sets the collision flags for each side of this tile and updates the interesting faces list.192 *193 * @method Phaser.Tile#setCollision194 * @param {boolean} left - Indicating collide with any object on the left.195 * @param {boolean} right - Indicating collide with any object on the right.196 * @param {boolean} up - Indicating collide with any object on the top.197 * @param {boolean} down - Indicating collide with any object on the bottom.198 */199 setCollision: function (left, right, up, down) {200 this.collideLeft = left;201 this.collideRight = right;202 this.collideUp = up;203 this.collideDown = down;204 this.faceLeft = left;205 this.faceRight = right;206 this.faceTop = up;207 this.faceBottom = down;208 },209 /**210 * Reset collision status flags.211 *212 * @method Phaser.Tile#resetCollision213 */214 resetCollision: function () {215 this.collideLeft = false;216 this.collideRight = false;217 this.collideUp = false;218 this.collideDown = false;219 this.faceTop = false;220 this.faceBottom = false;221 this.faceLeft = false;222 this.faceRight = false;223 },224 /**225 * Is this tile interesting?226 *227 * @method Phaser.Tile#isInteresting228 * @param {boolean} collides - If true will check any collides value.229 * @param {boolean} faces - If true will check any face value.230 * @return {boolean} True if the Tile is interesting, otherwise false.231 */232 isInteresting: function (collides, faces) {233 if (collides && faces)234 {235 // Does this tile have any collide flags OR interesting face?236 return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown || this.faceTop || this.faceBottom || this.faceLeft || this.faceRight || this.collisionCallback);237 }238 else if (collides)239 {240 // Does this tile collide?241 return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown);242 }243 else if (faces)244 {245 // Does this tile have an interesting face?246 return (this.faceTop || this.faceBottom || this.faceLeft || this.faceRight);247 }248 return false;249 },250 /**251 * Copies the tile data and properties from the given tile to this tile.252 *253 * @method Phaser.Tile#copy254 * @param {Phaser.Tile} tile - The tile to copy from.255 */256 copy: function (tile) {257 this.index = tile.index;258 this.alpha = tile.alpha;259 this.properties = tile.properties;260 this.collideUp = tile.collideUp;261 this.collideDown = tile.collideDown;262 this.collideLeft = tile.collideLeft;263 this.collideRight = tile.collideRight;264 this.collisionCallback = tile.collisionCallback;265 this.collisionCallbackContext = tile.collisionCallbackContext;266 }267};268Phaser.Tile.prototype.constructor = Phaser.Tile;269/**270* @name Phaser.Tile#collides271* @property {boolean} collides - True if this tile can collide on any of its faces.272* @readonly273*/274Object.defineProperty(Phaser.Tile.prototype, "collides", {275 get: function () {276 return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown);277 }278});279/**280* @name Phaser.Tile#canCollide281* @property {boolean} canCollide - True if this tile can collide on any of its faces or has a collision callback set.282* @readonly283*/284Object.defineProperty(Phaser.Tile.prototype, "canCollide", {285 get: function () {286 return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown || this.collisionCallback);287 }288});289/**290* @name Phaser.Tile#left291* @property {number} left - The x value in pixels.292* @readonly293*/294Object.defineProperty(Phaser.Tile.prototype, "left", {295 get: function () {296 return this.worldX;297 }298});299/**300* @name Phaser.Tile#right301* @property {number} right - The sum of the x and width properties.302* @readonly303*/304Object.defineProperty(Phaser.Tile.prototype, "right", {305 get: function () {306 return this.worldX + this.width;307 }308});309/**310* @name Phaser.Tile#top311* @property {number} top - The y value.312* @readonly313*/314Object.defineProperty(Phaser.Tile.prototype, "top", {315 get: function () {316 return this.worldY;317 }318});319/**320* @name Phaser.Tile#bottom321* @property {number} bottom - The sum of the y and height properties.322* @readonly323*/324Object.defineProperty(Phaser.Tile.prototype, "bottom", {325 get: function () {326 return this.worldY + this.height;327 }...

Full Screen

Full Screen

p5.collide2d.min.js

Source:p5.collide2d.min.js Github

copy

Full Screen

1console.log(""), p5.prototype._collideDebug = !1, p5.prototype.collideDebug = function (t) {2 _collideDebug = t3}, p5.prototype.collideRectRect = function (t, o, e, i, r, l, n, c) {4 return t + e >= r && t <= r + n && o + i >= l && o <= l + c5}, p5.prototype.collideRectRectVector = function (t, o, e, i) {6 return p5.prototype.collideRectRect(t.x, t.y, o.x, o.y, e.x, e.y, i.x, i.y)7}, p5.prototype.collideRectCircle = function (t, o, e, i, r, l, n) {8 var c = r,9 p = l;10 return r < t ? c = t : r > t + e && (c = t + e), l < o ? p = o : l > o + i && (p = o + i), this.dist(r, l, c, p) <= n / 211}, p5.prototype.collideRectCircleVector = function (t, o, e, i) {12 return p5.prototype.collideRectCircle(t.x, t.y, o.x, o.y, e.x, e.y, i)13}, p5.prototype.collideCircleCircle = function (t, o, e, i, r, l) {14 return this.dist(t, o, i, r) <= e / 2 + l / 215}, p5.prototype.collideCircleCircleVector = function (t, o, e, i) {16 return p5.prototype.collideCircleCircle(t.x, t.y, o, e.x, e.y, i)17}, p5.prototype.collidePointCircle = function (t, o, e, i, r) {18 return this.dist(t, o, e, i) <= r / 219}, p5.prototype.collidePointCircleVector = function (t, o, e) {20 return p5.prototype.collidePointCircle(t.x, t.y, o.x, o.y, e)21}, p5.prototype.collidePointEllipse = function (t, o, e, i, r, l) {22 var n = r / 2,23 c = l / 2;24 if (t > e + n || t < e - n || o > i + c || o < i - c) return !1;25 var p = t - e,26 y = o - i,27 d = c * this.sqrt(this.abs(n * n - p * p)) / n;28 return y <= d && y >= -d29}, p5.prototype.collidePointEllipseVector = function (t, o, e) {30 return p5.prototype.collidePointEllipse(t.x, t.y, o.x, o.y, e.x, e.y)31}, p5.prototype.collidePointRect = function (t, o, e, i, r, l) {32 return t >= e && t <= e + r && o >= i && o <= i + l33}, p5.prototype.collidePointRectVector = function (t, o, e) {34 return p5.prototype.collidePointRect(t.x, t.y, o.x, o.y, e.x, e.y)35}, p5.prototype.collidePointLine = function (t, o, e, i, r, l, n) {36 var c = this.dist(t, o, e, i),37 p = this.dist(t, o, r, l),38 y = this.dist(e, i, r, l);39 return void 0 === n && (n = .1), c + p >= y - n && c + p <= y + n40}, p5.prototype.collidePointLineVector = function (t, o, e, i) {41 return p5.prototype.collidePointLine(t.x, t.y, o.x, o.y, e.x, e.y, i)42}, p5.prototype.collideLineCircle = function (t, o, e, i, r, l, n) {43 var c = this.collidePointCircle(t, o, r, l, n),44 p = this.collidePointCircle(e, i, r, l, n);45 if (c || p) return !0;46 var y = t - e,47 d = o - i,48 u = this.sqrt(y * y + d * d),49 s = ((r - t) * (e - t) + (l - o) * (i - o)) / this.pow(u, 2),50 x = t + s * (e - t),51 f = o + s * (i - o);52 return !!this.collidePointLine(x, f, t, o, e, i) && (this._collideDebug && this.ellipse(x, f, 10, 10), y = x - r, d = f - l, this.sqrt(y * y + d * d) <= n / 2)53}, p5.prototype.collideLineCircleVector = function (t, o, e, i) {54 return p5.prototype.collideLineCircle(t.x, t.y, o.x, o.y, e.x, e.y, i)55}, p5.prototype.collideLineLine = function (t, o, e, i, r, l, n, c, p) {56 var y = ((n - r) * (o - l) - (c - l) * (t - r)) / ((c - l) * (e - t) - (n - r) * (i - o)),57 d = ((e - t) * (o - l) - (i - o) * (t - r)) / ((c - l) * (e - t) - (n - r) * (i - o));58 if (y >= 0 && y <= 1 && d >= 0 && d <= 1) {59 if (this._collideDebug || p) var u = t + y * (e - t),60 s = o + y * (i - o);61 return this._collideDebug && this.ellipse(u, s, 10, 10), !p || {62 x: u,63 y: s64 }65 }66 return !!p && {67 x: !1,68 y: !169 }70}, p5.prototype.collideLineLineVector = function (t, o, e, i, r) {71 return p5.prototype.collideLineLine(t.x, t.y, o.x, o.y, e.x, e.y, i.x, i.y, r)72}, p5.prototype.collideLineRect = function (t, o, e, i, r, l, n, c, p) {73 var y, d, u, s, x;74 return p ? x = {75 left: y = this.collideLineLine(t, o, e, i, r, l, r, l + c, !0),76 right: d = this.collideLineLine(t, o, e, i, r + n, l, r + n, l + c, !0),77 top: u = this.collideLineLine(t, o, e, i, r, l, r + n, l, !0),78 bottom: s = this.collideLineLine(t, o, e, i, r, l + c, r + n, l + c, !0)79 } : (y = this.collideLineLine(t, o, e, i, r, l, r, l + c), d = this.collideLineLine(t, o, e, i, r + n, l, r + n, l + c), u = this.collideLineLine(t, o, e, i, r, l, r + n, l), s = this.collideLineLine(t, o, e, i, r, l + c, r + n, l + c)), !!(y || d || u || s) && (!p || x)80}, p5.prototype.collideLineRectVector = function (t, o, e, i, r) {81 return p5.prototype.collideLineRect(t.x, t.y, o.x, o.y, e.x, e.y, i.x, i.y, r)82}, p5.prototype.collidePointPoly = function (t, o, e) {83 for (var i = !1, r = 0, l = 0; l < e.length; l++) {84 (r = l + 1) === e.length && (r = 0);85 var n = e[l],86 c = e[r];87 (n.y >= o && c.y < o || n.y < o && c.y >= o) && t < (c.x - n.x) * (o - n.y) / (c.y - n.y) + n.x && (i = !i)88 }89 return i90}, p5.prototype.collidePointPolyVector = function (t, o) {91 return p5.prototype.collidePointPoly(t.x, t.y, o)92}, p5.prototype.collideCirclePoly = function (t, o, e, i, r) {93 void 0 === r && (r = !1);94 for (var l = 0, n = 0; n < i.length; n++) {95 (l = n + 1) === i.length && (l = 0);96 var c = i[n],97 p = i[l];98 if (this.collideLineCircle(c.x, c.y, p.x, p.y, t, o, e)) return !099 }100 if (!0 === r && this.collidePointPoly(t, o, i)) return !0;101 return !1102}, p5.prototype.collideCirclePolyVector = function (t, o, e, i) {103 return p5.prototype.collideCirclePoly(t.x, t.y, o, e, i)104}, p5.prototype.collideRectPoly = function (t, o, e, i, r, l) {105 null == l && (l = !1);106 for (var n = 0, c = 0; c < r.length; c++) {107 (n = c + 1) === r.length && (n = 0);108 var p = r[c],109 y = r[n];110 if (this.collideLineRect(p.x, p.y, y.x, y.y, t, o, e, i)) return !0;111 if (!0 === l)112 if (this.collidePointPoly(t, o, r)) return !0113 }114 return !1115}, p5.prototype.collideRectPolyVector = function (t, o, e, i) {116 return p5.prototype.collideRectPoly(t.x, t.y, o.x, o.y, e, i)117}, p5.prototype.collideLinePoly = function (t, o, e, i, r) {118 for (var l = 0, n = 0; n < r.length; n++) {119 (l = n + 1) === r.length && (l = 0);120 var c = r[n].x,121 p = r[n].y,122 y = r[l].x,123 d = r[l].y;124 if (this.collideLineLine(t, o, e, i, c, p, y, d)) return !0125 }126 return !1127}, p5.prototype.collideLinePolyVector = function (t, o, e) {128 return p5.prototype.collideLinePoly(t.x, t.y, o.x, o.y, e)129}, p5.prototype.collidePolyPoly = function (t, o, e) {130 void 0 === e && (e = !1);131 for (var i = 0, r = 0; r < t.length; r++) {132 (i = r + 1) === t.length && (i = 0);133 var l = t[r],134 n = t[i],135 c = this.collideLinePoly(l.x, l.y, n.x, n.y, o);136 if (c) return !0;137 if (!0 === e) {138 if (c = this.collidePointPoly(o[0].x, o[0].y, t)) return !0;139 if (c = this.collidePointPoly(t[0].x, t[0].y, o)) return !0140 }141 }142 return !1143}, p5.prototype.collidePolyPolyVector = function (t, o, e) {144 return p5.prototype.collidePolyPoly(t, o, e)145}, p5.prototype.collidePointTriangle = function (t, o, e, i, r, l, n, c) {146 var p = this.abs((r - e) * (c - i) - (n - e) * (l - i));147 return this.abs((e - t) * (l - o) - (r - t) * (i - o)) + this.abs((r - t) * (c - o) - (n - t) * (l - o)) + this.abs((n - t) * (i - o) - (e - t) * (c - o)) === p148}, p5.prototype.collidePointTriangleVector = function (t, o, e, i) {149 return p5.prototype.collidePointTriangle(t.x, t.y, o.x, o.y, e.x, e.y, i.x, i.y)150}, p5.prototype.collidePointPoint = function (t, o, e, i, r) {151 return void 0 === r && (r = 0), this.dist(t, o, e, i) <= r152}, p5.prototype.collidePointPointVector = function (t, o, e) {153 return p5.prototype.collidePointPoint(t.x, t.y, o.x, o.y, e)154}, p5.prototype.collidePointArc = function (t, o, e, i, r, l, n, c) {155 void 0 === c && (c = 0);156 var p = this.createVector(t, o),157 y = this.createVector(e, i),158 d = this.createVector(r, 0).rotate(l),159 u = p.copy().sub(y);160 if (p.dist(y) <= r + c) {161 var s = d.dot(u),162 x = d.angleBetween(u);163 if (s > 0 && x <= n / 2 && x >= -n / 2) return !0164 }165 return !1166}, p5.prototype.collidePointArcVector = function (t, o, e, i, r, l) {167 return p5.prototype.collidePointArc(t.x, t.y, o.x, o.y, e, i, r, l)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { linkTo } from '@storybook/addon-links';5import { Button, Welcome } from '@storybook/react/demo';6import { Button as Button2 } from 'antd';7import { Button as Button3 } from 'antd';8import { Button as Button4 } from 'antd';9import { Button as Button5 } from 'antd';10import { Button as Button6 } from 'antd';11import { Button as Button7 } from 'antd';12import { Button as Button8 } from 'antd';13import { Button as Button9 } from 'antd';14import { Button as Button10 } from 'antd';15import { Button as Button11 } from 'antd';16import { Button as Button12 } from 'antd';17import { Button as Button13 } from 'antd';18import { Button as Button14 } from 'antd';19import { Button as Button15 } from 'antd';20import { Button as Button16 } from 'antd';21import { Button as Button17 } from 'antd';22import { Button as Button18 } from 'antd';23import { Button as Button19 } from 'antd';24import { Button as Button20 } from 'antd';25import { Button as Button21 } from 'antd';26import { Button as Button22 } from 'antd';27import { Button as Button23 } from 'antd';28import { Button as Button24 } from 'antd';29import { Button as Button25 } from 'antd';30import { Button as Button26 } from 'antd';31import { Button as Button27 } from 'antd';32import { Button as Button28 } from 'antd';33import { Button as Button29 } from 'antd';34import { Button as Button30 } from 'antd';35import { Button as Button31 } from 'antd';36import { Button as Button32 } from 'antd';37import { Button as Button33 } from 'antd';38import { Button as Button34 } from 'antd';39import { Button as Button35 } from 'antd';40import { Button as Button36 } from 'antd';41import { Button as Button37 } from 'antd';42import { Button as Button38 } from 'antd';43import { Button as Button39 } from 'antd';44import { Button as Button40 } from 'antd';45import { Button as Button41 } from 'antd';46import { Button as Button42 } from

Full Screen

Using AI Code Generation

copy

Full Screen

1import React from 'react';2import {storiesOf} from '@storybook/react';3import {action} from '@storybook/addon-actions';4import {withInfo} from '@storybook/addon-info';5import {withKnobs, text, boolean, number} from '@storybook/addon-knobs';6import {withA11y} from '@storybook/addon-a11y';7import {Collide} from '../../src';8import readme from '../../src/Collide/README.md';9const stories = storiesOf('Collide', module);10stories.addDecorator(withKnobs);11stories.addDecorator(withA11y);12stories.addDecorator(withInfo);13stories.addParameters({14 readme: {15 },16 options: {},17});18stories.add(19 () => (20 onCollide={action('onCollide')}21 onCollideEnd={action('onCollideEnd')}22 onCollideStart={action('onCollideStart')}23 enabled={boolean('enabled', true)}24 debug={boolean('debug', false)}25 onHit={action('onHit')}26 onHitEnd={action('onHitEnd')}27 onHitStart={action('onHitStart')}28 onMiss={action('onMiss')}29 onMissEnd={action('onMissEnd')}30 onMissStart={action('onMissStart')}31 onCollideGroup={action('onCollideGroup')}32 onCollideGroupEnd={action('onCollideGroupEnd')}33 onCollideGroupStart={action('onCollideGroupStart')}34 onHitGroup={action('onHitGroup')}35 onHitGroupEnd={action('onHitGroupEnd')}36 onHitGroupStart={action('onHitGroupStart')}37 onMissGroup={action('onMissGroup')}38 onMissGroupEnd={action('onMissGroupEnd')}39 onMissGroupStart={action('onMissGroupStart')}40 onCollideWith={action('onCollideWith')}41 onCollideWithEnd={action('onCollideWithEnd')}42 onCollideWithStart={action('onCollideWithStart')}43 onHitWith={action('onHitWith')}44 onHitWithEnd={action('onHitWithEnd')}45 onHitWithStart={action('onHitWithStart')}46 onMissWith={action('onMissWith')}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { collide } from 'storybook-root';2collide();3{4 "dependencies": {5 }6}7import _ from 'lodash';8export const collide = () => {9 console.log(_.camelCase('Hello World'));10}11import { collide } from 'storybook-root';12collide();13{14 "dependencies": {15 }16}17import _ from 'lodash';18export const collide = () => {19 console.log(_.camelCase('Hello World'));20}21import { collide } from 'storybook-root';22collide();23{24 "dependencies": {25 }26}27import _ from 'lodash';28export const collide = () =>

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Collide } from 'storybook-root';2import { Collide } from 'storybook-root/dist/collide';3import { Collide } from 'storybook-root';4import { Collide } from 'storybook-root/dist/collide';5import { Collide } from 'storybook-root';6import { Collide } from 'storybook-root/dist/collide';7import { Collide } from 'storybook-root';8import { Collide } from 'storybook-root/dist/collide';9import { Collide } from 'storybook-root';10import { Collide } from 'storybook-root/dist/collide';11import { Collide } from 'storybook-root';12import { Collide } from 'storybook-root/dist/collide';13import { Collide } from 'storybook-root';14import { Collide } from 'storybook-root/dist/collide';15import { Collide } from 'storybook-root';16import { Collide } from 'storybook-root/dist/collide';17import { Collide } from 'storybook-root';18import { Collide } from 'storybook-root/dist/collide';19import { Collide } from 'storybook-root';20import { Collide } from 'storybook-root/dist/collide';21import { Collide } from 'storybook-root';22import { Collide } from 'storybook-root/dist/collide';23import { Collide } from 'storybook-root';24import { Collide } from 'storybook-root/dist/coll

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Collide } from 'storybook-root';2import { Collide } from 'storybook-root';3import { Collide } from 'storybook-root';4import { Collide } from 'storybook-root';5import { Collide } from 'storybook-root';6import { Collide } from 'storybook-root';7import { Collide } from 'storybook-root';8import { Collide } from 'storybook-root';9import { Collide } from 'storybook-root';10import { Collide } from 'storybook-root';11import { Collide } from 'storybook-root';12import { Collide } from 'storybook-root';13import { Collide } from 'storybook-root';14import { Collide } from 'storybook-root';15import { Collide } from 'storybook-root';16import { Collide } from 'storybook-root';17import { Collide } from 'storybook-root';18import { Collide } from 'storybook-root';19import { Collide } from 'storybook-root';20import { Collide } from 'storybook-root';21import { Collide } from 'storybook-root';

Full Screen

Using AI Code Generation

copy

Full Screen

1const storybookRoot = document.querySelector('storybook-root');2const storybookRootRect = storybookRoot.getBoundingClientRect();3const storybookRootStyle = window.getComputedStyle(storybookRoot);4const storybookRootWidth = storybookRootRect.width - parseInt(storybookRootStyle.paddingLeft) - parseInt(storybookRootStyle.paddingRight);5const storybookRootHeight = storybookRootRect.height - parseInt(storybookRootStyle.paddingTop) - parseInt(storybookRootStyle.paddingBottom);6const storybookPreview = document.querySelector('storybook-preview');7const storybookPreviewRect = storybookPreview.getBoundingClientRect();8const storybookPreviewStyle = window.getComputedStyle(storybookPreview);9const storybookPreviewWidth = storybookPreviewRect.width - parseInt(storybookPreviewStyle.paddingLeft) - parseInt(storybookPreviewStyle.paddingRight);10const storybookPreviewHeight = storybookPreviewRect.height - parseInt(storybookPreviewStyle.paddingTop) - parseInt(storybookPreviewStyle.paddingBottom);11const storybookViewport = document.querySelector('storybook-viewport');12const storybookViewportRect = storybookViewport.getBoundingClientRect();13const storybookViewportStyle = window.getComputedStyle(storybookViewport);14const storybookViewportWidth = storybookViewportRect.width - parseInt(storybookViewportStyle.paddingLeft) - parseInt(storybookViewportStyle.paddingRight);15const storybookViewportHeight = storybookViewportRect.height - parseInt(storybookViewportStyle.paddingTop) - parseInt(storybookViewportStyle.paddingBottom);16const storybookPreviewIframe = document.querySelector('storybook-preview-iframe');17const storybookPreviewIframeRect = storybookPreviewIframe.getBoundingClientRect();18const storybookPreviewIframeStyle = window.getComputedStyle(storybookPreviewIframe);19const storybookPreviewIframeWidth = storybookPreviewIframeRect.width - parseInt(storybookPreviewIframeStyle.paddingLeft) - parseInt(storybookPreviewIframeStyle.paddingRight);20const storybookPreviewIframeHeight = storybookPreviewIframeRect.height - parseInt(storybookPreviewIframeStyle.paddingTop) - parseInt(storybookPreviewIframeStyle.paddingBottom);21const storybookPreviewIframeContent = document.querySelector('storybook-preview-iframe').contentWindow.document.body;

Full Screen

Using AI Code Generation

copy

Full Screen

1import { collide } from 'storybook-root'2collide()3export function collide() {4 console.log('boom')5}6{7}8{9 "dependencies": {10 }11}12import { collide } from 'storybook-root'13collide()14 @ multi ./node_modules/@storybook/core/dist/server/common/polyfills.js ./node_modules/@storybook/core/dist/server/preview/globals.js ./.storybook/generated-stories-entry.js (webpack)-hot-middleware/client.js?reload=true&quiet=true15 CPU: (8) x64 Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz16 Yarn: 1.19.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getStorybook } = require('@storybook/react');2const { getStorybookUI, configure, addDecorator } = require('@storybook/react-native');3const { withCollide } = require('storybook-root-wrapper');4const StorybookUIRoot = getStorybookUI({ port: 7007, onDeviceUI: true });5module.exports = withCollide(StorybookUIRoot, getStorybook, configure, addDecorator);6import React from 'react';7import { StyleSheet, Text, View } from 'react-native';8import StorybookUIRoot from './storybook';9export default class App extends React.Component {10 render() {11 return (12 <View style={styles.container}>13 );14 }15}16const styles = StyleSheet.create({17 container: {18 },19});

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 storybook-root 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