## Individual Points

Points are assumed to take the form `(x, y)`

, but we allow for customisation in how we represent these points. The following methods are used, where we first list the methods that must be defined and then methods that extend these former methods.

### Necessary Methods

`DelaunayTriangulation.getx`

— Function`getx(p::P) where {P}`

Given a point `p`

, returns the `x`

-coordinate. The only methods currently defined are

```
getx(p::NTuple{N,T}) where {N,T}
getx(p::AbstractVector)
```

You can extend this function as you need.

`DelaunayTriangulation.gety`

— Function`gety(p::P) where {P}`

Given a point `p`

, returns the `y`

-coordinate. The only methods currently defined are

```
gety(p::NTuple{N,T}) where {N,T}
gety(p::AbstractVector)
```

You can extend this function as you need.

### Generic Methods

`DelaunayTriangulation.getxy`

— Function`getxy(p)`

Given a point `p`

, returns `(getx(p), gety(p))`

.

## Collection of Points

A collection of points simply store many points. It does not need to be mutable (unless you want to add points into the triangulation not already in `tri.points`

, or if you want mesh refinement). The following methods are used, where we first list the methods that must be defined and then methods that extend these former methods.

### Necessary Methods

`DelaunayTriangulation.getpoint`

— Function`getpoint(pts::P, i)`

Given a collection of points `pts`

, returns a `Tuple`

of the `x`

and `y`

coordinates of the `i`

th point in the collection. The methods currently defined are

```
getpoint(pts::AbstractVecOrTuple, i)
getpoint(pts::AbstractMatrix, i)
```

You can extend this function as you need.

It is assumed that whenever `i`

is not an integer, `i`

is meant to be a point, so `(getx(i), gety(i))`

would be returned in that case. This makes it easier to use some predicates without having to know the index of the point, simply passing the point directly.

`DelaunayTriangulation.each_point_index`

— Function`each_point_index(pts::P) where {P}`

Given a collection of points `pts`

, returns an iterator over the indices of the collection. The methods currently defined are

```
each_point_index(pts::AbstractVecOrTuple)
each_point_index(pts::AbstractMatrix)
```

with the first returning `eachindex(pts)`

and the second returning `axes(pts, 2)`

. You can extend this function as you need.

`DelaunayTriangulation.each_point`

— Function`each_point(pts::P) where {p}`

For a given collection of points `p`

, returns an iterator that goes over each point in the collection. The methods currently defined are

```
each_point(pts::AbstractVecOrTuple)
each_point(pts::AbstractMatrix)
```

with the first method simply returning `pts`

, and the second returning `eachcol(pts)`

. You can extend this function as you need.

`DelaunayTriangulation.num_points`

— Function`num_points(pts)`

Returns the number of points in `pts`

. The methods currently defined are

```
num_points(pts::AbstractVecOrTuple)
num_points(pts::AbstractMatrix)
```

with the first returning `length(pts)`

and the second returning `size(pts, 2)`

. You can extend this function as you need.

`DelaunayTriangulation.number_type`

— Function`number_type(vor::VoronoiTessellation)`

Returns the type of the numbers used in the Voronoi tessellation `vor`

.

`number_type(x)`

Given a container `x`

, returns the number type used for storing coordinates.

`DelaunayTriangulation.push_point!`

— Function`push_point!(pts, x, y)`

Pushes the point `(x, y)`

into `pts`

. The only methods currently defined are

```
push_point!(pts::AbstractVector{T}, x, y) where {F,T<:NTuple{2,F}} = push!(pts, (F(x), F(y)))
push_point!(pts::AbstractVector{T}, x, y) where {F<:Number,T<:AbstractVector{F}} = push!(pts, F[x, y])
```

You can extend this function as needed. We also provide the method

`push_point!(pts, p) = push_point!(pts, getx(p), gety(p))`

which you can extend if you have a point type `p`

that has `getx`

and `gety`

.

`DelaunayTriangulation.pop_point!`

— Function`pop_point!(pts)`

Pops the last point from `pts`

. The only method currently defined is

`pop_point!(pts::AbstractVector) = pop!(pts)`

You can extend this function as needed.

`DelaunayTriangulation.set_point!`

— Function`set_point!(points, i, x, y)`

Sets the point at index `i`

in `points`

to `(x, y)`

. The only methods currently defined are

```
set_point!(points::AbstractVector{T}, i, x, y) = (points[i] = (x, y))
set_point!(points::AbstractMatrix{T}, i, x, y) where {T} = (points[1, i] = x; points[2, i] = y)
```

You can extend this function as needed. We also define

`set_point!(points, i, p) = set_point!(points, i, getx(p), gety(p))`

### Generic Methods

`DelaunayTriangulation.get_point`

— Function`get_point(pts::P, i...)`

Given a collection of points `pts`

, returns the points corresponding to the indices in `i...`

. This simply calls `getpoint`

- you do not need to extend this method.

`DelaunayTriangulation.points_are_unique`

— Function`points_are_unique(pts)`

Returns `true`

if `pts`

has no duplicate points, and `false`

otherwise.

`DelaunayTriangulation.lexicographic_order`

— Function`lexicographic_order(pts)`

Returns a set of indices `idx`

that gives the lexicographic ordering of the set of points `pts`

, i.e. sorting by `x`

and then sorting points with duplicate `x`

-coordinates by `y`

. The implementation is simply

`lexicographic_order(pts) = (sortperm ∘ collect ∘ each_point)(pts)`

which you might want to specialise for an easier representation of your points `pts`

.

`DelaunayTriangulation.mean_points`

— Function`mean_points(points, vertices = each_point_index(points))`

Returns the mean of the points in `points`

indexed by `vertices`

, given as a `Tuple`

of the form `(mean_x, mean_y)`

.