diff --git a/melos.yaml b/melos.yaml deleted file mode 100644 index e4d49cf..0000000 --- a/melos.yaml +++ /dev/null @@ -1,84 +0,0 @@ -name: Forge2D -repository: https://github.com/flame-engine/forge2d - -packages: - - packages/** - -ignore: - - packages/benchmark/build - -command: - version: - # Generate commit links in package changelogs. - linkToCommits: true - # Only allow versioning to happen on main branch. - branch: main - environment: - sdk: ">=3.0.0 <4.0.0" - bootstrap: - environment: - sdk: ">=3.0.0 <4.0.0" - dependencies: - meta: ^1.11.0 - vector_math: ^2.1.4 - dev_dependencies: - dartdoc: ^7.0.2 - flame_lint: ^1.1.1 - mocktail: ^1.0.1 - test: ^1.24.9 - -scripts: - lint:all: - run: melos run analyze && melos run format - description: Run all static analysis checks. - - analyze: - run: | - melos exec -c 1 -- \ - dart analyze --fatal-infos - description: Run `dart analyze` for all packages. - - format: - run: melos exec dart format . --fix - description: Run `dart format` for all packages. - - format-check: - run: melos exec dart format . --set-exit-if-changed - description: Run `dart format` checks for all packages. - - dartdoc: - run: melos exec dart pub run dartdoc - description: Run dartdoc checks for all packages. - - test:select: - run: melos exec -c 1 -- dart test - packageFilters: - dirExists: test - description: Run `dart test` for selected packages. - - test: - run: melos run test:select --no-select - description: Run all tests in this project. - - coverage: - run: | - melos exec -- dart test --coverage && - melos exec -- genhtml coverage/lcov.info --output-directory=coverage/ - packageFilters: - dirExists: test - description: Generate coverage for the selected package. - - benchmark: - run: melos exec -- dart web/bench2d.dart - packageFilters: - scope: forge2d_benchmark - - benchmark_serve: - run: melos exec -- dart pub global run webdev serve --release - packageFilters: - scope: forge2d_benchmark - - example: - run: melos exec -- dart pub global run webdev serve --release - packageFilters: - scope: forge2d_examples \ No newline at end of file diff --git a/packages/benchmark/pubspec.yaml b/packages/benchmark/pubspec.yaml index 2b1884d..0dd12fb 100644 --- a/packages/benchmark/pubspec.yaml +++ b/packages/benchmark/pubspec.yaml @@ -1,17 +1,19 @@ name: forge2d_benchmark description: Simple benchmark for Forge2D +resolution: workspace version: 1.0.0+1 publish_to: 'none' environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" dependencies: build_runner: ^2.4.5 build_web_compilers: ^4.0.3 forge2d: ^0.14.0 + web: ^1.1.1 dev_dependencies: - flame_lint: ^1.1.1 + flame_lint: ^1.4.1 diff --git a/packages/benchmark/web/bench2d_web.dart b/packages/benchmark/web/bench2d_web.dart index 29a648e..279c6ce 100644 --- a/packages/benchmark/web/bench2d_web.dart +++ b/packages/benchmark/web/bench2d_web.dart @@ -1,6 +1,7 @@ -import 'dart:html'; +import 'dart:js_interop'; import 'package:forge2d/forge2d_browser.dart'; +import 'package:web/web.dart'; import 'bench2d.dart'; @@ -16,7 +17,7 @@ class Bench2dWeb extends Bench2d { static const int canvasHeight = 600; static const double _viewportScale = 10.0; - late CanvasElement canvas; + late HTMLCanvasElement canvas; late CanvasRenderingContext2D ctx; late ViewportTransform viewport; late DebugDraw debugDraw; @@ -25,7 +26,7 @@ class Bench2dWeb extends Bench2d { /// before calling runAnimation. void initializeAnimation() { // Setup the canvas. - canvas = CanvasElement() + canvas = HTMLCanvasElement() ..width = canvasWidth ..height = canvasHeight; @@ -51,10 +52,10 @@ class Bench2dWeb extends Bench2d { ctx.clearRect(0, 0, canvasWidth, canvasHeight); world.drawDebugData(); - window.animationFrame.then(render); + window.requestAnimationFrame(render.toJS); } void runAnimation() { - window.animationFrame.then(render); + window.requestAnimationFrame(render.toJS); } } diff --git a/packages/forge2d/example/pubspec.yaml b/packages/forge2d/example/pubspec.yaml index 7f7159b..37ab900 100644 --- a/packages/forge2d/example/pubspec.yaml +++ b/packages/forge2d/example/pubspec.yaml @@ -1,17 +1,18 @@ name: forge2d_examples description: Samples showcasing Forge2D - version: 1.0.0+1 +resolution: workspace publish_to: 'none' environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" dependencies: forge2d: ^0.14.0 + web: ^1.1.1 dev_dependencies: - build_runner: ^2.4.5 - build_web_compilers: ^4.0.4 - flame_lint: ^1.1.1 + build_runner: ^2.6.0 + build_web_compilers: ^4.2.0 + flame_lint: ^1.4.1 diff --git a/packages/forge2d/example/web/demo.dart b/packages/forge2d/example/web/demo.dart index a116861..624a0eb 100644 --- a/packages/forge2d/example/web/demo.dart +++ b/packages/forge2d/example/web/demo.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'dart:html' hide Body; +import 'dart:js_interop'; import 'package:forge2d/forge2d_browser.dart'; +import 'package:web/web.dart'; /// An abstract class for any Demo of the Forge2D library. abstract class Demo { @@ -31,7 +32,7 @@ abstract class Demo { final double _viewportScale; /// The drawing canvas. - late final CanvasElement canvas; + late final HTMLCanvasElement canvas; /// The canvas rendering context. late final CanvasRenderingContext2D ctx; @@ -55,10 +56,10 @@ abstract class Demo { late final Element worldStepTime; Demo(String name, [Vector2? gravity, this._viewportScale = viewportScale]) - : world = World(gravity ?? Vector2(0.0, _gravity)), - _stopwatch = Stopwatch()..start() { + : world = World(gravity ?? Vector2(0.0, _gravity)), + _stopwatch = Stopwatch()..start() { world.setAllowSleep(true); - querySelector('#title')?.innerHtml = name; + document.querySelector('#title')?.innerHTML = name.toJS; } /// Advances the world forward by timestep seconds. @@ -72,17 +73,17 @@ abstract class Demo { world.drawDebugData(); frameCount++; - window.requestAnimationFrame(step); + window.requestAnimationFrame(step.toJS); } /// Creates the canvas and readies the demo for animation. Must be called /// before calling runAnimation. void initializeAnimation() { // Setup the canvas. - canvas = (Element.tag('canvas') as CanvasElement) + canvas = HTMLCanvasElement() ..width = canvasWidth ..height = canvasHeight; - document.body?.nodes.add(canvas); + document.body?.appendChild(canvas); ctx = canvas.context2D; // Create the viewport transform with the center at extents. @@ -96,17 +97,17 @@ abstract class Demo { // Have the world draw itself for debugging purposes. world.debugDraw = debugDraw; - fpsCounter = querySelector('#fps-counter')!; - worldStepTime = querySelector('#world-step-time')!; + fpsCounter = document.querySelector('#fps-counter')!; + worldStepTime = document.querySelector('#world-step-time')!; Timer.periodic(const Duration(seconds: 1), (Timer t) { - fpsCounter.innerHtml = frameCount.toString(); + fpsCounter.innerHTML = frameCount.toJS; frameCount = 0; }); Timer.periodic(const Duration(milliseconds: 200), (Timer t) { if (elapsedUs == null) { return; } - worldStepTime.innerHtml = '${elapsedUs! / 1000} ms'; + worldStepTime.innerHTML = '${elapsedUs! / 1000} ms'.toJS; }); } @@ -114,6 +115,6 @@ abstract class Demo { /// Starts running the demo as an animation using an animation scheduler. void runAnimation() { - window.requestAnimationFrame(step); + window.requestAnimationFrame(step.toJS); } } diff --git a/packages/forge2d/example/web/domino_test.dart b/packages/forge2d/example/web/domino_test.dart index ab831f8..a1c1182 100644 --- a/packages/forge2d/example/web/domino_test.dart +++ b/packages/forge2d/example/web/domino_test.dart @@ -42,8 +42,10 @@ class DominoTest extends Demo { for (var i = 0; i < 4; ++i) { for (var j = 0; j < numPerRow; j++) { - bodyDef.position = - Vector2(-14.75 + j * (29.5 / (numPerRow - 1)), 7.3 + 5 * i); + bodyDef.position = Vector2( + -14.75 + j * (29.5 / (numPerRow - 1)), + 7.3 + 5 * i, + ); if (i == 2 && j == 0) { bodyDef.angle = -.1; bodyDef.position.x += .1; diff --git a/packages/forge2d/example/web/domino_tower.dart b/packages/forge2d/example/web/domino_tower.dart index 1322c12..e89331d 100644 --- a/packages/forge2d/example/web/domino_tower.dart +++ b/packages/forge2d/example/web/domino_tower.dart @@ -97,7 +97,8 @@ class DominoTower extends Demo { dominoHeight * .5 + (dominoHeight + 2 * dominoWidth) * .99 * j; for (var i = 0; i < baseCount - j; ++i) { - currX = i * 1.5 * dominoHeight - + currX = + i * 1.5 * dominoHeight - (1.5 * dominoHeight * (baseCount - j) / 2); dominoDensity *= 2.5; if (i == 0) { diff --git a/packages/forge2d/example/web/racer.dart b/packages/forge2d/example/web/racer.dart index 0036e46..77e1b5d 100644 --- a/packages/forge2d/example/web/racer.dart +++ b/packages/forge2d/example/web/racer.dart @@ -1,7 +1,8 @@ -import 'dart:html' hide Body; +import 'dart:js_interop'; import 'dart:math'; import 'package:forge2d/forge2d_browser.dart'; +import 'package:web/web.dart'; import 'demo.dart'; import 'racer/car.dart'; @@ -26,8 +27,8 @@ class Racer extends Demo implements ContactListener { _controlState = 0; // Bind to keyboard events. - document.onKeyDown.listen(_handleKeyDown); - document.onKeyUp.listen(_handleKeyUp); + document.onkeydown = _handleKeyDown.toJS; + document.onkeyup = _handleKeyUp.toJS; // Add ourselves as a collision listener. world.setContactListener(this); @@ -120,16 +121,12 @@ class Racer extends Demo implements ContactListener { switch (event.keyCode) { case 37: _controlState |= ControlState.left; - break; case 38: _controlState |= ControlState.up; - break; case 39: _controlState |= ControlState.right; - break; case 40: _controlState |= ControlState.down; - break; } } @@ -137,16 +134,12 @@ class Racer extends Demo implements ContactListener { switch (event.keyCode) { case 37: _controlState &= ~ControlState.left; - break; case 38: _controlState &= ~ControlState.up; - break; case 39: _controlState &= ~ControlState.right; - break; case 40: _controlState &= ~ControlState.down; - break; } } @@ -179,8 +172,8 @@ void main() { final racer = Racer(); racer.initialize(); racer.initializeAnimation(); - final paragraph = ParagraphElement() + final paragraph = HTMLParagraphElement() ..innerText = 'Use the arrow keys to drive the car'; - document.body?.nodes.add(paragraph); + document.body?.append(paragraph); racer.runAnimation(); } diff --git a/packages/forge2d/example/web/racer/car.dart b/packages/forge2d/example/web/racer/car.dart index cf837ab..afd6307 100644 --- a/packages/forge2d/example/web/racer/car.dart +++ b/packages/forge2d/example/web/racer/car.dart @@ -122,15 +122,15 @@ class Car { switch (controlState & (ControlState.left | ControlState.right)) { case ControlState.left: desiredAngle = _lockAngle; - break; case ControlState.right: desiredAngle = -_lockAngle; - break; } final turnPerTimeStep = _turnSpeedPerSec * 1000 / time; final angleNow = _frontLeftJoint.jointAngle(); - final angleToTurn = - (desiredAngle - angleNow).clamp(-turnPerTimeStep, turnPerTimeStep); + final angleToTurn = (desiredAngle - angleNow).clamp( + -turnPerTimeStep, + turnPerTimeStep, + ); final angle = angleNow + angleToTurn; _frontLeftJoint.setLimits(angle, angle); _frontRightJoint.setLimits(angle, angle); diff --git a/packages/forge2d/example/web/racer/tire.dart b/packages/forge2d/example/web/racer/tire.dart index 6eec5d5..0bee823 100644 --- a/packages/forge2d/example/web/racer/tire.dart +++ b/packages/forge2d/example/web/racer/tire.dart @@ -71,10 +71,8 @@ class Tire { switch (controlState & (ControlState.up | ControlState.down)) { case ControlState.up: desiredSpeed = _maxForwardSpeed; - break; case ControlState.down: desiredSpeed = _maxBackwardSpeed; - break; default: return; } @@ -98,10 +96,8 @@ class Tire { switch (controlState & (ControlState.left | ControlState.right)) { case ControlState.left: desiredTorque = 15.0; - break; case ControlState.right: desiredTorque = -15.0; - break; } body.applyTorque(desiredTorque); } diff --git a/packages/forge2d/lib/src/callbacks/canvas_draw.dart b/packages/forge2d/lib/src/callbacks/canvas_draw.dart index 31367ff..61fcea6 100644 --- a/packages/forge2d/lib/src/callbacks/canvas_draw.dart +++ b/packages/forge2d/lib/src/callbacks/canvas_draw.dart @@ -1,8 +1,9 @@ -import 'dart:html'; +import 'dart:js_interop'; import 'dart:math'; import 'package:forge2d/forge2d.dart'; import 'package:forge2d/forge2d_browser.dart'; +import 'package:web/web.dart'; class CanvasDraw extends DebugDraw { /// The canvas rendering context with which to draw. @@ -27,25 +28,35 @@ class CanvasDraw extends DebugDraw { } void _pathPolygon(List vertices, Color3i color) { - // Set the color and convert to screen coordinates. _setColor(color); - // TODO(gregbglw): Do a single ctx transform rather than convert all of - // these vectors. - final screenVertices = vertices.map(worldToScreen).toList(); + // Save the current canvas state + ctx.save(); + + // Apply the transformation matrix for world-to-screen conversion + ctx.transform( + viewport.scale, + 0, + 0, + -viewport.scale, + viewport.extents.x + viewport.translation.x, + viewport.extents.y - viewport.translation.y, + ); + + // Begin the path and move to the first vertex ctx.beginPath(); - ctx.moveTo(screenVertices[0].x, screenVertices[0].y); + ctx.moveTo(vertices[0].x, vertices[0].y); - // Draw lines to all of the remaining points. - for (final vertex in screenVertices) { + // Draw lines to the remaining vertices + for (final vertex in vertices) { ctx.lineTo(vertex.x, vertex.y); } - // Draw a line back to the starting point. - ctx.lineTo(screenVertices[0].x, screenVertices[0].y); - - // Close the drawn polygon ready for fill/stroke + // Close the polygon ctx.closePath(); + + // Restore the canvas state + ctx.restore(); } /// Draw a line segment. WARNING: This mutates [p1] and [p2]. @@ -114,8 +125,8 @@ class CanvasDraw extends DebugDraw { /// Sets the rendering context stroke and fill color to [color]. void _setColor(Color3i color) { - ctx.setStrokeColorRgb(color.r, color.g, color.b, color.a); - ctx.setFillColorRgb(color.r, color.g, color.b, color.a); + ctx.strokeStyle = color.toHex().toJS; + ctx.fillStyle = color.toHex().toJS; } @override diff --git a/packages/forge2d/lib/src/collision/aabb.dart b/packages/forge2d/lib/src/collision/aabb.dart index 0d3d1a4..4e4cb4b 100644 --- a/packages/forge2d/lib/src/collision/aabb.dart +++ b/packages/forge2d/lib/src/collision/aabb.dart @@ -12,21 +12,19 @@ class AABB { final Vector2 upperBound; /// Creates the default object, with vertices at 0,0 and 0,0. - AABB() - : lowerBound = Vector2.zero(), - upperBound = Vector2.zero(); + AABB() : lowerBound = Vector2.zero(), upperBound = Vector2.zero(); /// Copies from the given object. AABB.copy(AABB copy) - : lowerBound = Vector2.copy(copy.lowerBound), - upperBound = Vector2.copy(copy.upperBound); + : lowerBound = Vector2.copy(copy.lowerBound), + upperBound = Vector2.copy(copy.upperBound); /// Creates an AABB object using the given bounding vertices. /// [lowerVertex] should be the bottom left vertex of the bounding box. /// [upperVertex] should be the top right vertex of the bounding box. AABB.withVec2(Vector2 lowerVertex, Vector2 upperVertex) - : lowerBound = Vector2.copy(lowerVertex), - upperBound = Vector2.copy(upperVertex); + : lowerBound = Vector2.copy(lowerVertex), + upperBound = Vector2.copy(upperVertex); /// Sets this object from the given object. void set(AABB aabb) { @@ -101,14 +99,18 @@ class AABB { /// Combines another aabb with this one void combine(AABB aabb) { - lowerBound.x = - lowerBound.x < aabb.lowerBound.x ? lowerBound.x : aabb.lowerBound.x; - lowerBound.y = - lowerBound.y < aabb.lowerBound.y ? lowerBound.y : aabb.lowerBound.y; - upperBound.x = - upperBound.x > aabb.upperBound.x ? upperBound.x : aabb.upperBound.x; - upperBound.y = - upperBound.y > aabb.upperBound.y ? upperBound.y : aabb.upperBound.y; + lowerBound.x = lowerBound.x < aabb.lowerBound.x + ? lowerBound.x + : aabb.lowerBound.x; + lowerBound.y = lowerBound.y < aabb.lowerBound.y + ? lowerBound.y + : aabb.lowerBound.y; + upperBound.x = upperBound.x > aabb.upperBound.x + ? upperBound.x + : aabb.upperBound.x; + upperBound.y = upperBound.y > aabb.upperBound.y + ? upperBound.y + : aabb.upperBound.y; } /// Does this aabb contain the provided AABB. diff --git a/packages/forge2d/lib/src/collision/broadphase/dynamic_tree.dart b/packages/forge2d/lib/src/collision/broadphase/dynamic_tree.dart index efbc909..ea87f02 100644 --- a/packages/forge2d/lib/src/collision/broadphase/dynamic_tree.dart +++ b/packages/forge2d/lib/src/collision/broadphase/dynamic_tree.dart @@ -151,7 +151,8 @@ class DynamicTree implements BroadPhaseStrategy { } else { if (_nodeStack.length - nodeStackIndex - 2 <= 0) { final previousSize = _nodeStack.length; - _nodeStack = _nodeStack + + _nodeStack = + _nodeStack + List.generate( previousSize, (i) => DynamicTreeNode(previousSize + i), @@ -269,7 +270,8 @@ class DynamicTree implements BroadPhaseStrategy { } else { if (_nodeStack.length - nodeStackIndex - 2 <= 0) { final previousSize = _nodeStack.length; - _nodeStack = _nodeStack + + _nodeStack = + _nodeStack + List.generate( previousSize, (i) => DynamicTreeNode(previousSize + i), @@ -429,7 +431,8 @@ class DynamicTree implements BroadPhaseStrategy { if (_freeList == nullNode) { assert(_nodeCount == _nodeCapacity); - _nodes = _nodes + + _nodes = + _nodes + List.generate( _nodeCapacity, (i) => DynamicTreeNode(_nodeCapacity + i), diff --git a/packages/forge2d/lib/src/collision/collision.dart b/packages/forge2d/lib/src/collision/collision.dart index e2003cc..2c611da 100644 --- a/packages/forge2d/lib/src/collision/collision.dart +++ b/packages/forge2d/lib/src/collision/collision.dart @@ -648,7 +648,8 @@ class Collision { var pointCount = 0; for (var i = 0; i < settings.maxManifoldPoints; ++i) { - final separation = normalx * _clipPoints2[i].v.x + + final separation = + normalx * _clipPoints2[i].v.x + normaly * _clipPoints2[i].v.y - frontOffset; @@ -1123,8 +1124,9 @@ class EdgePolygonCollider { // Get polygonB in frameA polygonB.count = polygonB2.vertices.length; for (var i = 0; i < polygonB2.vertices.length; ++i) { - polygonB.vertices[i] - .setFrom(Transform.mulVec2(xf, polygonB2.vertices[i])); + polygonB.vertices[i].setFrom( + Transform.mulVec2(xf, polygonB2.vertices[i]), + ); polygonB.normals[i].setFrom(Rot.mulVec2(xf.q, polygonB2.normals[i])); } diff --git a/packages/forge2d/lib/src/collision/distance.dart b/packages/forge2d/lib/src/collision/distance.dart index 8b5bbdd..dade0f7 100644 --- a/packages/forge2d/lib/src/collision/distance.dart +++ b/packages/forge2d/lib/src/collision/distance.dart @@ -201,11 +201,9 @@ class _Simplex { switch (count) { case 0: assert(false); - break; case 1: pA.setFrom(vertex1.wA); pB.setFrom(vertex1.wB); - break; case 2: _case2 ..setFrom(vertex1.wA) @@ -224,7 +222,6 @@ class _Simplex { ..scale(vertex2.a) ..add(_case2); - break; case 3: pA ..setFrom(vertex1.wA) @@ -239,10 +236,8 @@ class _Simplex { ..add(_case3) ..add(_case33); pB.setFrom(pA); - break; default: assert(false); - break; } } @@ -469,7 +464,6 @@ class DistanceProxy { _count = 1; radius = circle.radius; - break; case ShapeType.polygon: final poly = shape as PolygonShape; _count = poly.vertices.length; @@ -477,7 +471,6 @@ class DistanceProxy { for (var i = 0; i < _count; i++) { vertices[i].setFrom(poly.vertices[i]); } - break; case ShapeType.chain: final chain = shape as ChainShape; assert(0 <= index && index < chain.vertexCount); @@ -493,14 +486,12 @@ class DistanceProxy { vertices[1].setFrom(buffer[1]); _count = 2; radius = chain.radius; - break; case ShapeType.edge: final edge = shape as EdgeShape; vertices[0].setFrom(edge.vertex1); vertices[1].setFrom(edge.vertex2); _count = 2; radius = edge.radius; - break; } } @@ -607,10 +598,8 @@ class Distance { break; case 2: _simplex.solve2(); - break; case 3: _simplex.solve3(); - break; default: assert(false); } diff --git a/packages/forge2d/lib/src/collision/manifold_point.dart b/packages/forge2d/lib/src/collision/manifold_point.dart index c17b284..05f03e8 100644 --- a/packages/forge2d/lib/src/collision/manifold_point.dart +++ b/packages/forge2d/lib/src/collision/manifold_point.dart @@ -25,16 +25,14 @@ class ManifoldPoint { final ContactID id; /// Blank manifold point with everything zeroed out. - ManifoldPoint() - : localPoint = Vector2.zero(), - id = ContactID(); + ManifoldPoint() : localPoint = Vector2.zero(), id = ContactID(); /// Creates a manifold point as a copy of the given point. ManifoldPoint.copy(ManifoldPoint manifoldPoint) - : localPoint = manifoldPoint.localPoint.clone(), - normalImpulse = manifoldPoint.normalImpulse, - tangentImpulse = manifoldPoint.tangentImpulse, - id = ContactID.copy(manifoldPoint.id); + : localPoint = manifoldPoint.localPoint.clone(), + normalImpulse = manifoldPoint.normalImpulse, + tangentImpulse = manifoldPoint.tangentImpulse, + id = ContactID.copy(manifoldPoint.id); /// Sets this manifold point form the given one. void set(ManifoldPoint manifoldPoint) { diff --git a/packages/forge2d/lib/src/collision/shapes/circle_shape.dart b/packages/forge2d/lib/src/collision/shapes/circle_shape.dart index b872556..b0411fd 100644 --- a/packages/forge2d/lib/src/collision/shapes/circle_shape.dart +++ b/packages/forge2d/lib/src/collision/shapes/circle_shape.dart @@ -136,7 +136,8 @@ class CircleShape extends Shape { massData.center.y = position.y; // inertia about the local origin - massData.I = massData.mass * + massData.I = + massData.mass * (0.5 * radius * radius + (position.x * position.x + position.y * position.y)); } diff --git a/packages/forge2d/lib/src/collision/shapes/mass_data.dart b/packages/forge2d/lib/src/collision/shapes/mass_data.dart index c322192..f7f1ed4 100644 --- a/packages/forge2d/lib/src/collision/shapes/mass_data.dart +++ b/packages/forge2d/lib/src/collision/shapes/mass_data.dart @@ -18,9 +18,9 @@ class MassData { /// Copies from the given mass data. MassData.copy(MassData md) - : mass = md.mass, - center = md.center.clone(), - I = md.I; + : mass = md.mass, + center = md.center.clone(), + I = md.I; void set(MassData md) { mass = md.mass; diff --git a/packages/forge2d/lib/src/collision/time_of_impact.dart b/packages/forge2d/lib/src/collision/time_of_impact.dart index d2f2105..07ef2b3 100644 --- a/packages/forge2d/lib/src/collision/time_of_impact.dart +++ b/packages/forge2d/lib/src/collision/time_of_impact.dart @@ -77,8 +77,10 @@ class TimeOfImpact { final totalRadius = proxyA.radius + proxyB.radius; // djm: whats with all these constants? - final target = - max(settings.linearSlop, totalRadius - 3.0 * settings.linearSlop); + final target = max( + settings.linearSlop, + totalRadius - 3.0 * settings.linearSlop, + ); final tolerance = 0.25 * settings.linearSlop; assert(target > tolerance); diff --git a/packages/forge2d/lib/src/collision/world_manifold.dart b/packages/forge2d/lib/src/collision/world_manifold.dart index 2a14199..4395a75 100644 --- a/packages/forge2d/lib/src/collision/world_manifold.dart +++ b/packages/forge2d/lib/src/collision/world_manifold.dart @@ -65,7 +65,6 @@ class WorldManifold { points[0].y = (cAy + cBy) * .5; separations[0] = (cBx - cAx) * normal.x + (cBy - cAy) * normal.y; } - break; case ManifoldType.faceA: { final planePoint = _pool3; @@ -76,10 +75,12 @@ class WorldManifold { final clipPoint = _pool4; for (var i = 0; i < manifold.pointCount; i++) { - clipPoint - .setFrom(Transform.mulVec2(xfB, manifold.points[i].localPoint)); + clipPoint.setFrom( + Transform.mulVec2(xfB, manifold.points[i].localPoint), + ); - final scalar = radiusA - + final scalar = + radiusA - ((clipPoint.x - planePoint.x) * normal.x + (clipPoint.y - planePoint.y) * normal.y); @@ -94,7 +95,6 @@ class WorldManifold { separations[i] = (cBx - cAx) * normal.x + (cBy - cAy) * normal.y; } } - break; case ManifoldType.faceB: final planePoint = _pool3; normal.setFrom(Rot.mulVec2(xfB.q, manifold.localNormal)); @@ -103,10 +103,12 @@ class WorldManifold { final clipPoint = _pool4; for (var i = 0; i < manifold.pointCount; i++) { - clipPoint - .setFrom(Transform.mulVec2(xfA, manifold.points[i].localPoint)); + clipPoint.setFrom( + Transform.mulVec2(xfA, manifold.points[i].localPoint), + ); - final scalar = radiusB - + final scalar = + radiusB - ((clipPoint.x - planePoint.x) * normal.x + (clipPoint.y - planePoint.y) * normal.y); @@ -123,7 +125,6 @@ class WorldManifold { // Ensure normal points from A to B. normal.x = -normal.x; normal.y = -normal.y; - break; } } } diff --git a/packages/forge2d/lib/src/common/canvas_viewport_transform.dart b/packages/forge2d/lib/src/common/canvas_viewport_transform.dart index 00f0289..f0ac9c7 100644 --- a/packages/forge2d/lib/src/common/canvas_viewport_transform.dart +++ b/packages/forge2d/lib/src/common/canvas_viewport_transform.dart @@ -1,6 +1,7 @@ -import 'dart:html'; +import 'dart:js_interop'; import 'package:forge2d/forge2d.dart'; +import 'package:web/web.dart'; /// Transform for drawing using a canvas context. Y-flip is permanently set /// to true. @@ -9,7 +10,7 @@ class CanvasViewportTransform extends ViewportTransform { /// Constructs a new viewport transform with the default scale. CanvasViewportTransform(Vector2 extents, Vector2 center) - : super(extents, center, defaultDrawingScale) { + : super(extents, center, defaultDrawingScale) { yFlip = true; } @@ -18,7 +19,7 @@ class CanvasViewportTransform extends ViewportTransform { /// screen. void updateTransformation(CanvasRenderingContext2D ctx) { // Clear all previous transformation. - ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.setTransform(1.toJS, 0, 0, 1, 0, 0); // Translate to the center of the canvas screen. This will be considered the // actual origin. diff --git a/packages/forge2d/lib/src/common/color3i.dart b/packages/forge2d/lib/src/common/color3i.dart index af2d3d2..0c51a85 100644 --- a/packages/forge2d/lib/src/common/color3i.dart +++ b/packages/forge2d/lib/src/common/color3i.dart @@ -15,10 +15,10 @@ class Color3i { Color3i.zero(); Color3i.fromRGBd(double red, double green, double blue, {double alpha = 1.0}) - : r = (red * 255).floor(), - g = (green * 255).floor(), - b = (blue * 255).floor(), - a = alpha; + : r = (red * 255).floor(), + g = (green * 255).floor(), + b = (blue * 255).floor(), + a = alpha; void setRGB(int red, int green, int blue, {double? alpha}) { r = red; @@ -43,6 +43,12 @@ class Color3i { Color3i clone() => Color3i(r, g, b, a: a); + String toHex() => + '#${r.toRadixString(16).padLeft(2, '0')}' + '${g.toRadixString(16).padLeft(2, '0')}' + '${b.toRadixString(16).padLeft(2, '0')}' + '${(a * 255).toInt().toRadixString(16).padLeft(2, '0')}'; + @override String toString() => 'Color3i($r, $g, $b, $a)'; } diff --git a/packages/forge2d/lib/src/common/rot.dart b/packages/forge2d/lib/src/common/rot.dart index 9ef7a14..4504995 100644 --- a/packages/forge2d/lib/src/common/rot.dart +++ b/packages/forge2d/lib/src/common/rot.dart @@ -8,9 +8,7 @@ class Rot { Rot({this.sin = 0.0, this.cos = 1.0}); - Rot.withAngle(double angle) - : sin = math.sin(angle), - cos = math.cos(angle); + Rot.withAngle(double angle) : sin = math.sin(angle), cos = math.cos(angle); void setAngle(double angle) { sin = math.sin(angle); @@ -49,16 +47,16 @@ class Rot { Rot clone() => Rot(sin: sin, cos: cos); Rot.mul(Rot q, Rot r) - : this( - sin: q.sin * r.cos + q.cos * r.sin, - cos: q.cos * r.cos - q.sin * r.sin, - ); + : this( + sin: q.sin * r.cos + q.cos * r.sin, + cos: q.cos * r.cos - q.sin * r.sin, + ); Rot.mulTrans(Rot q, Rot r) - : this( - sin: q.cos * r.sin - q.sin * r.cos, - cos: q.cos * r.cos + q.sin * r.sin, - ); + : this( + sin: q.cos * r.sin - q.sin * r.cos, + cos: q.cos * r.cos + q.sin * r.sin, + ); static Vector2 mulVec2(Rot q, Vector2 v) { return Vector2(q.cos * v.x - q.sin * v.y, q.sin * v.x + q.cos * v.y); diff --git a/packages/forge2d/lib/src/common/transform.dart b/packages/forge2d/lib/src/common/transform.dart index d63c2eb..bea8d83 100644 --- a/packages/forge2d/lib/src/common/transform.dart +++ b/packages/forge2d/lib/src/common/transform.dart @@ -10,19 +10,13 @@ class Transform { final Rot q; /// The default constructor. - Transform.zero() - : p = Vector2.zero(), - q = Rot(); + Transform.zero() : p = Vector2.zero(), q = Rot(); /// Initialize as a copy of another transform. - Transform.clone(Transform xf) - : p = xf.p.clone(), - q = xf.q.clone(); + Transform.clone(Transform xf) : p = xf.p.clone(), q = xf.q.clone(); /// Initialize using a position vector and a rotation matrix. - Transform.from(Vector2 position, Rot r) - : p = position.clone(), - q = r.clone(); + Transform.from(Vector2 position, Rot r) : p = position.clone(), q = r.clone(); /// Set this to equal another transform. void setFrom(Transform xf) { diff --git a/packages/forge2d/lib/src/dynamics/body.dart b/packages/forge2d/lib/src/dynamics/body.dart index 8091716..4d0a531 100644 --- a/packages/forge2d/lib/src/dynamics/body.dart +++ b/packages/forge2d/lib/src/dynamics/body.dart @@ -74,10 +74,10 @@ class Body { Object? userData; Body(BodyDef bd, this.world) - : assert(!bd.position.isInfinite && !bd.position.isNaN), - assert(!bd.linearVelocity.isInfinite && !bd.linearVelocity.isNaN), - assert(bd.angularDamping >= 0.0), - assert(bd.linearDamping >= 0.0) { + : assert(!bd.position.isInfinite && !bd.position.isNaN), + assert(!bd.linearVelocity.isInfinite && !bd.linearVelocity.isNaN), + assert(bd.angularDamping >= 0.0), + assert(bd.linearDamping >= 0.0) { flags = 0; if (bd.bullet) { @@ -364,7 +364,8 @@ class Body { } linearVelocity += impulse * _inverseMass; - _angularVelocity += inverseInertia * + _angularVelocity += + inverseInertia * ((point.x - sweep.c.x) * impulse.y - (point.y - sweep.c.y) * impulse.x); } @@ -731,10 +732,12 @@ class Body { final xf1 = _pxf; xf1.q.sin = sin(sweep.a0); xf1.q.cos = cos(sweep.a0); - xf1.p.x = sweep.c0.x - + xf1.p.x = + sweep.c0.x - xf1.q.cos * sweep.localCenter.x + xf1.q.sin * sweep.localCenter.y; - xf1.p.y = sweep.c0.y - + xf1.p.y = + sweep.c0.y - xf1.q.sin * sweep.localCenter.x - xf1.q.cos * sweep.localCenter.y; diff --git a/packages/forge2d/lib/src/dynamics/body_def.dart b/packages/forge2d/lib/src/dynamics/body_def.dart index 8c818cc..5c43b02 100644 --- a/packages/forge2d/lib/src/dynamics/body_def.dart +++ b/packages/forge2d/lib/src/dynamics/body_def.dart @@ -23,8 +23,8 @@ class BodyDef { this.active = true, this.gravityOverride, this.gravityScale, - }) : position = position ?? Vector2.zero(), - linearVelocity = linearVelocity ?? Vector2.zero(); + }) : position = position ?? Vector2.zero(), + linearVelocity = linearVelocity ?? Vector2.zero(); /// The body type: static, kinematic, or dynamic. /// diff --git a/packages/forge2d/lib/src/dynamics/contacts/chain_and_circle_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/chain_and_circle_contact.dart index dbe77f5..a432d3d 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/chain_and_circle_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/chain_and_circle_contact.dart @@ -8,8 +8,8 @@ class ChainAndCircleContact extends Contact { super.indexB, super.collision, super.distance, - ) : assert(fixtureA.type == ShapeType.chain), - assert(fixtureB.type == ShapeType.circle); + ) : assert(fixtureA.type == ShapeType.chain), + assert(fixtureB.type == ShapeType.circle); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/contacts/chain_and_polygon_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/chain_and_polygon_contact.dart index 7379e6f..45ee5ab 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/chain_and_polygon_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/chain_and_polygon_contact.dart @@ -8,8 +8,8 @@ class ChainAndPolygonContact extends Contact { super.indexB, super.collision, super.distance, - ) : assert(fixtureA.type == ShapeType.chain), - assert(fixtureB.type == ShapeType.polygon); + ) : assert(fixtureA.type == ShapeType.chain), + assert(fixtureB.type == ShapeType.polygon); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/contacts/circle_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/circle_contact.dart index 8ea28fc..f1ece1a 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/circle_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/circle_contact.dart @@ -6,9 +6,9 @@ class CircleContact extends Contact { Fixture fixtureB, Collision collision, Distance distance, - ) : assert(fixtureA.type == ShapeType.circle), - assert(fixtureB.type == ShapeType.circle), - super(fixtureA, 0, fixtureB, 0, collision, distance); + ) : assert(fixtureA.type == ShapeType.circle), + assert(fixtureB.type == ShapeType.circle), + super(fixtureA, 0, fixtureB, 0, collision, distance); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/contacts/contact.dart b/packages/forge2d/lib/src/dynamics/contacts/contact.dart index 1783fdc..15c8a9e 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/contact.dart @@ -211,8 +211,10 @@ abstract class Contact { } void resetRestitution() { - _restitution = - Contact.mixRestitution(fixtureA.restitution, fixtureB.restitution); + _restitution = Contact.mixRestitution( + fixtureA.restitution, + fixtureB.restitution, + ); } void evaluate(Manifold manifold, Transform xfA, Transform xfB); diff --git a/packages/forge2d/lib/src/dynamics/contacts/contact_solver.dart b/packages/forge2d/lib/src/dynamics/contacts/contact_solver.dart index 7db3921..8b569a7 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/contact_solver.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/contact_solver.dart @@ -290,8 +290,10 @@ class ContactSolver { // Clamp the accumulated force final maxFriction = (friction * vcp.normalImpulse).abs(); - final newImpulse = - (vcp.tangentImpulse + lambda).clamp(-maxFriction, maxFriction); + final newImpulse = (vcp.tangentImpulse + lambda).clamp( + -maxFriction, + maxFriction, + ); lambda = newImpulse - vcp.tangentImpulse; vcp.tangentImpulse = newImpulse; @@ -459,11 +461,13 @@ class ContactSolver { vB.x += mB * (p1x + p2x); vB.y += mB * (p1y + p2y); - wA -= iA * + wA -= + iA * (cp1rA.x * p1y - cp1rA.y * p1x + (cp2rA.x * p2y - cp2rA.y * p2x)); - wB += iB * + wB += + iB * (cp1rB.x * p1y - cp1rB.y * p1x + (cp2rB.x * p2y - cp2rB.y * p2x)); @@ -530,11 +534,13 @@ class ContactSolver { vB.x += mB * (p1x + p2x); vB.y += mB * (p1y + p2y); - wA -= iA * + wA -= + iA * (cp1rA.x * p1y - cp1rA.y * p1x + (cp2rA.x * p2y - cp2rA.y * p2x)); - wB += iB * + wB += + iB * (cp1rB.x * p1y - cp1rB.y * p1x + (cp2rB.x * p2y - cp2rB.y * p2x)); @@ -599,11 +605,13 @@ class ContactSolver { vB.x += mB * (p1x + p2x); vB.y += mB * (p1y + p2y); - wA -= iA * + wA -= + iA * (cp1rA.x * p1y - cp1rA.y * p1x + (cp2rA.x * p2y - cp2rA.y * p2x)); - wB += iB * + wB += + iB * (cp1rB.x * p1y - cp1rB.y * p1x + (cp2rB.x * p2y - cp2rB.y * p2x)); @@ -666,11 +674,13 @@ class ContactSolver { vB.x += mB * (p1x + p2x); vB.y += mB * (p1y + p2y); - wA -= iA * + wA -= + iA * (cp1rA.x * p1y - cp1rA.y * p1x + (cp2rA.x * p2y - cp2rA.y * p2x)); - wB += iB * + wB += + iB * (cp1rB.x * p1y - cp1rB.y * p1x + (cp2rB.x * p2y - cp2rB.y * p2x)); @@ -932,7 +942,6 @@ class PositionSolverManifold { final tempY = pointBy - pointAy; separation = tempX * normal.x + tempY * normal.y - pc.radiusA - pc.radiusB; - break; case ManifoldType.faceA: final pcLocalNormal = pc.localNormal; @@ -946,17 +955,16 @@ class PositionSolverManifold { final clipPointX = (xfBq.cos * pcLocalPointsI.x - xfBq.sin * pcLocalPointsI.y) + - xfB.p.x; + xfB.p.x; final clipPointY = (xfBq.sin * pcLocalPointsI.x + xfBq.cos * pcLocalPointsI.y) + - xfB.p.y; + xfB.p.y; final tempX = clipPointX - planePointX; final tempY = clipPointY - planePointY; separation = tempX * normal.x + tempY * normal.y - pc.radiusA - pc.radiusB; point.x = clipPointX; point.y = clipPointY; - break; case ManifoldType.faceB: final pcLocalNormal = pc.localNormal; @@ -970,10 +978,10 @@ class PositionSolverManifold { final clipPointX = (xfAq.cos * pcLocalPointsI.x - xfAq.sin * pcLocalPointsI.y) + - xfA.p.x; + xfA.p.x; final clipPointY = (xfAq.sin * pcLocalPointsI.x + xfAq.cos * pcLocalPointsI.y) + - xfA.p.y; + xfA.p.y; final tempX = clipPointX - planePointX; final tempY = clipPointY - planePointY; separation = @@ -982,7 +990,6 @@ class PositionSolverManifold { point.y = clipPointY; normal.x *= -1; normal.y *= -1; - break; } } } diff --git a/packages/forge2d/lib/src/dynamics/contacts/contact_velocity_constraint.dart b/packages/forge2d/lib/src/dynamics/contacts/contact_velocity_constraint.dart index 20a4371..624218d 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/contact_velocity_constraint.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/contact_velocity_constraint.dart @@ -14,9 +14,9 @@ class VelocityConstraintPoint { class ContactVelocityConstraint { final List points = List.generate( - settings.maxManifoldPoints, - (_) => VelocityConstraintPoint(), - ); + settings.maxManifoldPoints, + (_) => VelocityConstraintPoint(), + ); final Vector2 normal = Vector2.zero(); final Matrix2 normalMass = Matrix2.zero(); diff --git a/packages/forge2d/lib/src/dynamics/contacts/edge_and_circle_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/edge_and_circle_contact.dart index 414ba84..645ceb6 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/edge_and_circle_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/edge_and_circle_contact.dart @@ -8,8 +8,8 @@ class EdgeAndCircleContact extends Contact { super.indexB, super.collision, super.distance, - ) : assert(fixtureA.type == ShapeType.edge), - assert(fixtureB.type == ShapeType.circle); + ) : assert(fixtureA.type == ShapeType.edge), + assert(fixtureB.type == ShapeType.circle); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/contacts/edge_and_polygon_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/edge_and_polygon_contact.dart index be8e0e3..ea0fa85 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/edge_and_polygon_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/edge_and_polygon_contact.dart @@ -8,8 +8,8 @@ class EdgeAndPolygonContact extends Contact { super.indexB, super.collision, super.distance, - ) : assert(fixtureA.type == ShapeType.edge), - assert(fixtureB.type == ShapeType.polygon); + ) : assert(fixtureA.type == ShapeType.edge), + assert(fixtureB.type == ShapeType.polygon); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/contacts/polygon_and_circle_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/polygon_and_circle_contact.dart index 229f65c..fefa8a9 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/polygon_and_circle_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/polygon_and_circle_contact.dart @@ -6,9 +6,9 @@ class PolygonAndCircleContact extends Contact { Fixture fixtureB, Collision collision, Distance distance, - ) : assert(fixtureA.type == ShapeType.polygon), - assert(fixtureB.type == ShapeType.circle), - super(fixtureA, 0, fixtureB, 0, collision, distance); + ) : assert(fixtureA.type == ShapeType.polygon), + assert(fixtureB.type == ShapeType.circle), + super(fixtureA, 0, fixtureB, 0, collision, distance); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/contacts/polygon_contact.dart b/packages/forge2d/lib/src/dynamics/contacts/polygon_contact.dart index 91b714d..f1f395e 100644 --- a/packages/forge2d/lib/src/dynamics/contacts/polygon_contact.dart +++ b/packages/forge2d/lib/src/dynamics/contacts/polygon_contact.dart @@ -6,9 +6,9 @@ class PolygonContact extends Contact { Fixture fixtureB, Collision collision, Distance distance, - ) : assert(fixtureA.type == ShapeType.polygon), - assert(fixtureB.type == ShapeType.polygon), - super(fixtureA, 0, fixtureB, 0, collision, distance); + ) : assert(fixtureA.type == ShapeType.polygon), + assert(fixtureB.type == ShapeType.polygon), + super(fixtureA, 0, fixtureB, 0, collision, distance); @override void evaluate(Manifold manifold, Transform xfA, Transform xfB) { diff --git a/packages/forge2d/lib/src/dynamics/fixture.dart b/packages/forge2d/lib/src/dynamics/fixture.dart index 902fe84..5252b1d 100644 --- a/packages/forge2d/lib/src/dynamics/fixture.dart +++ b/packages/forge2d/lib/src/dynamics/fixture.dart @@ -280,7 +280,6 @@ class Fixture { debugDraw.drawSolidCircle(renderCenter, radius, color); } } - break; case ShapeType.polygon: { final poly = shape as PolygonShape; @@ -297,7 +296,6 @@ class Fixture { debugDraw.drawSolidPolygon(vertices, color); } } - break; case ShapeType.edge: { final edge = shape as EdgeShape; @@ -305,7 +303,6 @@ class Fixture { _v2.setFrom(Transform.mulVec2(xf, edge.vertex2)); debugDraw.drawSegment(_v1, _v2, color); } - break; case ShapeType.chain: { final chain = shape as ChainShape; @@ -320,7 +317,6 @@ class Fixture { _v1.setFrom(_v2); } } - break; } } } diff --git a/packages/forge2d/lib/src/dynamics/island.dart b/packages/forge2d/lib/src/dynamics/island.dart index dff2f97..c154961 100644 --- a/packages/forge2d/lib/src/dynamics/island.dart +++ b/packages/forge2d/lib/src/dynamics/island.dart @@ -190,10 +190,12 @@ class Island { if (b.bodyType == BodyType.dynamic) { // Integrate velocities. final bodyGravity = b.gravityOverride ?? gravity; - v.x += dt * + v.x += + dt * ((b.gravityScale?.x ?? 1) * bodyGravity.x + b.inverseMass * b.force.x); - v.y += dt * + v.y += + dt * ((b.gravityScale?.y ?? 1) * bodyGravity.y + b.inverseMass * b.force.y); w += dt * b.inverseInertia * b.torque; @@ -267,7 +269,8 @@ class Island { if (translationX * translationX + translationY * translationY > settings.maxTranslationSquared) { - final ratio = settings.maxTranslation / + final ratio = + settings.maxTranslation / sqrt(translationX * translationX + translationY * translationY); v.x *= ratio; v.y *= ratio; @@ -378,8 +381,10 @@ class Island { // Solve position constraints. for (var i = 0; i < subStep.positionIterations; ++i) { - final contactsOkay = - _toiContactSolver.solveTOIPositionConstraints(toiIndexA, toiIndexB); + final contactsOkay = _toiContactSolver.solveTOIPositionConstraints( + toiIndexA, + toiIndexB, + ); if (contactsOkay) { break; } @@ -420,7 +425,8 @@ class Island { final translationY = v.y * dt; if (translationX * translationX + translationY * translationY > settings.maxTranslationSquared) { - final ratio = settings.maxTranslation / + final ratio = + settings.maxTranslation / sqrt(translationX * translationX + translationY * translationY); v.scale(ratio); } diff --git a/packages/forge2d/lib/src/dynamics/joints/constant_volume_joint.dart b/packages/forge2d/lib/src/dynamics/joints/constant_volume_joint.dart index ca2b164..de2b5d0 100644 --- a/packages/forge2d/lib/src/dynamics/joints/constant_volume_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/constant_volume_joint.dart @@ -29,8 +29,8 @@ class ConstantVolumeJoint extends Joint { } ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def) - : _bodies = def.bodies.toList(growable: false), - super(def) { + : _bodies = def.bodies.toList(growable: false), + super(def) { _world = argWorld; if (def.bodies.length <= 2) { throw "Can't create a constant volume joint with less than three bodies."; @@ -92,7 +92,8 @@ class ConstantVolumeJoint extends Joint { var area = 0.0; for (var i = 0; i < _bodies.length; ++i) { final next = (i == _bodies.length - 1) ? 0 : i + 1; - area += _bodies[i].worldCenter.x * _bodies[next].worldCenter.y - + area += + _bodies[i].worldCenter.x * _bodies[next].worldCenter.y - _bodies[next].worldCenter.x * _bodies[i].worldCenter.y; } return area *= .5; @@ -102,7 +103,8 @@ class ConstantVolumeJoint extends Joint { var area = 0.0; for (var i = 0; i < _bodies.length; ++i) { final next = (i == _bodies.length - 1) ? 0 : i + 1; - area += positions[_bodies[i].islandIndex].c.x * + area += + positions[_bodies[i].islandIndex].c.x * positions[_bodies[next].islandIndex].c.y - positions[_bodies[next].islandIndex].c.x * positions[_bodies[i].islandIndex].c.y; @@ -114,9 +116,11 @@ class ConstantVolumeJoint extends Joint { var perimeter = 0.0; for (var i = 0; i < _bodies.length; ++i) { final next = (i == _bodies.length - 1) ? 0 : i + 1; - final dx = positions[_bodies[next].islandIndex].c.x - + final dx = + positions[_bodies[next].islandIndex].c.x - positions[_bodies[i].islandIndex].c.x; - final dy = positions[_bodies[next].islandIndex].c.y - + final dy = + positions[_bodies[next].islandIndex].c.y - positions[_bodies[i].islandIndex].c.y; var dist = sqrt(dx * dx + dy * dy); if (dist < settings.epsilon) { @@ -198,7 +202,8 @@ class ConstantVolumeJoint extends Joint { (i) { final prev = (i == 0) ? _bodies.length - 1 : i - 1; final next = (i == _bodies.length - 1) ? 0 : i + 1; - final v = positions[_bodies[next].islandIndex].c - + final v = + positions[_bodies[next].islandIndex].c - positions[_bodies[prev].islandIndex].c; dotMassSum += (v.length2) / _bodies[i].mass; crossMassSum += velocities[_bodies[i].islandIndex].v.cross(v); diff --git a/packages/forge2d/lib/src/dynamics/joints/distance_joint.dart b/packages/forge2d/lib/src/dynamics/joints/distance_joint.dart index 7a3503a..6b391e9 100644 --- a/packages/forge2d/lib/src/dynamics/joints/distance_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/distance_joint.dart @@ -220,8 +220,10 @@ class DistanceJoint extends Joint { ..sub(rA); final length = u.normalize(); - final C = (length - _length) - .clamp(-settings.maxLinearCorrection, settings.maxLinearCorrection); + final C = (length - _length).clamp( + -settings.maxLinearCorrection, + settings.maxLinearCorrection, + ); final impulse = -_mass * C; final pX = impulse * u.x; diff --git a/packages/forge2d/lib/src/dynamics/joints/friction_joint.dart b/packages/forge2d/lib/src/dynamics/joints/friction_joint.dart index e58d9b2..d52193a 100644 --- a/packages/forge2d/lib/src/dynamics/joints/friction_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/friction_joint.dart @@ -22,8 +22,8 @@ class FrictionJoint extends Joint { double _angularMass = 0.0; FrictionJoint(FrictionJointDef def) - : _linearImpulse = Vector2.zero(), - super(def) { + : _linearImpulse = Vector2.zero(), + super(def) { _maxForce = def.maxForce; _maxTorque = def.maxTorque; } @@ -164,8 +164,10 @@ class FrictionJoint extends Joint { final oldImpulse = _angularImpulse; final maxImpulse = dt * _maxTorque; - _angularImpulse = - (_angularImpulse + impulse).clamp(-maxImpulse, maxImpulse); + _angularImpulse = (_angularImpulse + impulse).clamp( + -maxImpulse, + maxImpulse, + ); impulse = _angularImpulse - oldImpulse; wA -= iA * impulse; diff --git a/packages/forge2d/lib/src/dynamics/joints/gear_joint.dart b/packages/forge2d/lib/src/dynamics/joints/gear_joint.dart index 653aad6..e47b929 100644 --- a/packages/forge2d/lib/src/dynamics/joints/gear_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/gear_joint.dart @@ -81,11 +81,11 @@ class GearJoint extends Joint { double _mass = 0.0; GearJoint(GearJointDef def) - : _joint1 = def.joint1, - _joint2 = def.joint2, - _bodyC = def.joint1.bodyA, - _bodyD = def.joint2.bodyA, - super(def) { + : _joint1 = def.joint1, + _joint2 = def.joint2, + _bodyC = def.joint1.bodyA, + _bodyD = def.joint2.bodyA, + super(def) { assert( (_joint1 is RevoluteJoint || _joint1 is PrismaticJoint) && (_joint2 is RevoluteJoint || _joint2 is PrismaticJoint), @@ -325,7 +325,8 @@ class GearJoint extends Joint { final temp1 = Vector2.zero(); final temp2 = Vector2.zero(); - var cDot = _jvAC.dot( + var cDot = + _jvAC.dot( temp1 ..setFrom(vA) ..sub(vC), diff --git a/packages/forge2d/lib/src/dynamics/joints/joint.dart b/packages/forge2d/lib/src/dynamics/joints/joint.dart index e49cfc2..4c3d895 100644 --- a/packages/forge2d/lib/src/dynamics/joints/joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/joint.dart @@ -18,9 +18,9 @@ abstract class Joint { final Vector2 localAnchorB; Joint(JointDef def) - : assert(def.bodyA != def.bodyB), - localAnchorA = def.localAnchorA, - localAnchorB = def.localAnchorB { + : assert(def.bodyA != def.bodyB), + localAnchorA = def.localAnchorA, + localAnchorB = def.localAnchorB { bodyA = def.bodyA; bodyB = def.bodyB; _collideConnected = def.collideConnected; diff --git a/packages/forge2d/lib/src/dynamics/joints/motor_joint.dart b/packages/forge2d/lib/src/dynamics/joints/motor_joint.dart index 9c2e9a8..8fb5602 100644 --- a/packages/forge2d/lib/src/dynamics/joints/motor_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/motor_joint.dart @@ -242,8 +242,10 @@ class MotorJoint extends Joint { final oldImpulse = _angularImpulse; final maxImpulse = dt * _maxTorque; - _angularImpulse = - (_angularImpulse + impulse).clamp(-maxImpulse, maxImpulse); + _angularImpulse = (_angularImpulse + impulse).clamp( + -maxImpulse, + maxImpulse, + ); impulse = _angularImpulse - oldImpulse; wA -= iA * impulse; @@ -256,12 +258,14 @@ class MotorJoint extends Joint { { // Cdot = vB + b2Cross(wB, _rB) - vA - b2Cross(wA, _rA) + inv_h * // _correctionFactor * _linearError; - cDot.x = vB.x + + cDot.x = + vB.x + -wB * _rB.y - vA.x - -wA * _rA.y + invDt * _correctionFactor * _linearError.x; - cDot.y = vB.y + + cDot.y = + vB.y + wB * _rB.x - vA.y - wA * _rA.x + diff --git a/packages/forge2d/lib/src/dynamics/joints/mouse_joint.dart b/packages/forge2d/lib/src/dynamics/joints/mouse_joint.dart index 01c0c81..de3b93b 100644 --- a/packages/forge2d/lib/src/dynamics/joints/mouse_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/mouse_joint.dart @@ -30,11 +30,11 @@ class MouseJoint extends Joint { final Vector2 _c = Vector2.zero(); MouseJoint(MouseJointDef def) - : assert(!def.target.isInfinite && !def.target.isNaN), - assert(def.maxForce >= 0), - assert(def.frequencyHz >= 0), - assert(def.dampingRatio >= 0), - super(def) { + : assert(!def.target.isInfinite && !def.target.isNaN), + assert(def.maxForce >= 0), + assert(def.frequencyHz >= 0), + assert(def.dampingRatio >= 0), + super(def) { _targetA.setFrom(def.target); localAnchorB.setFrom(Transform.mulTransVec2(bodyB.transform, _targetA)); diff --git a/packages/forge2d/lib/src/dynamics/joints/prismatic_joint.dart b/packages/forge2d/lib/src/dynamics/joints/prismatic_joint.dart index 1767f51..afb6535 100644 --- a/packages/forge2d/lib/src/dynamics/joints/prismatic_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/prismatic_joint.dart @@ -123,11 +123,11 @@ class PrismaticJoint extends Joint { 0.0; // effective mass for motor/limit translational constraint. PrismaticJoint(PrismaticJointDef def) - : localAnchorA = Vector2.copy(def.localAnchorA), - localAnchorB = Vector2.copy(def.localAnchorB), - localXAxisA = Vector2.copy(def.localAxisA)..normalize(), - _localYAxisA = Vector2.zero(), - super(def) { + : localAnchorA = Vector2.copy(def.localAnchorA), + localAnchorB = Vector2.copy(def.localAnchorB), + localXAxisA = Vector2.copy(def.localAxisA)..normalize(), + _localYAxisA = Vector2.zero(), + super(def) { localXAxisA.scaleOrthogonalInto(1.0, _localYAxisA); _referenceAngle = def.referenceAngle; @@ -642,17 +642,19 @@ class PrismaticJoint extends Joint { ..sub(rA); axis.setFrom(Rot.mulVec2(qA, localXAxisA)); - final a1 = (temp - ..setFrom(d) - ..add(rA)) - .cross(axis); + final a1 = + (temp + ..setFrom(d) + ..add(rA)) + .cross(axis); final a2 = rB.cross(axis); perp.setFrom(Rot.mulVec2(qA, _localYAxisA)); - final s1 = (temp - ..setFrom(d) - ..add(rA)) - .cross(perp); + final s1 = + (temp + ..setFrom(d) + ..add(rA)) + .cross(perp); final s2 = rB.cross(perp); c1.x = perp.dot(d); @@ -676,14 +678,18 @@ class PrismaticJoint extends Joint { active = true; } else if (translation <= _lowerTranslation) { // Prevent large linear corrections and allow some slop. - c2 = (translation - _lowerTranslation + settings.linearSlop) - .clamp(-settings.maxLinearCorrection, 0.0); + c2 = (translation - _lowerTranslation + settings.linearSlop).clamp( + -settings.maxLinearCorrection, + 0.0, + ); linearError = max(linearError, _lowerTranslation - translation); active = true; } else if (translation >= _upperTranslation) { // Prevent large linear corrections and allow some slop. - c2 = (translation - _upperTranslation - settings.linearSlop) - .clamp(0.0, settings.maxLinearCorrection); + c2 = (translation - _upperTranslation - settings.linearSlop).clamp( + 0.0, + settings.maxLinearCorrection, + ); linearError = max(linearError, translation - _upperTranslation); active = true; } diff --git a/packages/forge2d/lib/src/dynamics/joints/revolute_joint.dart b/packages/forge2d/lib/src/dynamics/joints/revolute_joint.dart index bddac9b..dcf1b61 100644 --- a/packages/forge2d/lib/src/dynamics/joints/revolute_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/revolute_joint.dart @@ -360,16 +360,20 @@ class RevoluteJoint extends Joint { angularError = -C; // Prevent large angular corrections and allow some slop. - C = (C + settings.angularSlop) - .clamp(-settings.maxAngularCorrection, 0.0); + C = (C + settings.angularSlop).clamp( + -settings.maxAngularCorrection, + 0.0, + ); limitImpulse = -_motorMass * C; } else if (_limitState == LimitState.atUpper) { var C = angle - _upperAngle; angularError = C; // Prevent large angular corrections and allow some slop. - C = (C - settings.angularSlop) - .clamp(0.0, settings.maxAngularCorrection); + C = (C - settings.angularSlop).clamp( + 0.0, + settings.maxAngularCorrection, + ); limitImpulse = -_motorMass * C; } diff --git a/packages/forge2d/lib/src/dynamics/joints/weld_joint.dart b/packages/forge2d/lib/src/dynamics/joints/weld_joint.dart index 04dc753..3aa2d0a 100644 --- a/packages/forge2d/lib/src/dynamics/joints/weld_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/weld_joint.dart @@ -47,10 +47,10 @@ class WeldJoint extends Joint { final Matrix3 _mass = Matrix3.zero(); WeldJoint(WeldJointDef def) - : localAnchorA = Vector2.copy(def.localAnchorA), - localAnchorB = Vector2.copy(def.localAnchorB), - _impulse = Vector3.zero(), - super(def) { + : localAnchorA = Vector2.copy(def.localAnchorA), + localAnchorB = Vector2.copy(def.localAnchorB), + _impulse = Vector3.zero(), + super(def) { _referenceAngle = def.referenceAngle; _frequencyHz = def.frequencyHz; _dampingRatio = def.dampingRatio; diff --git a/packages/forge2d/lib/src/dynamics/joints/wheel_joint.dart b/packages/forge2d/lib/src/dynamics/joints/wheel_joint.dart index 4415782..f9374ea 100644 --- a/packages/forge2d/lib/src/dynamics/joints/wheel_joint.dart +++ b/packages/forge2d/lib/src/dynamics/joints/wheel_joint.dart @@ -225,10 +225,11 @@ class WheelJoint extends Joint { // Point to line constraint { _ay.setFrom(Rot.mulVec2(qA, _localYAxisA)); - _sAy = (temp - ..setFrom(d) - ..add(rA)) - .cross(_ay); + _sAy = + (temp + ..setFrom(d) + ..add(rA)) + .cross(_ay); _sBy = rB.cross(_ay); _mass = mA + mB + iA * _sAy * _sAy + iB * _sBy * _sBy; @@ -244,10 +245,11 @@ class WheelJoint extends Joint { _gamma = 0.0; if (_frequencyHz > 0.0) { _ax.setFrom(Rot.mulVec2(qA, _localXAxisA)); - _sAx = (temp - ..setFrom(d) - ..add(rA)) - .cross(_ax); + _sAx = + (temp + ..setFrom(d) + ..add(rA)) + .cross(_ax); _sBx = rB.cross(_ax); final invMass = mA + mB + iA * _sAx * _sAx + iB * _sBx * _sBx; @@ -341,7 +343,8 @@ class WheelJoint extends Joint { // Solve spring constraint { - final cDot = _ax.dot( + final cDot = + _ax.dot( temp ..setFrom(vB) ..sub(vA), @@ -381,7 +384,8 @@ class WheelJoint extends Joint { // Solve point to line constraint { - final cDot = _ay.dot( + final cDot = + _ay.dot( temp ..setFrom(vB) ..sub(vA), @@ -441,10 +445,11 @@ class WheelJoint extends Joint { ..sub(rA); final ay = Vector2.copy(Rot.mulVec2(qA, _localYAxisA)); - final sAy = (temp - ..setFrom(d) - ..add(rA)) - .cross(ay); + final sAy = + (temp + ..setFrom(d) + ..add(rA)) + .cross(ay); final sBy = rB.cross(ay); final c = d.dot(ay); diff --git a/packages/forge2d/lib/src/dynamics/world.dart b/packages/forge2d/lib/src/dynamics/world.dart index 9ec531b..4f0b32e 100644 --- a/packages/forge2d/lib/src/dynamics/world.dart +++ b/packages/forge2d/lib/src/dynamics/world.dart @@ -70,7 +70,7 @@ class World { late ParticleSystem particleSystem; World([Vector2? gravity, BroadPhase? broadPhase]) - : _gravity = Vector2.copy(gravity ?? Vector2.zero()) { + : _gravity = Vector2.copy(gravity ?? Vector2.zero()) { broadPhase ??= DefaultBroadPhaseBuffer(DynamicTree()); _warmStarting = true; diff --git a/packages/forge2d/lib/src/particle/particle_system.dart b/packages/forge2d/lib/src/particle/particle_system.dart index ad62c09..2fe774c 100644 --- a/packages/forge2d/lib/src/particle/particle_system.dart +++ b/packages/forge2d/lib/src/particle/particle_system.dart @@ -233,12 +233,16 @@ class ParticleSystem { } final upperBoundY = aabb.upperBound.y; final upperBoundX = aabb.upperBound.x; - for (var y = (aabb.lowerBound.y / stride).floor() * stride; - y < upperBoundY; - y += stride) { - for (var x = (aabb.lowerBound.x / stride).floor() * stride; - x < upperBoundX; - x += stride) { + for ( + var y = (aabb.lowerBound.y / stride).floor() * stride; + y < upperBoundY; + y += stride + ) { + for ( + var x = (aabb.lowerBound.x / stride).floor() * stride; + x < upperBoundX; + x += stride + ) { final p = _tempVec..setValues(x, y); if (shape.testPoint(identity, p)) { p.setFrom(Transform.mulVec2(transform, p)); @@ -277,8 +281,10 @@ class ParticleSystem { diagram.addGenerator(particle.position, particle); } diagram.generate(stride / 2); - final createParticleGroupCallback = - CreateParticleGroupCallback(this, groupDef); + final createParticleGroupCallback = CreateParticleGroupCallback( + this, + groupDef, + ); diagram.nodes(createParticleGroupCallback); } if ((groupDef.groupFlags & ParticleGroupType.solidParticleGroup) != 0) { @@ -532,8 +538,9 @@ class ParticleSystem { v.y += gravityY; final v2 = v.x * v.x + v.y * v.y; if (v2 > criticalVelocitySquared) { - final a = - v2 == 0 ? double.maxFinite : sqrt(criticalVelocitySquared / v2); + final a = v2 == 0 + ? double.maxFinite + : sqrt(criticalVelocitySquared / v2); v.x *= a; v.y *= a; } @@ -602,7 +609,8 @@ class ParticleSystem { final pressurePerWeight = pressureStrength * getCriticalPressure(step); for (final particle in _particles) { final w = particle.accumulation; - final h = pressurePerWeight * + final h = + pressurePerWeight * max( 0.0, min(w, settings.maxParticleWeight) - settings.minParticleWeight, diff --git a/packages/forge2d/pubspec.yaml b/packages/forge2d/pubspec.yaml index 74efc20..271b98b 100644 --- a/packages/forge2d/pubspec.yaml +++ b/packages/forge2d/pubspec.yaml @@ -2,16 +2,18 @@ name: forge2d version: 0.14.0 description: A 2D physics engine for Dart (based on Box2D), also works with the Flame game engine in Flutter homepage: https://github.com/flame-engine/forge2d +resolution: workspace environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" dependencies: - meta: ^1.11.0 - vector_math: ^2.1.4 + meta: ^1.17.0 + vector_math: ^2.2.0 + web: ^1.1.1 dev_dependencies: - dartdoc: ^7.0.2 - flame_lint: ^1.1.1 - mocktail: ^1.0.1 - test: ^1.24.9 + dartdoc: ^8.3.4 + flame_lint: ^1.4.1 + mocktail: ^1.0.4 + test: ^1.26.3 diff --git a/packages/forge2d/test/collision/shapes/circle_shape_test.dart b/packages/forge2d/test/collision/shapes/circle_shape_test.dart index ecd1265..8cc470f 100644 --- a/packages/forge2d/test/collision/shapes/circle_shape_test.dart +++ b/packages/forge2d/test/collision/shapes/circle_shape_test.dart @@ -35,8 +35,12 @@ void main() { final position = Vector2(1.0, 2.0); final circleShape = CircleShape(radius: radius, position: position); final normal = Vector2.zero(); - final distance = - circleShape.computeDistanceToOut(tf, testPoint, 0, normal); + final distance = circleShape.computeDistanceToOut( + tf, + testPoint, + 0, + normal, + ); expect(distance, closeTo(expectedDistance, 0.01)); expect(normal.x, closeTo(expectedNormal.x, 0.01)); expect(normal.y, closeTo(expectedNormal.y, 0.01)); diff --git a/packages/forge2d/test/collision/shapes/polygon_shape_test.dart b/packages/forge2d/test/collision/shapes/polygon_shape_test.dart index 6c2e549..637310d 100644 --- a/packages/forge2d/test/collision/shapes/polygon_shape_test.dart +++ b/packages/forge2d/test/collision/shapes/polygon_shape_test.dart @@ -42,8 +42,12 @@ void main() { ) { final polygonShape = PolygonShape()..setAsBoxXY(3, 4); final normal = Vector2.zero(); - final distance = - polygonShape.computeDistanceToOut(tf, testPoint, 0, normal); + final distance = polygonShape.computeDistanceToOut( + tf, + testPoint, + 0, + normal, + ); expect(distance, closeTo(expectedDistance, 0.01)); expect(normal.x, closeTo(expectedNormal.x, 0.01)); expect(normal.y, closeTo(expectedNormal.y, 0.01)); diff --git a/packages/forge2d/test/dynamics/body_test.dart b/packages/forge2d/test/dynamics/body_test.dart index 9f5b288..5805eea 100644 --- a/packages/forge2d/test/dynamics/body_test.dart +++ b/packages/forge2d/test/dynamics/body_test.dart @@ -38,8 +38,7 @@ void main() { expect(bodyInitialPosition.y, equals(body.position.y)); }); - test( - "body moves with world's gravity " + test("body moves with world's gravity " 'when gravityOverride is not specfied', () { final gravity = Vector2(10, 10); final world = World(gravity); @@ -70,8 +69,7 @@ void main() { expect(bodyInitialPosition.y, equals(body.position.y)); }); - test( - "body moves with world's gravity " + test("body moves with world's gravity " 'when gravityScale is not specfied', () { final gravity = Vector2(10, 10); final world = World(gravity); diff --git a/packages/forge2d/test/dynamics/joints/gear_joint_test.dart b/packages/forge2d/test/dynamics/joints/gear_joint_test.dart index 8ccf02a..91f966e 100644 --- a/packages/forge2d/test/dynamics/joints/gear_joint_test.dart +++ b/packages/forge2d/test/dynamics/joints/gear_joint_test.dart @@ -140,32 +140,36 @@ void main() { group('returns normally', () { test('when joint1 and joint2 are both RevoluteJoints', () { expect( - () => GearJoint(revoluteRevoluteGearJointDef) - .initVelocityConstraints(data), + () => GearJoint( + revoluteRevoluteGearJointDef, + ).initVelocityConstraints(data), returnsNormally, ); }); test('when joint1 is RevoluteJoint and joint2 is PrismaticJoint', () { expect( - () => GearJoint(revolutePrismaticGearJointDef) - .initVelocityConstraints(data), + () => GearJoint( + revolutePrismaticGearJointDef, + ).initVelocityConstraints(data), returnsNormally, ); }); test('when joint1 is PrismaticJoint and joint2 is RevoluteJoint', () { expect( - () => GearJoint(prismaticRevoluteGearJointDef) - .initVelocityConstraints(data), + () => GearJoint( + prismaticRevoluteGearJointDef, + ).initVelocityConstraints(data), returnsNormally, ); }); test('when joint1 and joint2 are both PrismaticJoints', () { expect( - () => GearJoint(prismaticPrismaticGearJointDef) - .initVelocityConstraints(data), + () => GearJoint( + prismaticPrismaticGearJointDef, + ).initVelocityConstraints(data), returnsNormally, ); }); @@ -185,32 +189,36 @@ void main() { group('returns normally', () { test('when joint1 and joint2 are both RevoluteJoints', () { expect( - () => GearJoint(revoluteRevoluteGearJointDef) - .solvePositionConstraints(data), + () => GearJoint( + revoluteRevoluteGearJointDef, + ).solvePositionConstraints(data), returnsNormally, ); }); test('when joint1 is RevoluteJoint and joint2 is PrismaticJoint', () { expect( - () => GearJoint(revolutePrismaticGearJointDef) - .solvePositionConstraints(data), + () => GearJoint( + revolutePrismaticGearJointDef, + ).solvePositionConstraints(data), returnsNormally, ); }); test('when joint1 is PrismaticJoint and joint2 is RevoluteJoint', () { expect( - () => GearJoint(prismaticRevoluteGearJointDef) - .solvePositionConstraints(data), + () => GearJoint( + prismaticRevoluteGearJointDef, + ).solvePositionConstraints(data), returnsNormally, ); }); test('when joint1 and joint2 are both PrismaticJoints', () { expect( - () => GearJoint(prismaticPrismaticGearJointDef) - .solvePositionConstraints(data), + () => GearJoint( + prismaticPrismaticGearJointDef, + ).solvePositionConstraints(data), returnsNormally, ); }); @@ -227,32 +235,28 @@ void main() { registerFallbackValue(Color3i.black()); }); - test( - 'draws three segments ' + test('draws three segments ' 'when joint1 and joint2 are both RevoluteJoints', () { final joint = GearJoint(revoluteRevoluteGearJointDef); joint.render(debugDraw); verify(() => debugDraw.drawSegment(any(), any(), any())).called(3); }); - test( - 'draws three segments ' + test('draws three segments ' 'when joint1 is RevoluteJoint and joint2 is PrismaticJoint', () { final joint = GearJoint(revolutePrismaticGearJointDef); joint.render(debugDraw); verify(() => debugDraw.drawSegment(any(), any(), any())).called(3); }); - test( - 'draws three segments ' + test('draws three segments ' 'when joint1 is PrismaticJoint and joint2 is RevoluteJoint', () { final joint = GearJoint(prismaticRevoluteGearJointDef); joint.render(debugDraw); verify(() => debugDraw.drawSegment(any(), any(), any())).called(3); }); - test( - 'draws three segments ' + test('draws three segments ' 'when joint1 and joint2 are both PrismaticJoints', () { final joint = GearJoint(prismaticPrismaticGearJointDef); joint.render(debugDraw); diff --git a/pubspec.yaml b/pubspec.yaml index 1c98e91..5b23ec6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,82 @@ name: forge2d_workspace +repository: https://github.com/flame-engine/forge2d +workspace: + - packages/benchmark + - packages/forge2d + - packages/forge2d/example environment: - sdk: ">=3.0.0 <4.0.0" + sdk: ">=3.8.0 <4.0.0" dev_dependencies: - melos: ^3.2.0 + melos: ^7.0.0-dev.9 + +melos: + command: + version: + # Only allow versioning to happen on main branch. + branch: main + # Generates a link to a prefilled GitHub release creation page. + releaseUrl: true + includeCommitId: true + linkToCommits: true + + bootstrap: + environment: + sdk: ">=3.8.0 <4.0.0" + + scripts: + lint:all: + run: melos run analyze && melos run format + description: Run all static analysis checks. + + analyze: + run: | + melos exec -c 1 -- \ + dart analyze --fatal-infos + description: Run `dart analyze` for all packages. + + format: + run: melos exec dart format . --fix + description: Run `dart format` for all packages. + + format-check: + run: melos exec dart format . --set-exit-if-changed + description: Run `dart format` checks for all packages. + + dartdoc: + run: melos exec dart pub run dartdoc + description: Run dartdoc checks for all packages. + + test:select: + run: melos exec -c 1 -- dart test + packageFilters: + dirExists: test + description: Run `dart test` for selected packages. + + test: + run: melos run test:select --no-select + description: Run all tests in this project. + + coverage: + run: | + melos exec -- dart test --coverage && + melos exec -- genhtml coverage/lcov.info --output-directory=coverage/ + packageFilters: + dirExists: test + description: Generate coverage for the selected package. + + benchmark: + run: melos exec -- dart web/bench2d.dart + packageFilters: + scope: forge2d_benchmark + + benchmark_serve: + run: melos exec -- dart pub global run webdev serve --release + packageFilters: + scope: forge2d_benchmark + + example: + run: melos exec -- dart pub global run webdev serve --release + packageFilters: + scope: forge2d_examples