Skip to content

Commit f0896b9

Browse files
committed
more granular docs
1 parent 291c892 commit f0896b9

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

docs/make.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ makedocs(
1212
sitename = "GeometryBasics.jl",
1313
pages = [
1414
"index.md",
15+
"primitives.md",
1516
"rectangles.md",
1617
"polygons.md",
1718
"meshes.md",
19+
"decomposition.md",
20+
"distancefields.md",
1821
"api.md",
1922
],
2023
modules = [GeometryTypes]

docs/src/decomposition.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,45 @@
11
# Decomposition
2+
3+
4+
## Displaying primitives
5+
6+
To display geometry primitives, they need to be decomposable.
7+
This can be done for any arbitrary primitive, by overloading the following interface:
8+
9+
```julia
10+
# Lets take SimpleRectangle as an example:
11+
# Minimal set of decomposable attributes to build up a triangle mesh
12+
isdecomposable(::Type{T}, ::Type{HR}) where {T<:Point, HR<:SimpleRectangle} = true
13+
isdecomposable(::Type{T}, ::Type{HR}) where {T<:Face, HR<:SimpleRectangle} = true
14+
15+
# Example implementation of decompose for points
16+
function GeometryBasics.decompose(P::Type{Point{3, PT}}, r::SimpleRectangle, resolution=(2,2)) where PT
17+
w,h = resolution
18+
vec(P[(x,y,0) for x=range(r.x, stop = r.x+r.w, length = w), y=range(r.y, stop = r.y+r.h, length = h)])
19+
end
20+
21+
function GeometryBasics.decompose(::Type{T}, r::SimpleRectangle, resolution=(2,2)) where T <: Face
22+
w,h = resolution
23+
Idx = LinearIndices(resolution)
24+
faces = vec([Face{4, Int}(
25+
Idx[i, j], Idx[i+1, j],
26+
Idx[i+1, j+1], Idx[i, j+1]
27+
) for i=1:(w-1), j=1:(h-1)]
28+
)
29+
decompose(T, faces)
30+
end
31+
```
32+
33+
With these methods defined, this constructor will magically work:
34+
35+
```julia
36+
rect = SimpleRectangle(0, 0, 1, 1)
37+
m = GLNormalMesh(rect)
38+
vertices(m) == decompose(Point3f0, rect)
39+
40+
faces(m) == decompose(GLTriangle, rect) # GLFace{3} == GLTriangle
41+
normals(m) # automatically calculated from mesh
42+
```
43+
44+
As you can see, the normals are automatically calculated only with the faces and points.
45+
You can overwrite that behavior, by also defining decompose for the `Normal` type!

docs/src/distancefields.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Distance Fields

docs/src/primitives.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Primitives
2+
3+
## Points and Vectors
4+
5+
## Simplices
6+
7+
## Shapes
8+
9+
```@docs
10+
Circle
11+
Sphere
12+
Cylinder
13+
```
14+
15+
## Abstract types
16+
17+
```@docs
18+
GeometryPrimitive
19+
AbstractSimplex
20+
AbstractMesh
21+
AbstractDistanceField
22+
```

0 commit comments

Comments
 (0)