Show / Hide Table of Contents

Class Viewport<T>

Viewport is a class that effectively creates and maintains a "viewport", or subsection, of the map. Its indexers perform relative to absolute coordinate translations, and return the proper value of type T from the underlying map.

Inheritance
System.Object
Viewport<T>
SettableViewport<T>
Implements
IMapView<T>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: GoRogue.MapViews
Assembly: GoRogue.dll
Syntax
public class Viewport<T> : IMapView<T>
Type Parameters
Name Description
T

The type being exposed by the Viewport.

Remarks

Since some algorithms that use IMapView<T> implementations can be expensive to run on large maps (GoalMaps, etc), you can use viewports to present only a relevant subsection of the map to that algorithm. It is generally useful for any case where you want an IMapView<T> that represents a subsection of some other IMapView<T>.

This implementation restricts the subsection of the map that is presented in such a way that no part of the viewport can be outside the boundary of its parent map view. The viewport cannot be bigger than the map, and the viewport's position is "locked" to the edge so that it cannot be set in such a way that a portion of the viewport lies outside the bounds of the parent map. If you would rather allow this and return a default value for locations outside the parent map, see UnboundedViewport<T>.

Constructors

| Improve this Doc View Source

Viewport(IMapView<T>)

Constructor. Takes the map view to represent. The viewport will represent the entire given map view.

Declaration
public Viewport(IMapView<T> mapView)
Parameters
Type Name Description
IMapView<T> mapView

The map view to represent.

| Improve this Doc View Source

Viewport(IMapView<T>, Rectangle)

Constructor. Takes the parent map view, and the initial subsection of that map view to represent.

Declaration
public Viewport(IMapView<T> mapView, Rectangle viewArea)
Parameters
Type Name Description
IMapView<T> mapView

The map view being represented.

Rectangle viewArea

The initial subsection of that map to represent.

Properties

| Improve this Doc View Source

Height

The height of the area being represented.

Declaration
public int Height { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Item[Coord]

Given a position in relative coordinates, returns the "value" associated with that location in absolute coordinates.

Declaration
public virtual T this[Coord relativePosition] { get; }
Parameters
Type Name Description
Coord relativePosition

Viewport-relative position of the location to retrieve the value for.

Property Value
Type Description
T

The "value" associated with the absolute location represented on the underlying map view.

| Improve this Doc View Source

Item[Int32]

Given a position in relative 1d-array-index style, returns the "value" associated with that location in absolute coordinates.

Declaration
public T this[int relativeIndex1D] { get; }
Parameters
Type Name Description
System.Int32 relativeIndex1D

Viewport-relative position of the location to retrieve the value for, as a 1D array index.

Property Value
Type Description
T

The "value" associated with the absolute location represented on the underlying map view.

| Improve this Doc View Source

Item[Int32, Int32]

Given an X and Y value in relative coordinates, returns the "value" associated with that location in absolute coordinates.

Declaration
public virtual T this[int relativeX, int relativeY] { get; }
Parameters
Type Name Description
System.Int32 relativeX

Viewport-relative X-value of location.

System.Int32 relativeY

Viewport-relative Y-value of location.

Property Value
Type Description
T

The "value" associated with the absolute location represented on the underlying map view.

| Improve this Doc View Source

MapView

The map view that this Viewport is exposing values from.

Declaration
public IMapView<T> MapView { get; }
Property Value
Type Description
IMapView<T>
| Improve this Doc View Source

ViewArea

The area of MapView that this Viewport is exposing. Although this property does not explicitly expose a set accessor, it is returning a reference and as such may be assigned to. When accessed, the rectangle is automatically restricted by the edges of the map as necessary.

Declaration
public Rectangle ViewArea { get; }
Property Value
Type Description
Rectangle
| Improve this Doc View Source

Width

The width of the area being represented.

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

Methods

| Improve this Doc View Source

ToString()

Returns a string representation of the Viewport.

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

A string representation of the Viewport.

Overrides
System.Object.ToString()
| Improve this Doc View Source

ToString(Func<T, String>)

Returns a string representation of the map view, using elementStringifier to determine what string represents each value.

Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type Name Description
System.Func<T, System.String> elementStringifier

Function determining the string representation of each element.

Returns
Type Description
System.String

A string representation of the Viewport.

Remarks

This could be used, for example, on a Viewport of boolean values, to output '#' for false values, and '.' for true values.

| Improve this Doc View Source

ToString(Int32, Func<T, String>)

Prints the values in the Viewport, using the function specified to turn elements into strings, and using the "field length" specified.

Declaration
public string ToString(int fieldSize, Func<T, string> elementStringifier = null)
Parameters
Type Name Description
System.Int32 fieldSize

The size of the field to give each value. A positive-number right-aligns the text within the field, while a negative number left-aligns the text.

System.Func<T, System.String> elementStringifier

Function to use to convert each element to a string. null defaults to the ToString function of type T.

Returns
Type Description
System.String

A string representation of the Viewport.

Remarks

Each element of type T will have spaces added to cause it to take up exactly fieldSize characters, provided fieldSize is less than the length of the element's string represention.

Implements

IMapView<T>

Extension Methods

Utility.Yield<T>(T)
IMapViewExtensions.Bounds<T>(IMapView<T>)
IMapViewExtensions.Contains<T>(IMapView<T>, Int32, Int32)
IMapViewExtensions.Contains<T>(IMapView<T>, Coord)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.Positions<T>(IMapView<T>)
IMapViewExtensions.RandomItem<T>(IMapView<T>, IGenerator)
IMapViewExtensions.RandomItem<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, T, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IEnumerable<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, HashSet<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator, T[])
IMapViewExtensions.RandomPosition<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX