# Adjacent

The `Adjacent`

map is used for mapping edges to vertices that together form a positively oriented triangle. The definition of the `Adjacent`

map is below:

```
struct Adjacent{I,E}
adjacent::DefaultDict{E,I,I}
function Adjacent{I,E}() where {I,E}
A = DefaultDict{E,I,I}(I(DefaultAdjacentValue))
adj = new{I,E}(A)
return adj
end
Adjacent(adj::DefaultDict{E,I,I}) where {I,E} = new{I,E}(adj)
end
```

We list the complete docstring for `Adjacent`

below, along with individual docstrings for methods for working with `Adjacent`

.

`DelaunayTriangulation.Adjacent`

— Type`Adjacent{I,E}`

Struct for storing adjacency relationships for mapping edges to vertices that together form a positively oriented triangle in an associated triangulation. The type `I`

is the integer type used, while `E`

is the edge type.

See the docs for a description of how boundary edges are handled.

See also `Adjacent2Vertex`

.

**Fields**

`adjacent::Dict{E,I}`

The `Dict`

used for storing the edges (the keys) and the associated vertices (the values). If `(u, v)`

is not a valid edge, then `w = get_adjacent(adjacent, u, v)`

returns `0`

(this value is defined in `DefaultAdjacentValue`

). Otherwise, `(u, v, w)`

is a positively oriented triangle.

**Constructors**

The adjacent map can be constructed in two ways:

`Adjacent{I, E}() where {I, E}`

Creates an empty map.

`Adjacent(adj::Dict{E,I,I}) where {E,I,I}`

Creates an adjacent map from an existing `Dict`

.

**Extended help**

You should not work with the `adjacent`

field directly. We provide the following functions for working with `Adjacent`

, where `adj`

denotes an `Adjacent{I, E}`

type. (Type information in the function signatures is omitted.)

**Accessors**

`get_adjacent(adj)`

`get_adjacent(adj, uv)`

or`get_adjacent(adj, u, v)`

In the latter methods, you can also use the keyword argument `check_existence`

to declare whether to check that the edge exists. This would be used if you need to be careful about different boundary indices on the same boundary curve. The default value is `Val(false)`

, meaning this isn't checked.

**Mutators**

`add_adjacent!(adj, uv, w)`

or`add_adjacent!(adj, u, v, w)`

`delete_adjacent!(adj, uv)`

or`delete_adjacent!(adj, u, v)`

`add_triangle!(adj, i, j, k)`

or`add_triangle!(adj, T)`

`add_triangle!(adj, T...)`

`delete_triangle!(adj, i, j, k)`

or`delete_triangle!(adj, T)`

`delete_triangle!(adj, T...)`

**Iteration**

You can also iterate over `Adjacent`

maps the same way as you would with a `Dict`

, e.g.

```
for (edge, vertex) in adj
get_adjacent(adj, edge) == vertex
end
```

Note that in the case that you have multiple boundary indices, this iteration may not be safe the iteration doesn't make use of `get_adjacent`

, which knows how to handle boundary indices properly (if you have just a single boundary, do not worry).

`DelaunayTriangulation.get_adjacent`

— Method`get_adjacent(adj::Adjacent)`

Given the adjacent map `adj`

, returns the `adjacent`

field.

`DelaunayTriangulation.get_adjacent`

— Method```
get_adjacent(adj::Adjacent{I,E}, uv::E; check_existence::V = Val(false), boundary_index_ranges=nothing) where {I,E,V}
get_adjacent(adj::Adjacent{I,E}, u, v; check_existence::V = Val(false), boundary_index_ranges=nothing) where {I,E,V}
```

Given the adjacent map `adj`

and an edge `(u, v)`

, returns the vertex `w`

such that `(u, v, w)`

is a positively oriented triangle in the underlying triangulation.

In the case of a ghost edge, `check_existence = Val(true)`

may be useful in case the boundary curve has multiple segments, meaning multiple boundary indices could correspond to the same same curve. If this is the case, then `boundary_index_ranges`

should also be a `Dict`

from `construct_boundary_index_ranges`

, so that all possible valid boundary indices can be checked.

`DelaunayTriangulation.add_adjacent!`

— Method```
add_adjacent!(adj::Adjacent, uv, w)
add_adjacent!(adj::Adjacent{I,E}, u, v, w) where {I,E}
```

Given the adjacent map `adj`

, an edge `(u, v)`

, and a vertex `w`

, adds the edge `(u, v)`

with corresponding value `w`

into the adjacent map so that `(u, v, w)`

is a positively oriented triangle in the underlying triangulation.

`DelaunayTriangulation.delete_adjacent!`

— Method```
delete_adjacent!(adj::Adjacent, uv)
delete_adjacent!(adj::Adjacent{I,E}, u, v) where {I,E}
```

Given the adjacent map `adj`

and an edge `(u, v)`

, deletes the edge `(u, v)`

from the adjacent map.

`DelaunayTriangulation.add_triangle!`

— Method`add_triangle!(adj::Adjacent, i, j, k)`

Given an adjacent map `adj`

and indices `(i, j, k)`

representing some triangle, adds that triangle into the adjacent map. In particular, adds the edges `(i, j)`

, `(j, k)`

, and `(k, i)`

into `adj`

with corresponding values `k`

, `i`

, and `j`

, respectively.

`DelaunayTriangulation.add_triangle!`

— Method`add_triangle!(adj::Adjacent, T...)`

Given an adjacent map `adj`

and triangles `T...`

, adds the triangles into `adj`

. See also `add_triangle!(::Ts, ::V, ::V, ::V) where {I,E,V<:Integer,Ts<:Adjacent{I,E}}`

.

`DelaunayTriangulation.delete_triangle!`

— Method`delete_triangle!(adj::Adjacent, i, j, k)`

Given an adjacent map `adj`

and indices `(i, j, k)`

representing some triangle, deletes that triangle into the adjacent map. In particular, deletes the edges `(i, j)`

, `(j, k)`

, and `(k, i)`

from `adj`

.

`DelaunayTriangulation.delete_triangle!`

— Method`delete_triangle!(adj::Adjacent, T...)`

Given an adjacent map `adj`

and triangles `T...`

, deletes the triangles from `adj`

. See also `delete_triangle!(::Ts, ::V, ::V, ::V) where {I,E,V<:Integer,Ts<:Adjacent{I,E}}`

.