IShape

Description

interface Tinman.Terrain.Shapes.IShape

Derived from

IShapeInfo
IShapeOps
ISerializable

Extended by

ShapeBase abstract

Base interface for geometric two-dimensional shapes that are defined by a distance field.

Shapes may be defined implicitly. In this case, the implementation class is responsible for computing the signed distance field (usually applying distance field offsets, for example to generate a circle around a point), using arbitrary arithmetic. Explicit shape definitions on the other hand make use of vertices (see VertexAt), edges (see EdgeAt) and triangles (see TriangleAt) to define the signed distance field with standard arithmetic (i.e. distance to point, distance to line segment, distance to triangle). To built an explicit shape, use Shape.Geometry.

Polygons are defined by one or more contours (see IShape.Contours), where each contour is a connected sequence of edges (see EdgeAt and EdgeWalk). Polygon contours do not intersect (but may share common edges) and will either be an outer ring or an inner ring (i.e. a hole), depending on the winding of its vertices (see IShapeInfo.EdgeParity).

Shapes may aggregate other shapes (see ShapeAt), optionally exposing all or some of the aggregated shape vertices as well (see ShapeVertex). Cubemap shapes contain up to six aggregated shapes (see ShapeFind), one for each cubemap face, having special a geo-reference (see CoordinateOperationMethod.Face).

The following table illustrates the different shape types and their relation to aggregated shapes and contained vertices / edges / triangles:

Shape    | Shape  | Vertex |  Edge  |  Edge  |Triangle
Type     | Count  | Count  | Count  | Parity | Count
---------+--------+--------+--------+--------+--------
Implicit |  >= 0  |  >= 0  |   = 0  |   = 0  |   = 0
---------+--------+--------+--------+--------+--------
Group    |  >= 0  |  >= 0  |   = 0  |   = 0  |   = 0
---------+--------+--------+--------+--------+--------
Cubemap  |  0..6  |   = 0  |   = 0  |   = 0  |   = 0
---------+--------+--------+--------+--------+--------
Points   |  >= 0  |   > 0  |   = 0  |   = 0  |   = 0
---------+--------+--------+--------+--------+--------
Graph    |  >= 0  |   > 0  |   > 0  |   = 0  |   = 0
---------+--------+--------+--------+--------+--------
Polygon  |  >= 0  |   > 0  |   > 0  |  != 0  |   = 0
---------+--------+--------+--------+--------+--------
Mesh     |  >= 0  |   > 0  |   = 0  |   = 0  |   > 0

All other combinations are invalid, see ShapeType.

In order to test whether a point p lies in the inside or outside half-space of a contour edge between two vertices v0 and v1, the Geometric.Winding1 method can be used:

w       := Winding(v0, v1, p)
inside  := w == Parity
outside := w != Parity
where w != 0

Usually, contours will be closed. Open contours can occur during transformation of shapes from one coordinate system to another (see IShapeOps.TransformCoordinateSystem or IShapeOps.TransformCubemap) for vertex coordinates which are not defined in the target coordinate system.

The signed distance field of a shape is defined in its coordinate system. If a shape is rendered in a geocentric frame (for example by using a IMapShapes object), the inherent distortions of the coordinate system will become apparent in the shape distance field. For example, meridians rendered as thick lines via distance offsets will become thinner towards the poles in a geographic coordinate system. Here are some guidelines for choosing an appropriate coordinate system:

  • If a shape uses plain geometry only (see IsGeometry), the distortion of the distance field is irrelevant. The shape geometry will be subdivided (if necessary, according to the specified accuracy) when a coordinate system transformation is applied.

  • To minimize distortions in the distance field, an appropriate map projection should be used for the region of interest, for example CoordinateOperationMethod.ObliqueStereographic or CoordinateOperationMethod.TransverseMercator.

  • Cubemap shapes may be used to define shape features globally, but the inherent distance field distortions should be taken into account: circles defined via distance offsets may appear as ovals (because of the skewed coordinate axes) and the apparent thickness of lines defined via distance offsets may vary.

Public / Methods

Check​Intersection


[ThreadSafe]
public method CheckIntersection → (3)

box in : Box2D

The box bounds.

offset opt : float64 = 0

