EnvironmentWithDynamics

class EnvironmentWithDynamics<T>(incarnation: Incarnation<T, Euclidean2DPosition>, path: String? = null, zoom: Double = 1.0, dx: Double = 0.0, dy: Double = 0.0, obstaclesColor: Int = Color.BLACK.rgb, roomsColor: Int = Color.BLUE.rgb, backingEnvironment: Physics2DEnvironment<T> = path?.let { ImageEnvironmentWithGraph(incarnation, it, zoom, dx, dy, obstaclesColor, roomsColor) } ?: ContinuousPhysics2DEnvironment(incarnation)) : Dynamics2DEnvironment<T> , EuclideanPhysics2DEnvironmentWithObstacles<RectObstacle2D<Euclidean2DPosition>, T>

This Environment uses hooks provided by Dynamics2DEnvironment to update the physical world, It also applies physical properties to any added node to perform collision detection and response. If an image path is provided a backing ImageEnvironmentWithGraph is used, otherwise the Continuous2DEnvironment will be used.

Constructors

Link copied to clipboard
constructor(incarnation: Incarnation<T, Euclidean2DPosition>, path: String? = null, zoom: Double = 1.0, dx: Double = 0.0, dy: Double = 0.0, obstaclesColor: Int = Color.BLACK.rgb, roomsColor: Int = Color.BLUE.rgb, backingEnvironment: Physics2DEnvironment<T> = path?.let { ImageEnvironmentWithGraph(incarnation, it, zoom, dx, dy, obstaclesColor, roomsColor) } ?: ContinuousPhysics2DEnvironment(incarnation))

Properties

Link copied to clipboard
open override val dimensions: Int

The number of dimensions of this environment.

Link copied to clipboard
open override val globalReactions: <Error class: unknown class><GlobalReaction<T>>

Get the Environment's GlobalReactions.

Link copied to clipboard

Return the Incarnation used to initialize the entities of this Environment, if it has been set.

Link copied to clipboard
open override val isTerminated: Boolean

Return true if all the terminators are true.

Link copied to clipboard
open override val layers: <Error class: unknown class><Layer<T, P>>

Return all the Layers in this Environment.

Link copied to clipboard

Returns the current LinkingRule.

Link copied to clipboard
open override val nodeCount: Int

Returns the number of Nodes currently in the Environment.

Link copied to clipboard
open override val nodes: <Error class: unknown class><Node<T>>

Returns all the Nodes that exist in current Environment.

Link copied to clipboard

A list of all the obstacles in this environment.

Link copied to clipboard
open override val offset: DoubleArray

This method allows to know which are the smallest coordinates represented. Return an array of length dimensions containing the smallest coordinates for each dimension.

Link copied to clipboard
open override val origin: Euclidean2DPosition

Create a position corresponding to the origin of this environment.

Link copied to clipboard

A factory of shapes compatible with this environment.

Link copied to clipboard

Return the current Simulation, if present, or throws an IllegalStateException otherwise.

Link copied to clipboard

Return the current Simulation, if present, or null otherwise.

Link copied to clipboard
open override val size: DoubleArray

The size of the environment as an array of length getDimensions(). This method must return distance measured with the same unit used by the positions. No non-euclidean distance metrics are allowed.

Link copied to clipboard
open override val sizeInDistanceUnits: DoubleArray

This method returns the size of the environment as an array of length .getDimensions. This method must return distance measured with the same unit used for measuring distances. It may or may not return the same result of .getSize.

Functions

Link copied to clipboard
open override fun addGlobalReaction(reaction: GlobalReaction<T>)

Add a GlobalReaction to the Environment.

Link copied to clipboard
open override fun addLayer(molecule: Molecule, layer: Layer<T, Euclidean2DPosition>)

Add a Layer to the Environment.

Link copied to clipboard
open override fun addNode(node: Node<T>, position: Euclidean2DPosition): Boolean

This method allows to add a new node to this environment in a specific position. The environment is responsible to call the right method of the simulation in order to ensure that the reaction is properly scheduled. The function returns true if the node is added to the environment.

Link copied to clipboard
open override fun addObstacle(obstacle: RectObstacle2D<Euclidean2DPosition>)

Adds an obstacle to this environment.

Link copied to clipboard
open override fun addTerminator(terminator: TerminationPredicate<T, Euclidean2DPosition>)

Add a terminator indicating whether the simulation should be considered finished.

open override fun addTerminator(terminator: (Environment<T, Euclidean2DPosition>) -> Boolean)

Add a terminator indicating whether the simulation should be considered finished.

Link copied to clipboard
open override fun farthestPositionReachable(node: Node<T>, desiredPosition: Euclidean2DPosition, hitboxRadius: Double): Euclidean2DPosition

Computes the farthest position reachable by a node towards a desiredPosition, avoiding node overlapping. If no node is located in between, desiredPosition is returned. Otherwise, the first position where the node collides with someone else is returned. For collision purposes, hitboxes are used: each node is given a circular hitbox of radius equal to its shape's radius (shapeless nodes can't cause overlapping). The client can specify a different radius for the hitbox of the moving node.

Link copied to clipboard
open override fun getDistanceBetweenNodes(n1: Node<T>, n2: Node<T>): Double

Measures the distance between two nodes (n1, n2) in the environment.

Link copied to clipboard
open override fun getHeading(node: Node<T>): Euclidean2DPosition

Gets the heading of a node as a direction vector.

Link copied to clipboard
open override fun getLayer(molecule: Molecule): Layer<T, Euclidean2DPosition>?

