Show / Hide Table of Contents

Class AdjacencyRule

Structure representing a method for determining which coordinates are adjacent to a given coordinate, and which directions those neighbors are in. Cannot be instantiated -- pre-made static instances are provided.

Inheritance
Object
AdjacencyRule
Implements
IEquatable<AdjacencyRule>
IMatchable<AdjacencyRule>
Namespace: SadRogue.Primitives
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class AdjacencyRule : ValueType, IEquatable<AdjacencyRule>, IMatchable<AdjacencyRule>

Fields

Cardinals

Represents method of determining adjacency where neighbors are considered adjacent if they are in a cardinal direction, eg. 4-way (manhattan-based) connectivity.

Declaration
public static readonly AdjacencyRule Cardinals
Field Value
Type Description
AdjacencyRule

Diagonals

Represents method of determining adjacency where neighbors are considered adjacent only if they are in a diagonal direction.

Declaration
public static readonly AdjacencyRule Diagonals
Field Value
Type Description
AdjacencyRule

DirectionsOfNeighborsCache

Array that caches the output of DirectionsOfNeighbors() for this instance. Can be useful since iterating over an array by index is often faster than using a foreach/IEnumerable.

Declaration
public readonly Direction[] DirectionsOfNeighborsCache
Field Value
Type Description
Direction[]
Remarks

The indices in this value are not intended to be modified; doing so may result in bad behavior!

DirectionsOfNeighborsClockwiseCache

Array that caches the output of DirectionsOfNeighborsClockwise() for this instance. Can be useful since iterating over an array by index is often faster than using a foreach/IEnumerable.

Declaration
public readonly Direction[] DirectionsOfNeighborsClockwiseCache
Field Value
Type Description
Direction[]
Remarks

The indices in this value are not intended to be modified; doing so may result in bad behavior!

DirectionsOfNeighborsCounterClockwiseCache

Array that caches the output of DirectionsOfNeighborsCounterClockwise() for this instance. Can be useful since iterating over an array by index is often faster than using a foreach/IEnumerable.

Declaration
public readonly Direction[] DirectionsOfNeighborsCounterClockwiseCache
Field Value
Type Description
Direction[]
Remarks

The indices in this value are not intended to be modified; doing so may result in bad behavior!

EightWay

Represents method of determining adjacency where all 8 possible neighbors are considered adjacent (eg. 8-way connectivity).

Declaration
public static readonly AdjacencyRule EightWay
Field Value
Type Description
AdjacencyRule

Type

Enum value representing the method of determining adjacency -- useful for using AdjacencyRule types in switch statements.

Declaration
public readonly AdjacencyRule.Types Type
Field Value
Type Description
AdjacencyRule.Types

Methods

DirectionsOfNeighbors()

Gets directions leading to neighboring locations, according to the current adjacency method. Cardinals are returned before any diagonals.

Declaration
public IEnumerable<Direction> DirectionsOfNeighbors()
Returns
Type Description
IEnumerable<Direction>

Directions that lead to neighboring locations.

DirectionsOfNeighborsClockwise(Direction)

Gets directions leading to neighboring locations, according to the current adjacency method. Appropriate directions are returned in clockwise order from the given starting direction.

Declaration
public IEnumerable<Direction> DirectionsOfNeighborsClockwise(Direction startingDirection = null)
Parameters
Type Name Description
Direction startingDirection

The direction to start with. None causes the default starting direction to be used, which is UP for CARDINALS/EIGHT_WAY, and UP_RIGHT for diagonals.

Returns
Type Description
IEnumerable<Direction>

Directions that lead to neighboring locations.

DirectionsOfNeighborsCounterClockwise(Direction)

Gets directions leading to neighboring locations, according to the current adjacency method. Appropriate directions are returned in counter-clockwise order from the given starting direction.

Declaration
public IEnumerable<Direction> DirectionsOfNeighborsCounterClockwise(Direction startingDirection = null)
Parameters
Type Name Description
Direction startingDirection

The direction to start with. null or None causes the default starting direction to be used, which is UP for CARDINALS/EIGHT_WAY, and UP_LEFT for diagonals.

Returns
Type Description
IEnumerable<Direction>

Directions that lead to neighboring locations.

Equals(AdjacencyRule)

True if the given AdjacencyRule has the same Type the current one.

Declaration
public bool Equals(AdjacencyRule other)
Parameters
Type Name Description
AdjacencyRule other

AdjacencyRule to compare.

Returns
Type Description
Boolean

True if the two directions are the same, false if not.

Equals(Object)

Same as operator == in this case; returns false if obj is not an AdjacencyRule.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
Object obj

The object to compare the current AdjacencyRule to.

Returns
Type Description
Boolean

True if obj is an AdjacencyRule, and the two adjacency rules are equal, false otherwise.

GetHashCode()

Returns a hash-map value for the current object.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32

Matches(AdjacencyRule)

True if the given AdjacencyRule has the same Type the current one.

Declaration
public bool Matches(AdjacencyRule other)
Parameters
Type Name Description
AdjacencyRule other

AdjacencyRule to compare.

Returns
Type Description
Boolean

True if the two directions are the same, false if not.

Neighbors(Point)

Gets all neighbors of the specified location, based on the current adjacency method. Cardinals are returned before any diagonals.

Declaration
public IEnumerable<Point> Neighbors(Point startingLocation)
Parameters
Type Name Description
Point startingLocation

Location to return neighbors for.

Returns
Type Description
IEnumerable<Point>