Optional distance offset that will be added to all computed distance values for the intersection test.

transform opt : ITransform2D = null

Optional transform to use for converting box in to shape coordinates.

returns → int32

-1 if this shape and box in are disjoint.
0 if this shape and box in intersect.
1 if box in fully contains this shape.
2 if this shape fully contains box in.

Checks the intersection between this shape and the given bounds.

See also

IShape.IsEmpty

Contour​Start


public method ContourStart → ()

returns → int32 [ ]

The polygon contours. Each element represents the index of an edge that belongs to the contour. For closed contours, the edge with the smallest index is given. For non-closed contours, the first edge is given. Will be empty if this shape is not of type ShapeType.Polygon.

Computes the contours of this polygon shape.

This method will not perform any geometric processing. Instead, it simply uses IShapeInfo.EdgeCount, EdgeAt and EdgeWalk in order to find the polygon contours.

Distance​To

2 overloads


[ThreadSafe]
public method DistanceTo1 → (3)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

maximum opt : float64 = Maths.MaxDouble

The maximum signed distance value that is relevant for the calling code. If an implementation would return a distance that is greater than maximum opt, it may choose to return maximum opt instead. This can be exploited for performance optimizations.

returns → float64

Smallest signed distance to the shape. Results greater than maximum opt are considered irrelevant, in which case maximum opt may be returned instead.

Computes the smallest distance from the given point to the shape.

If the point lies outside of the shape, the returned distance will be greater than zero. If the point is inside of the shape, the returned distance will be negative. The returned distance will be zero if the point exactly lies on the shape boundary.

See also

IShape.IsEmpty


[ThreadSafe]
public method DistanceTo2 → (5)

in : float64

X-coordinate of point.

in : float64

Y-coordinate of point.

vertices out : Vec3I

Shape vertex indices (see VertexAt) that describe the location of the nearest shape feature.

weights out : Vec3D

Location of the nearest shape feature, given as relative weights (i.e. the weight sum is 1) of vertices out. The weights are sorted in descending order, i.e. Vec3D.X always holds the greatest weight and Vec3D.Z always holds the smallest weight. The location of the nearest shape feature is undefined iff all relative weights are zero.

maximum opt : float64 = Maths.MaxDouble

The maximum signed distance value that is relevant for the calling code. If an implementation would return a distance that is greater than maximum opt, it may choose to return maximum opt instead. This can be exploited for performance optimizations.

returns → float64

Smallest signed distance to the shape. Results greater than maximum opt are considered irrelevant, in which case maximum opt may be returned instead.

Computes the smallest distance from the given point to the shape, additionally returning the coordinates of the nearest shape feature.

If the point lies outside of the shape, the returned distance will be greater than zero. If the point is inside of the shape, the returned distance will be negative. The returned distance will be zero if the point exactly lies on the shape boundary.

