• API Documentation
Show / Hide Table of Contents
  • Rebus
    • Arguments
    • Biome
    • CantorPairing
    • CommandRequest
    • CommandResponse
    • CommandType
    • Commodity
    • Configuration
    • ConflictEventArgs
    • Depths
    • Economy
    • Fleet
    • HexPoint
    • IGameService
    • ILoginService
    • Player
    • Unit
    • User
    • Zone
    • ZoneInfo
  • Rebus.Client
    • GraphicsEngine
    • Layout
    • RpcClient
    • ZoneVisualizer
  • Rebus.Client.Lenses
    • BiomeLens
    • ConstellationLens
    • Lens
    • PopulationLens
    • StarLens
  • Rebus.Server
    • AStarSearch
    • EvaluationContext
    • FisherYatesShuffle
    • JuliaSet
    • PowerSet
  • Rebus.Server.Considerations
    • Agent
    • Behavior
    • BehaviorCollection
    • Consideration
    • ConsiderationCollection
    • FunctionConsideration
    • LinearConsideration
    • QuadraticConsideration
  • Rebus.Server.Functions
    • IFunctions<T>
  • System
    • NegativeExponentialRandom
  • System.Text.Json.Serialization.Converters
    • ComplexConverter
    • CultureInfoConverter
    • IPAddressConverter

Struct HexPoint

Represents a cubic coordinate in three dimensions (Q, R, and S) used to identify a location in a grid of hexagons.

Implements
IComparable
IComparable<HexPoint>
IEquatable<HexPoint>
Inherited Members
Object.Equals(Object, Object)
Object.GetType()
Object.ReferenceEquals(Object, Object)
Namespace: Rebus
Assembly: Rebus.dll
Syntax
[MessagePackObject(false)]
public readonly struct HexPoint : IComparable, IComparable<HexPoint>, IEquatable<HexPoint>
Remarks

The implementation of this struct was inspired by and based on this article by Amit Patel.

Constructors

HexPoint(Int32, Int32)

Initializes a new instance of the HexPoint struct.

Declaration
public HexPoint(int q, int r)
Parameters
Type Name Description
Int32 q

The Q coordinate.

Int32 r

The R coordinate.

Fields

Empty

Specifies the coordinate whose three axes are zero.

Declaration
public static readonly HexPoint Empty
Field Value
Type Description
HexPoint

The coordinate (0, 0, 0).

Properties

Q

Gets the Q coordinate.

Declaration
[Key(0)]
public readonly int Q { get; }
Property Value
Type Description
Int32

The Q coordinate. The default is 0.

R

Gets the R coordinate.

Declaration
[Key(1)]
public readonly int R { get; }
Property Value
Type Description
Int32

The R coordinate. The default is 0.

S

Gets the S coordinate.

Declaration
[IgnoreMember]
public readonly int S { get; }
Property Value
Type Description
Int32

The S coordinate. The default is 0.

Methods

Add(HexPoint)

Returns a new HexPoint that adds the value of the specified HexPoint to the value of this instance.

Declaration
public readonly HexPoint Add(HexPoint other)
Parameters
Type Name Description
HexPoint other

A positive or negative hexagonal coordinate.

Returns
Type Description
HexPoint

An object whose value is the sum of the hexagonal coordinates represented by this instance and the other value.

CompareTo(HexPoint)

Declaration
public readonly int CompareTo(HexPoint other)
Parameters
Type Name Description
HexPoint other
Returns
Type Description
Int32

CompareTo(Object)