All neighbors of the given location.

Neighbors(Int32, Int32)

Gets all neighbors of the specified location, based on the current adjacency method. Cardinals are returned before any diagonals.

Declaration
public IEnumerable<Point> Neighbors(int startingLocationX, int startingLocationY)
Parameters
Type Name Description
Int32 startingLocationX

X-value of the location to return neighbors for.

Int32 startingLocationY

Y-value of the location to return neighbors for.

Returns
Type Description
IEnumerable<Point>

All neighbors of the given location.

NeighborsClockwise(Point, Direction)

Gets all neighbors of the specified location, based on the current adjacency method. Neighbors are returned in clockwise order, starting with the neighbor in the given starting direction.

Declaration
public IEnumerable<Point> NeighborsClockwise(Point startingLocation, Direction startingDirection = null)
Parameters
Type Name Description
Point startingLocation

Location to return neighbors for.

Direction startingDirection

The neighbor in this direction will be returned first, proceeding clockwise. If None is specified, the default starting direction is used, which is Up for CARDINALS/EIGHT_WAY, and UpRight for DIAGONALS.

Returns
Type Description
IEnumerable<Point>

All neighbors of the given location.

NeighborsClockwise(Int32, Int32, Direction)

Gets all neighbors of the specified location, based on the current adjacency method. Neighbors are returned in clockwise order, starting with the neighbor in the given starting direction.

Declaration
public IEnumerable<Point> NeighborsClockwise(int startingLocationX, int startingLocationY, Direction startingDirection = null)
Parameters
Type Name Description
Int32 startingLocationX

X-value of the location to return neighbors for.

Int32 startingLocationY

Y-value of the location to return neighbors for.

Direction startingDirection

The neighbor in this direction will be returned first, proceeding clockwise. If None is specified, the default starting direction is used, which is Up for CARDINALS/EIGHT_WAY, and UpRight for DIAGONALS.

Returns
Type Description
IEnumerable<Point>

All neighbors of the given location.

NeighborsCounterClockwise(Point, Direction)

Gets all neighbors of the specified location, based on the current adjacency method. Neighbors are returned in counter-clockwise order, starting with the neighbor in the given starting direction.

Declaration
public IEnumerable<Point> NeighborsCounterClockwise(Point startingLocation, Direction startingDirection = null)
Parameters
Type Name Description
Point startingLocation

Location to return neighbors for.

Direction startingDirection

The neighbor in this direction will be returned first, proceeding counter-clockwise. If None is specified, the default starting direction is used, which is Up for CARDINALS/EIGHT_WAY, and UpLeft for DIAGONALS.

Returns
Type Description
IEnumerable<Point>

All neighbors of the given location.

NeighborsCounterClockwise(Int32, Int32, Direction)

Gets all neighbors of the specified location, based on the current adjacency method. Neighbors are returned in counter-clockwise order, starting with the neighbor in the given starting direction.

Declaration
public IEnumerable<Point> NeighborsCounterClockwise(int startingLocationX, int startingLocationY, Direction startingDirection = null)
Parameters
Type Name Description
Int32 startingLocationX

X-value of the location to return neighbors for.

Int32 startingLocationY

Y-value of the location to return neighbors for.

Direction startingDirection

The neighbor in this direction will be returned first, proceeding counter-clockwise. If None is specified, the default starting direction is used, which is Up for CARDINALS/EIGHT_WAY, and UpLeft for DIAGONALS.

Returns
Type Description
IEnumerable<Point>

All neighbors of the given location.

ToString()

Returns a string representation of the AdjacencyRule.

Declaration
public override string ToString()
Returns
Type Description
String

A string representation of the AdjacencyRule.

Operators

Equality(AdjacencyRule, AdjacencyRule)

True if the two adjacency rules have the same Type.

Declaration
public static bool operator ==(AdjacencyRule lhs, AdjacencyRule rhs)
Parameters
Type Name Description
AdjacencyRule lhs
AdjacencyRule rhs
Returns
Type Description
Boolean

True if the two adjacency rules are equal, false if not.

Implicit(AdjacencyRule to AdjacencyRule.Types)

Implicitly converts an AdjacencyRule to its corresponding Type.

Declaration
public static implicit operator AdjacencyRule.Types(AdjacencyRule rule)
Parameters
Type Name Description
AdjacencyRule rule
Returns
Type Description
AdjacencyRule.Types

Implicit(AdjacencyRule.Types to AdjacencyRule)

Implicitly converts an AdjacencyRule.Types enum value to its corresponding AdjacencyRule.

Declaration
public static implicit operator AdjacencyRule(AdjacencyRule.Types type)
Parameters
Type Name Description
AdjacencyRule.Types type
Returns
Type Description
AdjacencyRule

Inequality(AdjacencyRule, AdjacencyRule)

True if the types are not equal.

Declaration
public static bool operator !=(AdjacencyRule lhs, AdjacencyRule rhs)
Parameters
Type Name Description
AdjacencyRule lhs
AdjacencyRule rhs
Returns
Type Description
Boolean

True if the types are not equal, false if they are both equal.

Implements

System.IEquatable<T>
IMatchable<T>

Extension Methods

PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>)
PropertyChangedEventHelpers.SafelySetProperty<TObject, TProperty>(TObject, ref TProperty, TProperty, EventHandler<ValueChangedEventArgs<TProperty>>, EventHandler<ValueChangedEventArgs<TProperty>>)
In This Article
Back to top Generated by DocFX