Skip to content

Commit 81a20c0

Browse files
authored
Fix errors in docs & fix GeoInterface test failures (#228)
* add setup blocks for imports * Fix GeoInterface test failure * fix MetaMesh docs insertion
1 parent 5a7d6e2 commit 81a20c0

File tree

3 files changed

+50
-35
lines changed

3 files changed

+50
-35
lines changed

docs/src/meshes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ In that case we have 8 positions and 6 normals with FaceViews, or 24 without (as
3838

3939
## MetaMesh
4040

41-
```julia; canonical=false
41+
```@docs; canonical=false
4242
MetaMesh
4343
```
4444

docs/src/primitives.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ They are defined by an origin and a radius.
3838
While you can technically create a HyperSphere of any dimension, decomposition
3939
is only defined in 2D and 3D.
4040

41+
```@setup hypersphere
42+
using GeometryBasics
43+
```
4144
```@repl hypersphere
4245
s1 = HyperSphere{4, Int}(Point{4, Int}(0), 5)
4346
s2 = Sphere(Point3f(0, 0, 1), 1)
@@ -51,6 +54,10 @@ The coordinates of Circle are defined in anti-clockwise order.
5154

5255
A `Cylinder` is a 3D shape defined by two points and a radius.
5356

57+
58+
```@setup cylinder
59+
using GeometryBasics
60+
```
5461
```@repl cylinder
5562
c = Cylinder(Point3f(-1, 0, 0), Point3f(0, 0, 1), 0.3f0) # start point, end point, radius
5663
```
@@ -63,6 +70,10 @@ Cylinder supports normals an Tessellation, but currently no texture coordinates.
6370
coming together into a sharp point.
6471
It is defined by by the center point of the base, its height and its width.
6572

73+
74+
```@setup pyramid
75+
using GeometryBasics
76+
```
6677
```@repl pyramid
6778
p = Pyramid(Point3f(0), 1f0, 0.3f0) # center, height, width
6879
```
@@ -74,6 +85,9 @@ Pyramid supports normals, but currently no texture coordinates or tessellation
7485
In GeometryBasics `Tessellation` is a wrapper type for primitives which communicates
7586
how dense the mesh generated from one should be.
7687

88+
```@setup tessellation
89+
using GeometryBasics
90+
```
7791
```@repl tessellation
7892
t = Tessellation(Cylinder(Point3f(0), Point3f(0,0,1), 0.2), 32) # 32 vertices for each circle
7993
normal_mesh(t)
@@ -178,4 +192,4 @@ function GeometryBasics.texturecoordinates(::Parallelepiped{T}) where {T}
178192
]
179193
return FaceView(uvs, fs)
180194
end
181-
```
195+
```

src/basic_types.jl

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Base.ndims(::AbstractGeometry{Dim}) where {Dim} = Dim
1010
"""
1111
Polytope{Dim, T} <: AbstractGeometry{Dim, T}
1212
13-
A Polytope is the generalization of a Polygon to higher dimensions, i.e. a
13+
A Polytope is the generalization of a Polygon to higher dimensions, i.e. a
1414
geometric object consisting of flat faces.
1515
1616
A `Polygon` and `Ngon` are both 2D `Polytope`s. A `Simplex` is the simplest
@@ -22,7 +22,7 @@ abstract type AbstractPolygon{Dim,T} <: Polytope{Dim,T} end
2222
"""
2323
AbstractFace{N_indices, T} <: StaticVector{N_indices, T}
2424
25-
Parent type for all face types. The standard face type is typically a
25+
Parent type for all face types. The standard face type is typically a
2626
`GLTriangleFace = NgonFace{3, GLIndex}`.
2727
"""
2828
abstract type AbstractFace{N,T} <: StaticVector{N,T} end
@@ -109,7 +109,7 @@ Base.:(==)(f1::FT, f2::FT) where {FT <: AbstractFace{2}} = minmax(f1.data...) ==
109109
Base.hash(f::AbstractFace{2}, h::UInt) = hash(minmax(f.data...), h)
110110

111111
function Base.:(==)(f1::FT, f2::FT) where {FT <: AbstractFace{3}}
112-
return (f1.data == f2.data) || (f1.data == (f2[2], f2[3], f2[1])) ||
112+
return (f1.data == f2.data) || (f1.data == (f2[2], f2[3], f2[1])) ||
113113
(f1.data == (f2[3], f2[1], f2[2]))
114114
end
115115
function Base.hash(f::AbstractFace{3}, h::UInt)
@@ -347,6 +347,7 @@ struct LineString{Dim, T<:Real} <: AbstractGeometry{Dim, T}
347347
points::Vector{Point{Dim, T}}
348348
end
349349
Base.length(ls::LineString) = length(coordinates(ls))
350+
Base.:(==)(a::LineString, b::LineString) = a.points == b.points
350351
coordinates(ls::LineString) = ls.points
351352

352353
struct MultiLineString{Dim, T<:Real} <: AbstractGeometry{Dim, T}
@@ -382,7 +383,7 @@ Base.length(mpt::MultiPoint) = length(mpt.points)
382383
"""
383384
FaceView(data, faces)
384385
385-
A FaceView is an alternative to passing a vertex attribute directly to a mesh.
386+
A FaceView is an alternative to passing a vertex attribute directly to a mesh.
386387
It bundles `data` with a new set of `faces` which may index that data differently
387388
from the faces defined in a mesh. This can be useful to avoid duplication in `data`.
388389
@@ -395,7 +396,7 @@ per_face_normals = FaceView(
395396
)
396397
```
397398
398-
If you need a mesh with strictly per-vertex data, e.g. for rendering, you can use
399+
If you need a mesh with strictly per-vertex data, e.g. for rendering, you can use
399400
`expand_faceviews(mesh)` to convert every vertex attribute to be per-vertex. This
400401
will duplicate data and reorder faces as needed.
401402
@@ -457,7 +458,7 @@ function verify(fs::AbstractVector{FT}, fv::FaceView, name = nothing) where {FT
457458
return true
458459
end
459460

460-
# Dodgy definitions... (since attributes can be FaceView or Array it's often
461+
# Dodgy definitions... (since attributes can be FaceView or Array it's often
461462
# useful to treat a FaceView like the vertex data it contains)
462463
Base.length(x::FaceView) = length(values(x))
463464
# Base.iterate(x::FaceView) = iterate(values(x))
@@ -485,8 +486,8 @@ end
485486
"""
486487
AbstractMesh
487488
488-
An abstract mesh is a collection of Polytope elements (Simplices / Ngons). The
489-
connections are defined via faces(mesh) and the coordinates of the elements are
489+
An abstract mesh is a collection of Polytope elements (Simplices / Ngons). The
490+
connections are defined via faces(mesh) and the coordinates of the elements are
490491
returned by coordinates(mesh).
491492
"""
492493
abstract type AbstractMesh{Dim, T} <: AbstractGeometry{Dim, T} end
@@ -504,9 +505,9 @@ struct Mesh{...}
504505
end
505506
```
506507
507-
A vertex typically carries multiple distinct pieces of data, e.g. a position,
508-
a normal, a texture coordinate, etc. We call those pieces of data vertex
509-
attributes. The `vertex_attributes` field contains the name and a collection
508+
A vertex typically carries multiple distinct pieces of data, e.g. a position,
509+
a normal, a texture coordinate, etc. We call those pieces of data vertex
510+
attributes. The `vertex_attributes` field contains the name and a collection
510511
`<: AbstractVector` or `<: FaceView` for each attribute. The n-th element of that
511512
collection is the value of the corresponding attribute for the n-th vertex.
512513
@@ -517,27 +518,27 @@ vertex_attributes[:normal] = [normal1, normal2, normal3, ...]
517518
...
518519
```
519520
520-
A `NamedTuple` is used here to allow different meshes to carry different vertex
521-
attributes while also keeping things type stable. The constructor enforces a
521+
A `NamedTuple` is used here to allow different meshes to carry different vertex
522+
attributes while also keeping things type stable. The constructor enforces a
522523
few restrictions:
523524
- The first attribute must be named `position` and must have a `Point{PositionDim, PositionType}` eltype.
524-
- Each vertex attribute must refer to the same number of vertices. (All vertex attributes defined by
525+
- Each vertex attribute must refer to the same number of vertices. (All vertex attributes defined by
525526
AbstractVector must match in length. For FaceViews, the number of faces needs to match.)
526527
527-
See also: [`vertex_attributes`](@ref), [`coordinates`](@ref), [`normals`](@ref),
528-
[`texturecoordinates`](@ref), [`decompose`](@ref), [`FaceView`](@ref),
528+
See also: [`vertex_attributes`](@ref), [`coordinates`](@ref), [`normals`](@ref),
529+
[`texturecoordinates`](@ref), [`decompose`](@ref), [`FaceView`](@ref),
529530
[`expand_faceviews`](@ref)
530531
531-
The `faces` field is a collection `<: AbstractVector{FaceType}` containing faces
532+
The `faces` field is a collection `<: AbstractVector{FaceType}` containing faces
532533
that describe how vertices are connected. Typically these are `(GL)TriangleFace`s
533534
or `QuadFace`s, but they can be any collection of vertex indices `<: AbstractFace`.
534535
535536
See also: [`faces`](@ref), [`decompose`](@ref)
536537
537-
The `views` field can be used to separate the mesh into mutliple submeshes. Each
538-
submesh is described by a "view" into the `faces` vector, i.e. submesh n uses
539-
`mesh.faces[mesh.views[n]]`. A `Mesh` can be constructed without `views`, which
540-
results in an empty `views` vector.
538+
The `views` field can be used to separate the mesh into mutliple submeshes. Each
539+
submesh is described by a "view" into the `faces` vector, i.e. submesh n uses
540+
`mesh.faces[mesh.views[n]]`. A `Mesh` can be constructed without `views`, which
541+
results in an empty `views` vector.
541542
542543
See also: [`merge`](@ref), [`split_mesh`](@ref)
543544
"""
@@ -554,7 +555,7 @@ struct Mesh{
554555
views::Vector{UnitRange{Int}}
555556

556557
function Mesh(
557-
vertex_attributes::NamedTuple{Names, VAT},
558+
vertex_attributes::NamedTuple{Names, VAT},
558559
fs::FVT,
559560
views::Vector{UnitRange{Int}} = UnitRange{Int}[]
560561
) where {
@@ -625,7 +626,7 @@ texturecoordinates(mesh::Mesh) = hasproperty(mesh, :uv) ? mesh.uv : nothing
625626
"""
626627
vertex_attributes(mesh::Mesh)
627628
628-
Returns a dictionairy containing the vertex attributes of the given mesh.
629+
Returns a dictionairy containing the vertex attributes of the given mesh.
629630
Mutating these will change the mesh.
630631
"""
631632
vertex_attributes(mesh::Mesh) = getfield(mesh, :vertex_attributes)
@@ -634,7 +635,7 @@ Base.getindex(mesh::Mesh, i::Integer) = mesh.position[mesh.faces[i]]
634635
Base.length(mesh::Mesh) = length(mesh.faces)
635636

636637
function Base.:(==)(a::Mesh, b::Mesh)
637-
return (a.vertex_attributes == b.vertex_attributes) &&
638+
return (a.vertex_attributes == b.vertex_attributes) &&
638639
(faces(a) == faces(b)) && (a.views == b.views)
639640
end
640641

@@ -654,17 +655,17 @@ end
654655
655656
Constructs a mesh from the given arguments.
656657
657-
If `positions` are given explicitly, they are merged with other vertex attributes
658+
If `positions` are given explicitly, they are merged with other vertex attributes
658659
under the name `position`. Otherwise they must be part of `attributes`. If `faces`
659660
are not given `attributes.position` must be a FaceView.
660661
661-
Any other vertex attribute can be either an `AbstractVector` or a `FaceView`
662+
Any other vertex attribute can be either an `AbstractVector` or a `FaceView`
662663
thereof. Every vertex attribute that is an `AbstractVector` must be sufficiently
663664
large to be indexable by `mesh.faces`. Every vertex attribute that is a `FaceView`
664665
must contain similar faces to `mesh.faces`, i.e. contain the same number of faces
665666
and have faces of matching length.
666667
667-
`views` can be defined optionally to implicitly split the mesh into multi
668+
`views` can be defined optionally to implicitly split the mesh into multi
668669
sub-meshes. This is done by providing ranges for indexing faces which correspond
669670
to the sub-meshes. By default this is left empty.
670671
"""
@@ -673,7 +674,7 @@ function Mesh(faces::AbstractVector{<:AbstractFace}; views::Vector{UnitRange{Int
673674
end
674675

675676
function Mesh(points::AbstractVector{Point{Dim, T}},
676-
faces::AbstractVector{<:AbstractFace};
677+
faces::AbstractVector{<:AbstractFace};
677678
views = UnitRange{Int}[], kwargs...) where {Dim, T}
678679
va = (position = points, kwargs...)
679680
return Mesh(va, faces, views)
@@ -716,13 +717,13 @@ Constructs a MetaMesh either from another `mesh` or by constructing another mesh
716717
with the given `positions` and `faces`. Any keyword arguments given will be
717718
stored in the `meta` field in `MetaMesh`.
718719
719-
This struct is meant to be used for storage of non-vertex data. Any vertex
720-
related data should be stored as a vertex attribute in `Mesh`. One example of such
720+
This struct is meant to be used for storage of non-vertex data. Any vertex
721+
related data should be stored as a vertex attribute in `Mesh`. One example of such
721722
data is material data, which is defined per view in `mesh.views`, i.e. per submesh.
722723
723-
The metadata added to the MetaMesh can be manipulated with Dict-like operations
724-
(getindex, setindex!, get, delete, keys, etc). Vertex attributes can be accessed
725-
via fields and the same getters as mesh. The mesh itself can be retrieved with
724+
The metadata added to the MetaMesh can be manipulated with Dict-like operations
725+
(getindex, setindex!, get, delete, keys, etc). Vertex attributes can be accessed
726+
via fields and the same getters as mesh. The mesh itself can be retrieved with
726727
`Mesh(metamesh)`.
727728
"""
728729
function MetaMesh(mesh::AbstractMesh; kwargs...)

0 commit comments

Comments
 (0)