Show / Hide Table of Contents

Class Radius

Structure representing different shapes that define the concept of a radius on a grid. You cannot create instances of this class using a constructor -- instead, this class contains static instances representing the various radius shapes.

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

Contains utility functions to work with radius shapes. Instances of Radius are also implicitly convertible to both Distance and AdjacencyRule (since both a method of determining adjacent locations and a method of calculating distance are implied by a radius shape).

Fields

Circle

Radius is a circle around the center point. CIRCLE would represent movement radius in an 8-way movement scheme with a ~1.41 cost multiplier for diagonal movement.

Declaration
public static readonly Radius Circle
Field Value
Type Description
Radius

Diamond

Radius is a diamond around the center point. DIAMOND would represent movement radius in a 4-way movement scheme.

Declaration
public static readonly Radius Diamond
Field Value
Type Description
Radius

Square

Radius is a square around the center point. SQUARE would represent movement radius in an 8-way movement scheme, where all 8 squares around an item are considered equal distance away.

Declaration
public static readonly Radius Square
Field Value
Type Description
Radius

Type

Enum value representing the radius shape -- useful for using Radius types in switch statements.

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

Methods

Equals(Radius)

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

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

Radius to compare.

Returns
Type Description
Boolean

True if the two radius shapes are the same, false if not.

Equals(Object)

Same as operator == in this case; returns false if obj is not a Radius.

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

The object to compare the current Radius to.

Returns
Type Description
Boolean

True if obj is a Radius, and the two radius shapes are equal, false otherwise.

GetHashCode()

Returns a hash-map value for the current object.

Declaration
public override int GetHashCode()
Returns
Type Description
Int32

Matches(Radius)

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

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

Radius to compare.

Returns
Type Description
Boolean

True if the two radius shapes are the same, false if not.

PositionsInRadius(Point, Int32)

Returns an IEnumerable of all positions in a radius of the current shape defined by the given parameters.

Declaration
public IEnumerable<Point> PositionsInRadius(Point center, int radius)
Parameters
Type Name Description
Point center

Center-point of the radius.

Int32 radius

Length of the radius.

Returns
Type Description
IEnumerable<Point>

All points in the radius shape defined by the given parameters, in order from least distance to greatest if Diamond or Square is being used.

Remarks

If you are getting positions for a radius of the same size frequently, it may be more performant to instead construct a RadiusLocationContext to represent it, and pass that to PositionsInRadius(RadiusLocationContext).

The positions returned are guaranteed to be in order from least distance from center to most distance if either Diamond or Square is being used.

PositionsInRadius(Point, Int32, Rectangle)

Returns an IEnumerable of all positions in a radius of the current shape defined by the given parameters.

Declaration
public IEnumerable<Point> PositionsInRadius(Point center, int radius, Rectangle bounds)
Parameters
Type Name Description
Point center

Center-point of the radius.

Int32 radius

Length of the radius.

Rectangle bounds

Bounds to restrict the returned values by.

Returns
Type Description
IEnumerable<Point>

All points in the radius shape defined by the given parameters, in order from least distance to greatest if Diamond or Square is being used.

Remarks

If you are getting positions for a radius of the same size frequently, it may be more performant to instead construct a RadiusLocationContext to represent it, and pass that to PositionsInRadius(RadiusLocationContext).

The positions returned are all guaranteed to be within the bounds specified. As well, they are guaranteed to be in order from least distance from center to most distance if either Diamond or Square is being used.

PositionsInRadius(RadiusLocationContext)

Returns an IEnumerable of all positions in a radius of the current shape defined by the given context. Creating a context to store, and using this function instead of another overload may be more performant when you plan to get the positions for a radius of the same size multiple times, even if the shape/position are changing.

Declaration
public IEnumerable<Point> PositionsInRadius(RadiusLocationContext context)
Parameters
Type Name Description
RadiusLocationContext context

Context defining radius parameters.

Returns
Type Description
IEnumerable<Point>

All points in the radius shape defined by the given context, in order from least distance to greatest if Diamond or Square is being used.

Remarks

The positions returned are all guaranteed to be within the Bounds specified in the context, unless the bounds are unspecified, in which case no bound restriction results.

As well, they are guaranteed to be in order from least distance from center to most distance if either Diamond or Square is being used.

PositionsInRadius(Int32, Int32, Int32)

Returns an IEnumerable of all positions in a radius of the current shape defined by the given parameters.

Declaration
public IEnumerable<Point> PositionsInRadius(int centerX, int centerY, int radius)
Parameters
Type Name Description
Int32 centerX

X-value of the center-point of the radius.

Int32 centerY

Y-value of the center-point of the radius.

Int32 radius

Length of the radius.

Returns
Type Description
IEnumerable<Point>

All points in the radius shape defined by the given parameters, in order from least distance to greatest if Diamond or Square is being used.

Remarks

If you are getting positions for a radius of the same size frequently, it may be more performant to instead construct a RadiusLocationContext to represent it, and pass that to PositionsInRadius(RadiusLocationContext).

The positions returned are guaranteed to be in order from least distance from center to most distance if either Diamond or Square is being used.

PositionsInRadius(Int32, Int32, Int32, Rectangle)

Returns an IEnumerable of all positions in a radius of the current shape defined by the given parameters.

Declaration
public IEnumerable<Point> PositionsInRadius(int centerX, int centerY, int radius, Rectangle bounds)
Parameters
Type Name Description
Int32 centerX

X-value of the center-point of the radius.

Int32 centerY

Y-value of the center-point of the radius.

Int32 radius

Length of the radius.

Rectangle bounds

Bounds to restrict the returned values by.

Returns
Type Description
IEnumerable<Point>

All points in the radius shape defined by the given parameters, in order from least distance to greatest if Diamond or Square is being used.

Remarks

If you are getting positions for a radius of the same size frequently, it may be more performant to instead construct a RadiusLocationContext to represent it, and pass that to PositionsInRadius(RadiusLocationContext).

The positions returned are all guaranteed to be within the bounds specified. As well, they are guaranteed to be in order from least distance from center to most distance if either Diamond or Square is being used.

ToString()

Returns a string representation of the Radius.

Declaration
public override string ToString()
Returns
Type Description
String

A string representation of the Radius.

Operators

Equality(Radius, Radius)

True if the two radius shapes have the same Type.

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

True if the two radius shapes are equal, false if not.

Implicit(Radius to AdjacencyRule)

Allows implicit casting to the AdjacencyRule type.

Declaration
public static implicit operator AdjacencyRule(Radius radius)
Parameters
Type Name Description
Radius radius

Radius type being casted.

Returns
Type Description
AdjacencyRule
Remarks

The rule corresponding to the proper definition of distance that creates the radius shape casted will be returned.

Implicit(Radius to Distance)

Allows implicit casting to the Distance type.

Declaration
public static implicit operator Distance(Radius radius)
Parameters
Type Name Description
Radius radius

Radius type being casted.

Returns
Type Description
Distance
Remarks

The Distance instance corresponding to the proper definition of distance that creates the radius shape casted will be returned.

Implicit(Radius to Radius.Types)

Implicitly converts a Radius to its corresponding Type.

Declaration
public static implicit operator Radius.Types(Radius radius)
Parameters
Type Name Description
Radius radius
Returns
Type Description
Radius.Types

Implicit(Radius.Types to Radius)

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

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

Inequality(Radius, Radius)

True if the types are not equal.

Declaration
public static bool operator !=(Radius lhs, Radius rhs)
Parameters
Type Name Description
Radius lhs
Radius 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