Get the Layer associate to the given molecule. If no Layer is associated with the given molecule, return null.

Link copied to clipboard
open override fun getNeighborhood(node: Node<T>): Neighborhood<T>

Given a node, this method returns its neighborhood.

Link copied to clipboard
open override fun getNodeByID(id: Int): Node<T>

Allows to access a Node in this Environment known its id. Depending on the implementation, this method may or not be optimized (namely, id could run in constant or linear time with the number of nodes).

Link copied to clipboard

Gets all nodes whose shape.intersect is true for the given shape.

Link copied to clipboard
open override fun getNodesWithinRange(node: Node<T>, range: Double): <Error class: unknown class><Node<T>>

Given a node this method returns a list of all the surroundings nodes within the given range. Note that this method (depending on the implementation) might be not optimized, and it's consequently much better to use Environment.getNeighborhood and filter the neighborhood if you are sure that all the nodes within the range are connected to the center.

open override fun getNodesWithinRange(position: Euclidean2DPosition, range: Double): <Error class: unknown class><Node<T>>

Given a position this method returns a list of all the surroundings nodes within the given range. Note that this method (depending on the implementation) might be not optimized.

Link copied to clipboard

Given a point and a range, retrieves all the obstacles within.

open override fun getObstaclesInRange(centerx: Double, centery: Double, range: Double): List<RectObstacle2D<Euclidean2DPosition>>

Given a point and a range, retrieves all the obstacles within. This function is maintained for compatibility with the previous version of the API, and may be deprecated in the future.

Link copied to clipboard
open override fun getPosition(node: Node<T>): Euclidean2DPosition

Calculates the position of a node.

Link copied to clipboard

Gets the shape of a node relatively to its position and heading in the environment.

Link copied to clipboard
open override fun getVelocity(node: Node<T>): Euclidean2DPosition

Get node's current linear velocity.

Link copied to clipboard
open override fun hasMobileObstacles(): Boolean
Link copied to clipboard

Checks whether there is at least an obstacle intersecting the line connecting start and end.

Link copied to clipboard
open operator override fun iterator(): Iterator<Node<T>>
Link copied to clipboard
open override fun makePosition(vararg coordinates: Number): Euclidean2DPosition
open override fun makePosition(coordinates: List<Number>): Euclidean2DPosition

Given the coordinates of the point, returns a Position compatible with this environment.

open override fun makePosition(x: Double, y: Double): Euclidean2DPosition
open override fun makePosition(x: Number, y: Number): Euclidean2DPosition

Creates a new Euclidean2DPosition.

Link copied to clipboard
open override fun moveNode(node: Node<T>, direction: Euclidean2DPosition)

This method moves a node in the environment toward some direction. If node move is unsupported, it does nothing. Subclasses may override this method if they want to change the way a node moves towards some direction. The current implementation internally calls {@link #moveNodeToPosition(Node, Position2D)}, as such, overriding that method may suffice.

Link copied to clipboard
open override fun moveNodeToPosition(node: Node<T>, position: Euclidean2DPosition)

This method moves a node in the environment to some position. If node move is unsupported, it does nothing.

Link copied to clipboard
open override fun next(current: Euclidean2DPosition, desired: Euclidean2DPosition): Euclidean2DPosition

This method must calculate the ABSOLUTE next allowed position given the current position and the position in which the node wants to move. For example, if your node is in position 2,3, wants to move to 3,4 but the next allowed position (because, e.g., of physical obstacles) is 2.5,3.5, the result must be a Position containing coordinates 2.5,3.5.

Link copied to clipboard
fun <R> Iterable<R>.randomElement(randomGenerator: <Error class: unknown class>): R

Returns a random element of the Iterable using the provided randomGenerator.

Link copied to clipboard
open override fun removeGlobalReaction(reaction: GlobalReaction<T>)

Remove a GlobalReaction from the Environment.

Link copied to clipboard
open override fun removeNode(node: Node<T>)

This method allows to remove a node. If node removal is unsupported, it does nothing.

Link copied to clipboard

Removes an obstacle from this environment.

Link copied to clipboard
open override fun setHeading(node: Node<T>, direction: Euclidean2DPosition)

Sets the heading of a node.

Link copied to clipboard
open override fun setVelocity(node: Node<T>, velocity: Euclidean2DPosition): <Error class: unknown class>

Set node's current linear velocity.

Link copied to clipboard
fun <R> Iterable<R>.shuffled(randomGenerator: <Error class: unknown class>): Iterable<R>

Fisher–Yates shuffle algorithm using a RandomGenerator. More information on Wikipedia.

Link copied to clipboard
fun <T, P : Position<out P>, TS : Any> Environment<T, P>.toEnvironmentSurrogate(toConcentrationSurrogate: (T) -> TS): EnvironmentSurrogate<TS, PositionSurrogate>

A function that maps an Environment to its surrogate class (EnvironmentSurrogate). Use the toSuitablePositionSurrogate strategy for PositionSurrogate mapping.

fun <T, P : Position<out P>, TS : Any, PS : PositionSurrogate> Environment<T, P>.toEnvironmentSurrogate(toConcentrationSurrogate: (T) -> TS, toPositionSurrogate: (P) -> PS): EnvironmentSurrogate<TS, PS>

A function that maps an Environment to its surrogate class (EnvironmentSurrogate).

Link copied to clipboard
open override fun updatePhysics(elapsedTime: Double)

Compute any collision response and update node positions.