Show / Hide Table of Contents

Class OrthogonalLineGrid2D

Structure representing an orthogonal line in a integer grid.

Inheritance
System.Object
OrthogonalLineGrid2D
Implements
System.IEquatable<OrthogonalLineGrid2D>
Namespace: Edgar.Geometry
Assembly: Edgar.dll
Syntax
public sealed class OrthogonalLineGrid2D : ValueType, IEquatable<OrthogonalLineGrid2D>

Constructors

OrthogonalLineGrid2D(Vector2Int, Vector2Int)

Construct an orthogonal line from given endpoints.

Declaration
public OrthogonalLineGrid2D(Vector2Int from, Vector2Int to)
Parameters
Type Name Description
Vector2Int from
Vector2Int to
Exceptions
Type Condition
System.ArgumentException

Thrown when given points do not form an orthogonal line.

OrthogonalLineGrid2D(Vector2Int, Vector2Int, OrthogonalLineGrid2D.Direction)

Construct an orthogonal line from given endpoints and a direction.

Declaration
public OrthogonalLineGrid2D(Vector2Int from, Vector2Int to, OrthogonalLineGrid2D.Direction degeneratedDirection)
Parameters
Type Name Description
Vector2Int from
Vector2Int to
OrthogonalLineGrid2D.Direction degeneratedDirection
Remarks

Direction is used only when the line is degenerated - that means when both endpoints are in fact the same point. It is useful in situations where line's direction is an important information.

Exceptions
Type Condition
System.ArgumentException

Thrown when given points do not form an orthogonal line.

Fields

From

Declaration
public readonly Vector2Int From
Field Value
Type Description
Vector2Int

To

Declaration
public readonly Vector2Int To
Field Value
Type Description
Vector2Int

Properties

Length

Returns number of points minus 1.

Declaration
public int Length { get; }
Property Value
Type Description
System.Int32

Methods

ComputeRotation()

Computes how the line must be rotated around the center to have "Right" direction.

Declaration
public int ComputeRotation()
Returns
Type Description
System.Int32

Contains(Vector2Int)

Checks if the orthogonal line contains a given point.

Declaration
public int Contains(Vector2Int point)
Parameters
Type Name Description
Vector2Int point
Returns
Type Description
System.Int32

Index of a given point on the line or -1.

Remarks

Index is 0 for From and Count + 1 for To.

Equals(OrthogonalLineGrid2D)

Declaration
public bool Equals(OrthogonalLineGrid2D other)
Parameters
Type Name Description
OrthogonalLineGrid2D other
Returns
Type Description
System.Boolean

Equals(Object)

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

GetDirection()

Returns a direction of the line.

Declaration
public OrthogonalLineGrid2D.Direction GetDirection()
Returns
Type Description
OrthogonalLineGrid2D.Direction
Remarks

If the line is degenerated, returns the direction that was set in constructor (or Undefined if none was set).

GetDirection(Vector2Int, Vector2Int)

Gets a direction of an orthogonal lined formed by given points.

Declaration
public static OrthogonalLineGrid2D.Direction GetDirection(Vector2Int from, Vector2Int to)
Parameters
Type Name Description
Vector2Int from
Vector2Int to
Returns
Type Description
OrthogonalLineGrid2D.Direction
Exceptions
Type Condition
System.ArgumentException

Thrown when given points do not form an orthogonal line

GetDirectionVector()

Gets a direction vector of the line.

Declaration
public Vector2Int GetDirectionVector()
Returns
Type Description
Vector2Int
Remarks

That is a vector that satisfies that From + Length * direction_vector = To.

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

GetNormalized()

Returns a line that has the same endpoints and From is smaller than To.

Declaration
public OrthogonalLineGrid2D GetNormalized()
Returns
Type Description
OrthogonalLineGrid2D

GetNthPoint(Int32)

Gets nth point on the line. (Counted from From)

Declaration
public Vector2Int GetNthPoint(int n)
Parameters
Type Name Description
System.Int32 n
Returns
Type Description
Vector2Int

GetOppositeDirection(OrthogonalLineGrid2D.Direction)

Gets opposite direction.

Declaration
public static OrthogonalLineGrid2D.Direction GetOppositeDirection(OrthogonalLineGrid2D.Direction direction)
Parameters
Type Name Description
OrthogonalLineGrid2D.Direction direction
Returns
Type Description
OrthogonalLineGrid2D.Direction

GetPoints()

Gets all points of the line. Both "From" and "To" are inclusive. The direction is from "From" to "To";

Declaration
public List<Vector2Int> GetPoints()
Returns
Type Description
System.Collections.Generic.List<Vector2Int>

Rotate(Int32, Boolean)

Rotate the line.

Declaration
public OrthogonalLineGrid2D Rotate(int degrees, bool checkDirection = true)
Parameters
Type Name Description
System.Int32 degrees
System.Boolean checkDirection

Throws if set to true and the rotated line has an undefined direction.

Returns
Type Description
OrthogonalLineGrid2D
Remarks

Positive degrees mean clockwise rotation.

Exceptions
Type Condition
System.ArgumentException

Thrown when degress are not a multiple of 90.

RotateDirection(OrthogonalLineGrid2D.Direction, Int32)

Compute rotated direction.

Declaration
public static OrthogonalLineGrid2D.Direction RotateDirection(OrthogonalLineGrid2D.Direction direction, int degrees)
Parameters
Type Name Description
OrthogonalLineGrid2D.Direction direction
System.Int32 degrees
Returns
Type Description
OrthogonalLineGrid2D.Direction
Remarks

Rotation is clockwise.

Shrink(Int32)

Shrinks the line by the same amount on both sides.

Declaration
public OrthogonalLineGrid2D Shrink(int length)
Parameters
Type Name Description
System.Int32 length
Returns
Type Description
OrthogonalLineGrid2D

Shrink(Int32, Int32)

Shrinks the line.

Declaration
public OrthogonalLineGrid2D Shrink(int from, int to)
Parameters
Type Name Description
System.Int32 from
System.Int32 to
Returns
Type Description
OrthogonalLineGrid2D
Remarks

Specified number of points is removed from respective sides of the line.

SwitchOrientation()

Returns a line where From and To are switched.

Declaration
public OrthogonalLineGrid2D SwitchOrientation()
Returns
Type Description
OrthogonalLineGrid2D

ToString()

Declaration
public override string ToString()
Returns
Type Description
System.String

ToStringShort()

Declaration
public string ToStringShort()
Returns
Type Description
System.String

Operators

Addition(OrthogonalLineGrid2D, Vector2Int)

Adds given IntVector2 to both endpoints of a given orthogonal line.

Declaration
public static OrthogonalLineGrid2D operator +(OrthogonalLineGrid2D line, Vector2Int point)
Parameters
Type Name Description
OrthogonalLineGrid2D line
Vector2Int point
Returns
Type Description
OrthogonalLineGrid2D

Addition(Vector2Int, OrthogonalLineGrid2D)

Adds given IntVector2 to both endpoints of a given orthogonal line.

Declaration
public static OrthogonalLineGrid2D operator +(Vector2Int point, OrthogonalLineGrid2D line)
Parameters
Type Name Description
Vector2Int point
OrthogonalLineGrid2D line
Returns
Type Description
OrthogonalLineGrid2D

Implements

System.IEquatable<>
Back to top Generated by DocFX