Class ParticleSystem_Utils
Utility methods and constants for computations done by the ParticleSystem.
Inheritance
Namespace: AS2.Sim
Assembly: .dll
Syntax
public static class ParticleSystem_Utils
Fields
| Edit this page View SourceexpandedLabels
Conversion matrix for converting a local direction of an expanded particle into a label.
The entry at position [exp,loc] is the head label
of an expanded particle with head direction exp
corresponding to the local direction loc. To get
the tail label for that direction, use (exp + 3) % 6
as the first index.
A label value of -1 means that the label does not
exist because there is no port in that location.
Declaration
private static readonly int[,] expandedLabels
Field Value
| Type | Description |
|---|---|
| int[,] |
isHeadLabel
Bool matrix telling whether a given label is a head or tail label.
The entry at position [exp,label] is true
if and only if the label label belongs to the
head of an expanded particle with head direction exp.
Note that the entries for head directions 3,4,5 are
exactly the opposite of the entries for head directions
0,1,2.
Declaration
private static readonly bool[,] isHeadLabel
Field Value
| Type | Description |
|---|---|
| bool[,] |
labelDirections
Conversion matrix for converting a label into a direction.
The entry at position [exp,label] is the direction
of an expanded particle with head direction exp
corresponding to label label.
Note that the conversion for head directions 3,4,5
is the same as for head directions 0,1,2, which is
why the second half of the matrix is redundant.
Declaration
private static readonly int[,] labelDirections
Field Value
| Type | Description |
|---|---|
| int[,] |
Methods
| Edit this page View SourceDirectionToVector(Direction)
Computes the unit vector in the grid coordinate system that points in the given direction. Secondary directions are mapped to their corresponding cardinal direction.
Declaration
public static Vector2Int DirectionToVector(Direction globalDir)
Parameters
| Type | Name | Description |
|---|---|---|
| Direction | globalDir | The global direction of the vector. |
Returns
| Type | Description |
|---|---|
| Vector2Int | A grid vector representing one step in the indicated
global direction. Will be |
GetDirOfLabel(int, Direction)
Computes the direction in which the given edge label points.
Declaration
public static Direction GetDirOfLabel(int label, Direction headDir = Direction.NONE)
Parameters
| Type | Name | Description |
|---|---|---|
| int | label | The label of which to compute the direction. |
| Direction | headDir | The head direction of the particle, if it is expanded. Leave it at NONE otherwise. |
Returns
| Type | Description |
|---|---|
| Direction | The direction of the edge label |
GetLabelInDir(Direction, Direction, bool)
Computes the edge label corresponding to the given direction and expansion state.
If headDir is NONE,
i.e., the particle is contracted, the label always equals the
given direction's int representation.
Declaration
public static int GetLabelInDir(Direction direction, Direction headDir = Direction.NONE, bool head = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Direction | direction | The direction of the edge marked by the returned label. |
| Direction | headDir | The head direction of the particle, if it is expanded. Leave it at NONE otherwise. |
| bool | head | If the particle is expanded, this flag determines whether the label belongs to the particle's head or tail. |
Returns
| Type | Description |
|---|---|
| int | The label of the edge specified by the direction and expansion state of a particle. |
GetNbrInDir(Vector2Int, Direction, int)
Computes the neighbor of a grid node position in the given direction and distance.
Declaration
public static Vector2Int GetNbrInDir(Vector2Int pos, Direction globalDir, int distance = 1)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2Int | pos | The original grid node position. |
| Direction | globalDir | The global direction in which the neighbor lies. Secondary directions are mapped back to their cardinal directions. |
| int | distance | The number of steps to reach the neighbor from the original position. |
Returns
| Type | Description |
|---|---|
| Vector2Int | The node that lies |
GetNeighborPosition(Particle, Direction, bool)
Determines the grid node neighboring the given particle in the indicated direction.
Declaration
public static Vector2Int GetNeighborPosition(Particle p, Direction locDir, bool fromHead)
Parameters
| Type | Name | Description |
|---|---|---|
| Particle | p | The Particle whose neighbor node to find. |
| Direction | locDir | The local direction of the Particle |
| bool | fromHead | If |
Returns
| Type | Description |
|---|---|
| Vector2Int | The grid node in direction |
GlobalToLocalDir(Direction, Direction, bool)
Turns the given global direction into the corresponding local direction based on the given compass orientation and chirality.
Declaration
public static Direction GlobalToLocalDir(Direction globalDir, Direction compassDir, bool chirality)
Parameters
| Type | Name | Description |
|---|---|---|
| Direction | globalDir | The global direction. |
| Direction | compassDir | The global offset of the compass direction (independent of chirality). This is the global direction that is interpreted as E by the local direction. |
| bool | chirality | The direction in which rotation is applied for the
local direction. |
Returns
| Type | Description |
|---|---|
| Direction | The local direction corresponding to |
GlobalToLocalLabel(int, Direction, Direction, bool)
Translates the given global label into the corresponding local label.
Declaration
public static int GlobalToLocalLabel(int globalLabel, Direction globalHeadDirection, Direction compassDir, bool chirality)
Parameters
| Type | Name | Description |
|---|---|---|
| int | globalLabel | The global label to be translated. |
| Direction | globalHeadDirection | The global head direction of the particle. |
| Direction | compassDir | The global compass direction of the particle. |
| bool | chirality | The chirality of the particle. |
Returns
| Type | Description |
|---|---|
| int | The local label that identifies the same port as the given global label. |
GridDistance(Vector2Int, Vector2Int)
Declaration
public static int GridDistance(Vector2Int p1, Vector2Int p2)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2Int | p1 | |
| Vector2Int | p2 |
Returns
| Type | Description |
|---|---|
| int |
IsHeadLabel(int, Direction)
Checks if the given label belongs to the particle's head.
If headDir is NONE,
i.e., the particle is contracted, the result will always be true.
Declaration
public static bool IsHeadLabel(int label, Direction headDir = Direction.NONE)
Parameters
| Type | Name | Description |
|---|---|---|
| int | label | The edge label to check. |
| Direction | headDir | The head direction of the particle, if it is expanded. Leave it at NONE otherwise. |
Returns
| Type | Description |
|---|---|
| bool |
|
IsTailLabel(int, Direction)
Checks if the given label belongs to the particle's tail.
If headDir is NONE,
i.e., the particle is contracted, the result will always be true.
Declaration
public static bool IsTailLabel(int label, Direction headDir = Direction.NONE)
Parameters
| Type | Name | Description |
|---|---|---|
| int | label | The edge label to check. |
| Direction | headDir | The head direction of the particle, if it is expanded. Leave it at NONE otherwise. |
Returns
| Type | Description |
|---|---|
| bool |
|
LocalToGlobalDir(Direction, Direction, bool)
Turns the given local direction into the corresponding global direction based on the given compass orientation and chirality.
Declaration
public static Direction LocalToGlobalDir(Direction locDir, Direction compassDir, bool chirality)
Parameters
| Type | Name | Description |
|---|---|---|
| Direction | locDir | The local direction. |
| Direction | compassDir | The global offset of the compass direction (independent of chirality). This is the global direction that is interpreted as E by the local direction. |
| bool | chirality | The direction in which rotation is applied for the
local direction. |
Returns
| Type | Description |
|---|---|
| Direction | The global direction corresponding to |
LocalToGlobalLabel(int, Direction, Direction, bool)
Translates the given local label into the corresponding global label.
Declaration
public static int LocalToGlobalLabel(int localLabel, Direction localHeadDirection, Direction compassDir, bool chirality)
Parameters
| Type | Name | Description |
|---|---|---|
| int | localLabel | The local label to be translated. |
| Direction | localHeadDirection | The local head direction of the particle. |
| Direction | compassDir | The global compass direction of the particle. |
| bool | chirality | The chirality of the particle. |
Returns
| Type | Description |
|---|---|
| int | The global label that identifies the same port as the given local label. |
VectorToDirection(Vector2Int)
Computes the global direction into which the given grid vector is pointing.
Declaration
public static Direction VectorToDirection(Vector2Int vector)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2Int | vector | The grid vector whose direction should be found. |
Returns
| Type | Description |
|---|---|
| Direction | The direction into which |