Declaration
public readonly int CompareTo(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
Int32

Distance(HexPoint, HexPoint)

Gets the distance between two hexagonal coordinates.

Declaration
public static int Distance(HexPoint value1, HexPoint value2)
Parameters
Type Name Description
HexPoint value1

The first value.

HexPoint value2

The second value.

Returns
Type Description
Int32

The distance between value1 and value2.

Equals(HexPoint)

Declaration
public readonly bool Equals(HexPoint other)
Parameters
Type Name Description
HexPoint other
Returns
Type Description
Boolean

Equals(Object)

Declaration
public override readonly bool Equals(object obj)
Parameters
Type Name Description
Object obj
Returns
Type Description
Boolean
Overrides
ValueType.Equals(Object)

GetHashCode()

Declaration
public override readonly int GetHashCode()
Returns
Type Description
Int32
Overrides
ValueType.GetHashCode()

Multiply(Int32)

Returns the value that results from multiplying the specified factor by the value of this instance.

Declaration
public readonly HexPoint Multiply(int factor)
Parameters
Type Name Description
Int32 factor

The factor to multiply.

Returns
Type Description
HexPoint

A hexagonal coordinate that is equal to this instance times the factor.

Neighbors()

Gets the six coordinates adjacent to this instance.

Declaration
public readonly IEnumerable<HexPoint> Neighbors()
Returns
Type Description
IEnumerable<HexPoint>

The neighboring coordinates.

Range(Int32)

Gets the coordinates within a hexagonal range.

Declaration
public readonly IEnumerable<HexPoint> Range(int radius)
Parameters
Type Name Description
Int32 radius

The radius of the range.

Returns
Type Description
IEnumerable<HexPoint>

The coordinates within the range defined by the given radius.

Ring(Int32)

Gets the coordinates within a hexagonal ring.

Declaration
public readonly IEnumerable<HexPoint> Ring(int radius)
Parameters
Type Name Description
Int32 radius

The radius of the ring.

Returns
Type Description
IEnumerable<HexPoint>

The coordinates within the ring defined by the given radius.

Spiral(Int32)

Gets the coordinates within a hexagonal spiral.

Declaration
public readonly IEnumerable<HexPoint> Spiral(int radius)
Parameters
Type Name Description
Int32 radius

The radius of the spiral.

Returns
Type Description
IEnumerable<HexPoint>

The coordinates within the spiral defined by the given radius.

Subtract(HexPoint)

Returns the value that results from subtracting the specified hexagonal coordinate from the value of this instance.

Declaration
public readonly HexPoint Subtract(HexPoint other)
Parameters
Type Name Description
HexPoint other

The hexagonal coordinate to subtract.

Returns
Type Description
HexPoint

A hexagonal coordinate that is equal to this instance minus the other value.

ToString()

Declaration
public override readonly string ToString()
Returns
Type Description
String
Overrides
ValueType.ToString()

Operators

Addition(HexPoint, HexPoint)

Adds a specified coordinate to another specified coordinate.

Declaration
public static HexPoint operator +(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first coordinate to add.

HexPoint right

The second coordinate to add.

Returns
Type Description
HexPoint

The sum of left and right.

Equality(HexPoint, HexPoint)

Returns a value that indicates whether two coordinates are equal.

Declaration
public static bool operator ==(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first coordinate to compare.

HexPoint right

The second coordinate to compare.

Returns
Type Description
Boolean

true if left and right are equal; otherwise, false.

GreaterThan(HexPoint, HexPoint)

Returns a value that indicates whether a specified value is greater than another specified value.

Declaration
public static bool operator>(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first value to compare.

HexPoint right

The second value to compare.

Returns
Type Description
Boolean

true if left is greater than right; otherwise, false.

GreaterThanOrEqual(HexPoint, HexPoint)

Returns a value that indicates whether a specified value is greater than or equal to another specified value.

Declaration
public static bool operator >=(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first value to compare.

HexPoint right

The second value to compare.

Returns
Type Description
Boolean

true if left is greater than or equal to right; otherwise, false.

Inequality(HexPoint, HexPoint)

Returns a value that indicates whether two coordinates are not equal.

Declaration
public static bool operator !=(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first coordinate to compare.

HexPoint right

The second coordinate to compare.

Returns
Type Description
Boolean

true if left and right are not equal; otherwise, false.

LessThan(HexPoint, HexPoint)

Returns a value that indicates whether a specified value is less than another specified value.

Declaration
public static bool operator <(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first value to compare.

HexPoint right

The second value to compare.

Returns
Type Description
Boolean

true if left is less than right; otherwise, false.

LessThanOrEqual(HexPoint, HexPoint)

Returns a value that indicates whether a specified value is less than or equal to another specified value.

Declaration
public static bool operator <=(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The first value to compare.

HexPoint right

The second value to compare.

Returns
Type Description
Boolean

true if left is less than or equal to right; otherwise, false.

Multiply(HexPoint, Int32)

Multiplies a specified coordinate by a number.

Declaration
public static HexPoint operator *(HexPoint left, int right)
Parameters
Type Name Description
HexPoint left

The coordinate to multiply.

Int32 right

The number to multiply.

Returns
Type Description
HexPoint

The product of left and right, as a hexagonal coordinate.

Multiply(Int32, HexPoint)

Multiplies a number by a specified coordinate.

Declaration
public static HexPoint operator *(int left, HexPoint right)
Parameters
Type Name Description
Int32 left

The number to multiply.

HexPoint right

The coordinate to multiply.

Returns
Type Description
HexPoint

The product of left and right, as a hexagonal coordinate.

Subtraction(HexPoint, HexPoint)

Subtracts a specified coordinate from another specified coordinate.

Declaration
public static HexPoint operator -(HexPoint left, HexPoint right)
Parameters
Type Name Description
HexPoint left

The value to subtract from (the minuend).

HexPoint right

The value to subtract (the subtrahend).

Returns
Type Description
HexPoint

The result of subtracting right from left.

Implements

System.IComparable
System.IComparable<T>
System.IEquatable<T>

See Also

Red Blob Games - Hexagonal Grids
Amit Patel&apos;s Home Page
In This Article
Back to top © 2021-2022 Ishan Pranav. All rights reserved. Licensed under the MIT License.