An ODESim simulation that detects and handles collisions between objects.

interface CollisionSim<T> {
    addObserver(observer): void;
    broadcast(evt): void;
    broadcastParameter(name): void;
    evaluate(vars, change, timeStep): null | object;
    findCollisions(collisions, vars, stepSize): void;
    getName(): string;
    getObservers(): Observer[];
    getParameter(name): Parameter;
    getParameterBoolean(name): ParameterBoolean;
    getParameterNumber(name): ParameterNumber;
    getParameterString(name): ParameterString;
    getParameters(): Parameter[];
    getSimList(): SimList;
    getTime(): number;
    getVarsList(): VarsList;
    handleCollisions(collisions, opt_totals?): boolean;
    modifyObjects(): void;
    removeObserver(observer): void;
    reset(): void;
    restoreState(): void;
    saveInitialState(): void;
    saveState(): void;
    setDebugPaint(fn): void;
    setTerminal(terminal): void;
    toStringShort(): string;
}

Type Parameters

Hierarchy (view full)

Implemented by

Methods

  • Adds the given Observer to this Subject's list of Observers, so that the Observer will be notified of changes in this Subject. An Observer may call Subject.addObserver during its observe method.

    Parameters

    Returns void

  • Notifies all Observers that the Parameter with the given name has changed by calling observe on each Observer.

    Parameters

    • name: string

      the language-independent or English name of the Parameter that has changed

    Returns void

    Throws

    if there is no Parameter with the given name

  • Defines the differential equations of this ODESim; for an input set of variables, returns the current rate of change for each variable (the first derivative of each variable with respect to time).

    The timeStep is the time since the state variables were last fully calculated, which can be and often is zero. The current time can be regarded as getTime() + timeStep. The input variables correspond to the Simulation state at that time. Note that timeStep is different from the time step used to advance the Simulation (as in AdvanceStrategy.advance). The timeStep is typically used when finding collisions in CollisionSim.findCollisions.

    Parameters

    • vars: number[]

      the current array of state variables (input), corresponding to the state at getTime() + timeStep

    • change: number[]

      array of change rates for each variable (output), all values are zero on entry.

    • timeStep: number

      the current time step (might be zero)

    Returns null | object

    null if the evaluation succeeds, otherwise an object relating to the error that occurred. The change array contains the output results.

  • Finds collisions based on the passed in state variables. Can rely on modifyObjects having been called prior, with this set of state variables. Uses the state saved by saveState as the 'before' state for comparison.

    The list of collisions that are passed in can potentially have collisions from the near future that were found previously. The CollisionSim should avoid adding collisions that are duplicates of those already on the list.

    Parameters

    • collisions: T[]

      the list of collisions to add to

    • vars: number[]

      the current array of state variables

    • stepSize: number

      the size of the current time step, in seconds

    Returns void

  • Return the language-independent name of this Subject for scripting purposes.

    Returns string

    name the language-independent name of this Subject

  • Returns the Parameter with the given name.

    Parameters

    • name: string

      the language-independent or English name of the Parameter

    Returns Parameter

    the Parameter with the given name

    Throws

    if there is no Parameter with the given name

  • Returns the current Simulation time.

    Returns number

    the current Simulation time.

    Throws

    if there is no time variable for the simulation

  • Adjusts the simulation state based on the given Collisions. For example, this might reverse the velocities of objects colliding against a wall. The simulation state is contained in the vars array of state variables from getVarsList.

    Note that these Collisions will typically be from the very near future; CollisionAdvance backs up to just before the moment of collision before handling Collisions.

    Parameters

    • collisions: T[]

      the list of current collisions

    • Optional opt_totals: CollisionTotals

      CollisionTotals object to update with number of collisions handled

    Returns boolean

    true if was able to handle the collision, changing state of simulation.

  • Removes the Observer from this Subject's list of Observers. An Observer may call removeObserver during its observe method.

    Parameters

    • observer: Observer

      the Observer to detach from list of Observers

    Returns void

  • Saves the current state of the Simulation, so that we can back up to this state later on. The state is defined mainly by the set of Simulation variables, see getVarsList, but can include other data. This state is typically used for collision detection as the before collision state, see CollisionSim.findCollisions.

    Returns void

  • For debugging, specify a function that will paint canvases, so that you can see the simulation while stepping thru with debugger.

    Parameters

    • fn: null | (() => void)

      function that will paint canvases

    Returns void

  • Sets the Terminal object that this simulation can print data into.

    Parameters

    • terminal: null | Terminal

      the Terminal object that this simulation can print data into.

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc