UNPKG

@box2d/debug-draw

Version:

Debug drawing helper for @box2d

142 lines (141 loc) 6.53 kB
"use strict"; // MIT License Object.defineProperty(exports, "__esModule", { value: true }); exports.b2MakeArray = exports.b2MakeBooleanArray = exports.b2MakeNumberArray = exports.b2_version = exports.b2_angularSleepTolerance = exports.b2_linearSleepTolerance = exports.b2_timeToSleep = exports.b2_toiBaumgarte = exports.b2_baumgarte = exports.b2_maxRotationSquared = exports.b2_maxRotation = exports.b2_maxTranslationSquared = exports.b2_maxTranslation = exports.b2_maxAngularCorrection = exports.b2_maxLinearCorrection = exports.b2_maxTOIContacts = exports.b2_maxSubSteps = exports.b2_polygonRadius = exports.b2_angularSlop = exports.b2_linearSlop = exports.b2_aabbMultiplier = exports.b2_aabbExtension = exports.b2_maxManifoldPoints = exports.b2_epsilon_sq = exports.b2_epsilon = exports.b2_maxFloat = exports.b2Verify = exports.b2Assert = void 0; // Copyright (c) 2019 Erin Catto // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. const b2_settings_1 = require("./b2_settings"); function b2Assert(condition, message) { if (!condition) throw new Error(message); } exports.b2Assert = b2Assert; function b2Verify(value) { if (value === null) throw new Error(); return value; } exports.b2Verify = b2Verify; exports.b2_maxFloat = 1e37; // FLT_MAX instead of Number.MAX_VALUE; exports.b2_epsilon = 1e-5; // FLT_EPSILON instead of Number.MIN_VALUE; exports.b2_epsilon_sq = exports.b2_epsilon * exports.b2_epsilon; // Global tuning constants based on meters-kilograms-seconds (MKS) units. // Collision /** * The maximum number of contact points between two convex shapes. Do * not change this value. */ exports.b2_maxManifoldPoints = 2; /** * This is used to fatten AABBs in the dynamic tree. This allows proxies * to move by a small amount without triggering a tree adjustment. * This is in meters. */ exports.b2_aabbExtension = 0.1 * b2_settings_1.b2_lengthUnitsPerMeter; /** * This is used to fatten AABBs in the dynamic tree. This is used to predict * the future position based on the current displacement. * This is a dimensionless multiplier. */ exports.b2_aabbMultiplier = 4; /** * A small length used as a collision and constraint tolerance. Usually it is * chosen to be numerically significant, but visually insignificant. In meters. */ exports.b2_linearSlop = 0.005 * b2_settings_1.b2_lengthUnitsPerMeter; /** * A small angle used as a collision and constraint tolerance. Usually it is * chosen to be numerically significant, but visually insignificant. */ exports.b2_angularSlop = (2 / 180) * Math.PI; /** * The radius of the polygon/edge shape skin. This should not be modified. Making * this smaller means polygons will have an insufficient buffer for continuous collision. * Making it larger may create artifacts for vertex collision. */ exports.b2_polygonRadius = 2 * exports.b2_linearSlop; /** Maximum number of sub-steps per contact in continuous physics simulation. */ exports.b2_maxSubSteps = 8; // Dynamics /** Maximum number of contacts to be handled to solve a TOI impact. */ exports.b2_maxTOIContacts = 32; /** * The maximum linear position correction used when solving constraints. This helps to * prevent overshoot. Meters. */ exports.b2_maxLinearCorrection = 0.2 * b2_settings_1.b2_lengthUnitsPerMeter; /** * The maximum angular position correction used when solving constraints. This helps to * prevent overshoot. */ exports.b2_maxAngularCorrection = (8 / 180) * Math.PI; /** * The maximum linear translation of a body per step. This limit is very large and is used * to prevent numerical problems. You shouldn't need to adjust this. Meters. */ exports.b2_maxTranslation = 2 * b2_settings_1.b2_lengthUnitsPerMeter; exports.b2_maxTranslationSquared = exports.b2_maxTranslation * exports.b2_maxTranslation; /** * The maximum angular velocity of a body. This limit is very large and is used * to prevent numerical problems. You shouldn't need to adjust this. */ exports.b2_maxRotation = 0.5 * Math.PI; exports.b2_maxRotationSquared = exports.b2_maxRotation * exports.b2_maxRotation; /** * This scale factor controls how fast overlap is resolved. Ideally this would be 1 so * that overlap is removed in one time step. However using values close to 1 often lead * to overshoot. */ exports.b2_baumgarte = 0.2; exports.b2_toiBaumgarte = 0.75; // Sleep /** The time that a body must be still before it will go to sleep. */ exports.b2_timeToSleep = 0.5; /** A body cannot sleep if its linear velocity is above this tolerance. */ exports.b2_linearSleepTolerance = 0.01 * b2_settings_1.b2_lengthUnitsPerMeter; /** A body cannot sleep if its angular velocity is above this tolerance. */ exports.b2_angularSleepTolerance = (2 / 180) * Math.PI; /** * Current version. * @see http://en.wikipedia.org/wiki/Software_versioning */ exports.b2_version = { major: 2, minor: 4, patch: 1, }; function b2MakeNumberArray(length, init = 0) { const result = new Array(length); for (let i = 0; i < length; i++) result[i] = init; return result; } exports.b2MakeNumberArray = b2MakeNumberArray; function b2MakeBooleanArray(length, init = false) { const result = new Array(length); for (let i = 0; i < length; i++) result[i] = init; return result; } exports.b2MakeBooleanArray = b2MakeBooleanArray; function b2MakeArray(length, Class) { const result = new Array(length); for (let i = 0; i < length; i++) result[i] = new Class(); return result; } exports.b2MakeArray = b2MakeArray;