mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
66 lines
1.2 KiB
JavaScript
66 lines
1.2 KiB
JavaScript
var Utils = require('../utils/Utils');
|
|
|
|
module.exports = Solver;
|
|
|
|
/**
|
|
* Base class for constraint solvers.
|
|
* @class Solver
|
|
* @constructor
|
|
*/
|
|
function Solver(){
|
|
|
|
/**
|
|
* Current equations in the solver.
|
|
*
|
|
* @property equations
|
|
* @type {Array}
|
|
*/
|
|
this.equations = [];
|
|
};
|
|
|
|
Solver.prototype.solve = function(dt,world){
|
|
throw new Error("Solver.solve should be implemented by subclasses!");
|
|
};
|
|
|
|
/**
|
|
* Add an equation to be solved.
|
|
*
|
|
* @method addEquation
|
|
* @param {Equation} eq
|
|
*/
|
|
Solver.prototype.addEquation = function(eq){
|
|
this.equations.push(eq);
|
|
};
|
|
|
|
/**
|
|
* Add equations. Same as .addEquation, but this time the argument is an array of Equations
|
|
*
|
|
* @method addEquations
|
|
* @param {Array} eqs
|
|
*/
|
|
Solver.prototype.addEquations = function(eqs){
|
|
Utils.appendArray(this.equations,eqs);
|
|
};
|
|
|
|
/**
|
|
* Remove an equation.
|
|
*
|
|
* @method removeEquation
|
|
* @param {Equation} eq
|
|
*/
|
|
Solver.prototype.removeEquation = function(eq){
|
|
var i = this.equations.indexOf(eq);
|
|
if(i!=-1)
|
|
this.equations.splice(i,1);
|
|
};
|
|
|
|
/**
|
|
* Remove all currently added equations.
|
|
*
|
|
* @method removeAllEquations
|
|
*/
|
|
Solver.prototype.removeAllEquations = function(){
|
|
this.equations.length=0;
|
|
};
|
|
|