r3-legacy/src/game-lib-d3-api-solver.js

70 lines
1.5 KiB
JavaScript

/**
* Raw Solver API object - should always correspond with the Solver Schema
* @param id
* @param name
* @param solverType
* @param iterations
* @param tolerance
* @param parentEntity
* @constructor
*/
GameLib.D3.API.Solver = function(
id,
name,
solverType,
iterations,
tolerance,
parentEntity
) {
if (GameLib.Utils.UndefinedOrNull(id)) {
id = GameLib.Utils.RandomId();
}
this.id = id;
if (GameLib.Utils.UndefinedOrNull(name)) {
name = 'Solver (' + this.id + ')';
}
this.name = name;
if (GameLib.Utils.UndefinedOrNull(solverType)) {
solverType = GameLib.D3.Solver.GS_SOLVER;
}
this.solverType = solverType;
if (GameLib.Utils.UndefinedOrNull(iterations)) {
iterations = 10;
}
this.iterations = iterations;
if (GameLib.Utils.UndefinedOrNull(tolerance)) {
tolerance = 1e-7;
}
this.tolerance = tolerance;
if (GameLib.Utils.UndefinedOrNull(parentEntity)) {
parentEntity = null;
}
this.parentEntity = parentEntity;
};
GameLib.D3.API.Solver.prototype = Object.create(GameLib.Component.prototype);
GameLib.D3.API.Solver.prototype.constructor = GameLib.D3.API.Solver;
/**
* Creates an API Solver from an Object Solver
* @param objectSolver
* @constructor
*/
GameLib.D3.API.Solver.FromObject = function(objectSolver) {
return new GameLib.D3.API.Solver(
objectSolver.id,
objectSolver.name,
objectSolver.solverType,
objectSolver.iterations,
objectSolver.tolerance,
objectSolver.parentEntity
);
};