UNPKG

@awayfl/awayfl-player

Version:

Flash Player emulator for executing SWF files (published for FP versions 6 and up) in javascript

150 lines (149 loc) 6.13 kB
/* * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ import { __extends } from "tslib"; import { b2Vec2 } from "../../Common/Math"; import { b2Settings } from "../../Common/b2Settings"; import { b2Shape } from "./b2Shape"; var b2StaticEdgeShape = /** @class */ (function (_super) { __extends(b2StaticEdgeShape, _super); //--------------- Internals Below ------------------- function b2StaticEdgeShape(v1, v2, edgeDef) { var _this = _super.call(this, edgeDef) || this; _this.m_type = b2Shape.e_staticEdgeShape; _this.m_v1 = v1; _this.m_v2 = v2; _this.m_direction = _this.m_v2.Copy(); _this.m_direction.Subtract(_this.m_v1); _this.m_length = _this.m_direction.Normalize(); _this.m_normal = new b2Vec2(_this.m_direction.y, -_this.m_direction.x); _this.m_coreV1 = _this.m_normal.Copy(); _this.m_coreV1.Subtract(_this.m_direction); _this.m_coreV1.Multiply(-b2Settings.b2_toiSlop); _this.m_coreV1.Add(_this.m_v1); _this.m_coreV2 = _this.m_normal.Copy(); _this.m_coreV2.Add(_this.m_direction); _this.m_coreV2.Multiply(-b2Settings.b2_toiSlop); _this.m_coreV2.Add(_this.m_v2); _this.m_cornerDir1 = _this.m_normal; _this.m_cornerDir2 = _this.m_normal.Copy(); _this.m_cornerDir2.Multiply(-1); return _this; } /// @see b2Shape::TestSegment b2StaticEdgeShape.prototype.TestSegment = function (transform, lambda, // float pointer normal, // pointer segment, maxLambda) { // This is mostly copied from b2Segment.TestSegment(), since // b2StaticEdgeShapes are much like b2Segments. var k_slop = 100.0 * Number.MIN_VALUE; var rX = segment.p2.x - segment.p1.x; var rY = segment.p2.y - segment.p1.y; var nX = this.m_v2.y - this.m_v1.y; var nY = this.m_v1.x - this.m_v2.x; var denom = -(rX * nX + rY * nY); if (denom > k_slop) { var bX = segment.p1.x - this.m_v1.x; var bY = segment.p1.y - this.m_v1.y; var a = (bX * nX + bY * nY); if (0.0 <= a && a <= maxLambda * denom) { var mu2 = -rX * bY + rY * bX; if (-k_slop * denom <= mu2 && mu2 <= denom * (1.0 + k_slop)) { a /= denom; var nLen = Math.sqrt(nX * nX + nY * nY); nX /= nLen; nY /= nLen; lambda[0] = a; normal.Set(nX, nY); return true; } } } return false; }; /// @see b2Shape::ComputeAABB b2StaticEdgeShape.prototype.ComputeAABB = function (aabb, transform) { if (this.m_v1.x < this.m_v2.x) { aabb.lowerBound.x = this.m_v1.x; aabb.upperBound.x = this.m_v2.x; } else { aabb.lowerBound.x = this.m_v2.x; aabb.upperBound.x = this.m_v1.x; } if (this.m_v1.y < this.m_v2.y) { aabb.lowerBound.y = this.m_v1.y; aabb.upperBound.y = this.m_v2.y; } else { aabb.lowerBound.y = this.m_v2.y; aabb.upperBound.y = this.m_v1.y; } }; /// @see b2Shape::ComputeSweptAABB b2StaticEdgeShape.prototype.ComputeSweptAABB = function (aabb, transform1, transform2) { return this.ComputeAABB(aabb, transform1); }; b2StaticEdgeShape.prototype.GetVertex1 = function () { return this.m_v1; }; b2StaticEdgeShape.prototype.GetVertex2 = function () { return this.m_v2; }; b2StaticEdgeShape.prototype.GetLength = function () { return this.m_length; }; b2StaticEdgeShape.prototype.GetNormalVector = function () { return this.m_normal; }; b2StaticEdgeShape.prototype.GetDirectionVector = function () { return this.m_direction; }; b2StaticEdgeShape.prototype.GetParentChain = function () { return this.m_chain; }; b2StaticEdgeShape.prototype.GetFirstVertex = function (xf) { return this.m_coreV1; }; b2StaticEdgeShape.prototype.Support = function (xf, dX, dY) { return (this.m_coreV1.x * dX + this.m_coreV1.y * dY) > (this.m_coreV2.x * dX + this.m_coreV2.y * dY) ? this.m_coreV1 : this.m_coreV2; }; b2StaticEdgeShape.prototype.SetPrevEdge = function (edge, core, cornerDir) { this.m_prevEdge = edge; this.m_coreV1 = core; this.m_cornerDir1 = cornerDir; }; b2StaticEdgeShape.prototype.SetNextEdge = function (edge, core, cornerDir) { this.m_nextEdge = edge; this.m_coreV2 = core; this.m_cornerDir2 = cornerDir; }; // Update the sweep radius (maximum radius) as measured from // a local center point. b2StaticEdgeShape.prototype.UpdateSweepRadius = function (center) { var dX = this.m_v1.x - center.x; var dY = this.m_v1.y - center.y; var d1 = dX * dX + dY * dY; dX = this.m_v2.x - center.x; dY = this.m_v2.y - center.y; var d2 = dX * dX + dY * dY; dX = Math.sqrt(d1 > d2 ? d1 : d2); // length this.m_sweepRadius = dX; }; return b2StaticEdgeShape; }(b2Shape)); export { b2StaticEdgeShape };