The nearest shape feature will be at a shape vertex (see VertexAt), a point on a shape edge (EdgeAt) or a point in a shape triangle ( TriangleAt, being represented by 1, 2 or 3 vertex indices.

For geometry shapes (see IsGeometry), the nearest shape feature and the given point will always have a distance that is equal to the absolute return value of this method. For other shape types, these values may be different.

Edge​At


public method EdgeAt → (1)

index in : int32

[0..IShapeInfo.EdgeCount-1]
The edge index.

returns → Vec2I

The shape edge.

Returns a shape edge.

Each edge connects two vertices (see VertexAt), in the direction from Vec2I.X to Vec2I.Y.

All points that lie on an edge have a shape distance of zero.

Edge​Next


public method EdgeNext → (1)

index in : int32

[0..IShapeInfo.EdgeCount-1]
The edge index.

returns → int32

Index of next edge (see EdgeAt) or -1 if there is no next edge (i.e. the contour is not closed).

Returns the next edge for walking along the polygon contour.

See also

IShape.EdgePrev

Edge​Prev


public method EdgePrev → (1)

index in : int32

[0..IShapeInfo.EdgeCount-1]
The edge index.

returns → int32

Index of previous edge (see EdgeAt) or -1 if there is no previous edge (i.e. the contour is not closed).

Returns the previous edge for walking along the polygon contour.

See also

IShape.EdgeNext

Edge​Walk


public method EdgeWalk → (1)

index in : int32

[0..IShapeInfo.EdgeCount-1]
The edge index.

returns → Vec2I

Index of neighbouring edge (see EdgeAt):
Vec2I.X points to previous edge, Vec2I.Y points to next edge. The component will be -1 if there is no neighbouring edge (i.e. the contour is not closed). Both components will be -1 for non-polygon shapes.

Returns the neighbouring edges for walking along the polygon contour.

Face


public method Face → (1)

face in : CubemapFace

The cubemap face.

returns → IShape

The shape or null if there are no shape parts on the given cubemap face.

Returns the shape on the given cubemap face.

Passing CubemapFace.NegZ to an ordinary shape will return this. Cubemap shapes (see IShapeOps.TransformCubemap) will return an aggregated shape for each cubemap face, or null.

Cubemap shapes are used by IHeightmapShape and IPixelPyramidShape objects.

Shape​Add


public method ShapeAdd → (1)

shape in : IShape

[not-null]
The shape to add.

returns → IShape

The prepared shape that has been added or null if this shape does not allow aggregated shapes to be added.

Adds the given shape in as an aggregated shape to this shape.

Aggregating a shape may involve transformations. Use ShapePrepare method to perform this transformation up-front. This method will never perform any transformation on a prepared shape.

See also

ShapeType.Group

Shape​At


public method ShapeAt → (1)

index in : int32

[0..IShapeInfo.ShapeCount-1]
The shape index.

returns → IShape

The aggregated shape.

Returns the index in-th aggregated shape.

Shape​Find


public method ShapeFind → (1)

face in : CubemapFace

The cubemap face.

returns → int32

The index of the aggregated shape or -1 if there is none.

Finds the aggregated shape that corresponds to the given cubemap face.

Shape​Index


public method ShapeIndex → (1)

shape in : IShape

[not-null]
The aggregated shape.

returns → int32

The index of shape in of -1 iff the given shape in is not aggregated by this shape.

Returns the index of the given aggregated shape.

See also

IShape.ShapeAt

Shape​Prepare


public method ShapePrepare → (1)

shape in : IShape

[not-null]
The shape to prepare.

returns → IShape

The prepared shape.

Performs all transformations on the given shape in that would be performed by ShapeAdd.

Preparing a shape that has been returned from ShapePrepare will be as no-op and will never involve any transformations.

See also

ShapeType.Group

Shape​Remove

2 overloads


public method ShapeRemove1 → (1)

index in : int32

[0..IShapeInfo.ShapeCount-1]
The index of shape to remove.

returns → IShape

The removed shape or null iff no shape has been removed, because this shape does not allow to remove aggregated shapes.

Removes the given shape as an aggregated shape from this shape.

See also

ShapeType.Group


public method ShapeRemove2 → (1)

shape in : IShape

[not-null]
The shape to remove, as returned by ShapeAdd.

returns → IShape

The removed shape or null iff no shape has been removed, either because the given shape in is not an aggregated shape of this shape or because this shape does not allow to remove aggregated shapes.

Removes the given shape as an aggregated shape from this shape.

See also

ShapeType.Group

Shape​Vertex


public method ShapeVertex → (1)

vertex in : int32

[0..IShapeInfo.VertexCount-1]
The exposed vertex index.

returns → Vec2I

The aggregated shape vertex:
Vec2I.X : aggregated shape index or -1 iff not found,
Vec2I.Y : vertex index in the aggregated shape or -1 iff not found.

Finds the aggregated shape vertex that corresponds to the given vertex in.

When a shape aggregates other shapes, it may expose vertices of aggregated shapes as its own vertices. In this case, the ShapeVertex method may be used to map such exposed shape vertices to their corresponding aggregated shape and/or vertex. Shapes may expose pseudo-vertices if aggregated shapes do not have any vertices, so it is valid if this method returns a value in the form (n,-1), where n is the index of an aggregated shape.

Triangle​At


public method TriangleAt → (1)

index in : int32

[0..IShapeInfo.TriangleCount-1]
The triangle index.

returns → Vec3I

The shape triangle.

Returns a shape triangle.

Each triangle connects three vertices (see VertexAt), in the order Vec3I.X, Vec3I.Y, Vec3I.Z, where Vec3I.X <Vec3I.Y and Vec3I.X < Vec3I.Z. The vertex winding is chosen so that the signed triangle area is positive (see Geometric.AreaTriangle1). If the Y-axis points upwards, the vertices are ordered in counter-clockwise winding. If it points downwards, the vertices are ordered in clockwise winding.

Value​At


public method ValueAt → (2)

index in : int32

[0..IShapeInfo.VertexCount-1]
The vertex index.

value in : ShapeValue

The shape value to return.

returns → float64

The shape value or Maths.NanD if the value is not available.

Returns a per-vertex shape value.

Vertex​At


public method VertexAt → (1)

index in : int32

[0..IShapeInfo.VertexCount-1]
The vertex index.

returns → Vec2D

The shape vertex.

Returns a shape vertex.

All vertices have a shape distance of zero.

Public / Attributes

Bounds


public attribute Bounds → (get)

value : Box2D

The axis-aligned bounding box. Will be Box2D.Max if the shape is unbounded (e.g. an inverted polygon). Will be Box2D.Inverse if the shape is empty.

Returns the axis-aligned bounding box of this shape.

The bounding box is defined as the smallest possible rectangle that contains all points which have a shape distance of zero or less.

See also

IShape.IsEmpty

Is​Empty


public attribute IsEmpty → (get)

value : bool

true if this shape is empty, false if it is not.

Is this shape empty?

An empty shape does not have any own spatial features, i.e. Bounds will return Box2D.Inverse, CheckIntersection will always return -1 and DistanceTo1 will always return the maximum relevant distance. An empty shape may have aggregated shapes that are not empty.

Is​Geometry


public attribute IsGeometry → (get)

value : bool

true if this is a geometry shape, false if not.

Is this a geometry shape?

A geometry shape has one the following types:

Geometry shapes can be rebuilt with Shape.Geometry by using the following shape builder methods:

Rebuilding a geometry shape will retain the same data as the IShapeOps.Compile method.

Quadtree


public attribute Quadtree → (get)

value : SpatialTreeNode<Box2D>

The root node of the spatial quadtree that holds the vertices, edges or triangles or this shape. Will be invalid if this shape does not have a quadtree none.

Returns the quadtree of this shape.

Vertex​Bounds


public attribute VertexBounds → (get)

value : Box2D

The axis-aligned bounding box that contains all shape vertices. Will be empty (see Box2D.IsEmpty) if there is only a single vertex. Will be Box2D.Inverse if the shape has no vertices.

Returns the axis-aligned bounding box of the shape vertices.

Extensions

Contains

2 overloads


public static method Contains1 → (2)

latitude in : float64

The geographic latitude angle, in radians.

longitude in : float64

The geographic longitude angle, in radians.

returns → bool

true if the given coordinates are inside of this shape,
false if they are outside of it.

Checks if this shape contains the given geographic coordinates.


public static method Contains2 → (1)

latLon in : LatLon

The geographic coordinates.

returns → bool

true if the given coordinates are inside of this shape,
false if they are outside of it.

Checks if this shape contains the given geographic coordinates.

Contour​Closed


public static method ContourClosed → (1)

contour in : int32

The contour index, as returned by IShape.ContourStart.

returns → bool

true if the polygon shape contour is closed, false if not.

Checks if the given polygon shape contour is closed.

Contours


public static method Contours → ()

returns → int32 [ ] [ ]

The vertices of each contour. Will be empty if this shape is not of type ShapeType.Polygon.

Computes the vertices of each contour of this polygon shape.

The returned array may be accessed as follows:

contours[N][M] := vertex index

where N is the contour index and M is the vertex index in the contour.

Contour​Vertices


public static method ContourVertices → (1)

contour in : int32

The contour index, as returned by IShape.ContourStart.

returns → int32 [ ]

The vertices on the polygon contour. Will be empty if this shape is not of type ShapeType.Polygon.

Computes the vertices on the given polygon contour.

The first and the last vertex will be the same iff the polygon contour is closed.

Convex​Hull


public static method ConvexHull → ()

returns → IShape

The convex hull or null if this shape does not have any vertices.

Computes the convex hull of vertices of this shape.

Distance​To

2 overloads


public static method DistanceTo1 → (2)

point in : Vec2D

The point coordinates.

maximum opt : float64 = Maths.MaxDouble

The maximum signed distance value that is relevant for the calling code. If an implementation would return a distance that is greater than maximum opt, it may choose to return maximum opt instead. This can be exploited for performance optimizations.

returns → float64

Smallest signed distance to the shape. Results greater than maximum opt are considered irrelevant, in which case maximum opt may be returned instead.

Computes the smallest distance from the given point to the shape.

If the point lies outside of the shape, the returned distance will be greater than zero. If the point is inside of the shape, the returned distance will be negative. The returned distance will be zero if the point exactly lies on the shape boundary.

See also

IShape.IsEmpty


public static method DistanceTo2 → (4)

point in : Vec2D

The point coordinates.

vertices out : Vec3I

Shape vertex indices (see IShape.VertexAt) that describe the location of the nearest shape feature.

weights out : Vec3D

Location of the nearest shape feature, given as relative weights (i.e. the weight sum is 1) of vertices out. The weights are sorted in descending order, i.e. Vec3D.X always holds the greatest weight and Vec3D.Z always holds the smallest weight. The location of the nearest shape feature is undefined iff all relative weights are zero.

maximum opt : float64 = Maths.MaxDouble

The maximum signed distance value that is relevant for the calling code. If an implementation would return a distance that is greater than maximum opt, it may choose to return maximum opt instead. This can be exploited for performance optimizations.

returns → float64

Smallest signed distance to the shape. Results greater than maximum opt are considered irrelevant, in which case maximum opt may be returned instead.

Computes the smallest distance from the given point to the shape, additionally returning the coordinates of the nearest shape feature.

If the point lies outside of the shape, the returned distance will be greater than zero. If the point is inside of the shape, the returned distance will be negative. The returned distance will be zero if the point exactly lies on the shape boundary.

The nearest shape feature will be at a shape vertex (see IShape.VertexAt), a point on a shape edge (IShape.EdgeAt) or a point in a shape triangle ( IShape.TriangleAt, being represented by 1, 2 or 3 vertex indices.

For geometry shapes (see IShape.IsGeometry), the nearest shape feature and the given point will always have a distance that is equal to the absolute return value of this method. For other shape types, these values may be different.

Import​CSH


[OwnerReturn]
public static method ImportCSH → (1)

output in : Path

[not-null]
Path to output CSH file.

returns → IOperation

The IOperation object that will write the shape file.

Imports this shape into a CSH file (Compressed SHape).

The returned IOperation object will use the WriteCSH method to write the actual file contents.

Nearest


[Pure]
public static method Nearest → (2)

vertices in : Vec3I

Shape vertex indices that describe the location of the nearest shape feature.

weights in : Vec3D

Location of the nearest shape feature, given as relative weights.

returns → Vec2D

The location of the nearest shape feature.

Returns the location of the nearest shape feature.

Render​Prepare


public static method RenderPrepare → ()

returns → IShape

The prepared shape (i.e. the preparation is performed by this method).

Prepares this shape for geometric rendering (i.e. triangles, and lines).

The method will convert this shape to ShapeType.Graph (for the lines) and to ShapeType.Mesh (for the triangles). The resulting shapes are returned as a compiled shape group.

Visible​Bounds


[Pure]
public static method VisibleBounds → (1)

padding opt : float64 = 0

The uniform padding to add to the bounds, given as an amount relative to the maximum of the bound width and height.

returns → Box2D

The non-empty visible bounds of this shape.

Computes the visible bounds of this shape, which may be used to render the shape.

If the shape is empty (see IShape.IsEmpty), the method returns a box between the points (0|0) and (1|1). If the shape is unbounded (see IShape.Bounds), the vertex bounds are used (see IShape.VertexBounds). If the shape contains only a single point or a horizontal / vertical line segment, the method returns a box with a minimum size of (1|1) that is centered around the point or line segment. point.

Write​CSH


public static method WriteCSH → (1)

stream in : IDataStream

[not-null]
The output data stream.

Writes this shape to a CSH file (Compressed SHape).

IOException

If an I/O error has occurred.

See also

IShape.ImportCSH