Skip to content

Commit df38b65

Browse files
authored
Merge pull request #93 from abhro/docs
Documentation website and docstrings
2 parents d0c96e0 + a13e939 commit df38b65

File tree

8 files changed

+89
-24
lines changed

8 files changed

+89
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44

55
*Manifest.toml
66
*.swp
7+
8+
/docs/build

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

docs/make.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Documenter
2+
using CoordinateTransformations
3+
4+
makedocs(
5+
sitename = "CoordinateTransformations.jl",
6+
pages = [
7+
"Introduction" => "index.md",
8+
"API" => "api.md",
9+
],
10+
)

docs/src/api.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# CoordinateTransformations.jl documentation
2+
3+
## API Reference
4+
5+
```@autodocs
6+
Modules = [CoordinateTransformations]
7+
```

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CoordinateTransformations.jl

src/affine.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ abstract type AbstractAffineMap <: Transformation end
22

33
"""
44
Translation(v) <: AbstractAffineMap
5-
Translation(dx, dy) (2D)
6-
Translation(dx, dy, dz) (3D)
5+
Translation(dx, dy) # 2D
6+
Translation(dx, dy, dz) # 3D
77
88
Construct the `Translation` transformation for translating Cartesian points by
99
an offset `v = (dx, dy, ...)`
@@ -215,8 +215,8 @@ transform_deriv(trans::AffineMap, x) = trans.linear
215215
216216
Create an Affine transformation that approximately maps the `from` points to the `to` points.
217217
At least `n+1` non-degenerate points are required to map an `n`-dimensional space.
218-
If there are more points than this, the transformation will be over-determined and a least-squares
219-
solution will be computed.
218+
If there are more points than this, the transformation will be over-determined
219+
and a least-squares solution will be computed.
220220
"""
221221
function AffineMap((from_points,to_points)::Pair)
222222
M = column_matrix(to_points) * pinv(column_matrix(from_points, 1))

src/coordinatesystems.jl

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
### 2D Coordinate systems ###
33
#############################
44
"""
5-
`Polar{T,A}(r::T, θ::A)` - 2D polar coordinates
5+
Polar{T,A}(r::T, θ::A)
6+
7+
2D polar coordinates
68
"""
79
struct Polar{T,A}
810
r::T
@@ -18,7 +20,9 @@ function Polar(r, θ)
1820
end
1921

2022
"""
21-
`Polar{T,T}(x::AbstractVector)` - 2D polar coordinates from an AbstractVector of length 2
23+
Polar{T,T}(x::AbstractVector)
24+
25+
2D polar coordinates from an AbstractVector of length 2
2226
"""
2327
function Polar(x::AbstractVector)
2428
return PolarFromCartesian()(x)
@@ -27,9 +31,17 @@ end
2731
Base.show(io::IO, x::Polar) = print(io, "Polar(r=$(x.r), θ=$(x.θ) rad)")
2832
Base.isapprox(p1::Polar, p2::Polar; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...)
2933

30-
"`PolarFromCartesian()` - transformation from `AbstractVector` of length 2 to `Polar` type"
34+
"""
35+
PolarFromCartesian()
36+
37+
Transformation from `AbstractVector` of length 2 to `Polar` type
38+
"""
3139
struct PolarFromCartesian <: Transformation; end
32-
"`CartesianFromPolar()` - transformation from `Polar` type to `SVector{2}` type"
40+
"""
41+
CartesianFromPolar()
42+
43+
Transformation from `Polar` type to `SVector{2}` type
44+
"""
3345
struct CartesianFromPolar <: Transformation; end
3446

3547
Base.show(io::IO, trans::PolarFromCartesian) = print(io, "PolarFromCartesian()")
@@ -79,10 +91,13 @@ Base.convert(::Type{Polar}, v::AbstractVector) = PolarFromCartesian()(v)
7991
### 3D Coordinate Systems ###
8092
#############################
8193
"""
82-
Spherical(r, θ, ϕ) - 3D spherical coordinates
94+
Spherical(r, θ, ϕ)
95+
96+
3D spherical coordinates
8397
8498
There are many Spherical coordinate conventions and this library uses a somewhat exotic one.
85-
Given a vector `v` with Cartesian coordinates `xyz`, let `v_xy = [x,y,0]` be the orthogonal projection of `v` on the `xy` plane.
99+
Given a vector `v` with Cartesian coordinates `xyz`, let `v_xy = [x,y,0]` be the
100+
orthogonal projection of `v` on the `xy` plane.
86101
87102
* `r` is the radius. It is given by `norm(v, 2)`.
88103
* `θ` is the azimuth. It is the angle from the x-axis to `v_xy`
@@ -95,10 +110,11 @@ julia> v = randn(3);
95110
96111
julia> sph = SphericalFromCartesian()(v);
97112
98-
julia> r = sph.r; θ=sph.θ; ϕ=sph.ϕ;
113+
julia> r = sph.r; θ = sph.θ; ϕ = sph.ϕ;
99114
100-
julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r*sin(ϕ)]
115+
julia> v ≈ [r * cos(θ) * cos(ϕ), r * sin(θ) * cos(ϕ), r * sin(ϕ)]
101116
true
117+
```
102118
"""
103119
struct Spherical{T,A}
104120
r::T
@@ -118,7 +134,9 @@ Base.show(io::IO, x::Spherical) = print(io, "Spherical(r=$(x.r), θ=$(x.θ) rad,
118134
Base.isapprox(p1::Spherical, p2::Spherical; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...) && isapprox(p1.ϕ, p2.ϕ; kwargs...)
119135

120136
"""
121-
Cylindrical(r, θ, z) - 3D cylindrical coordinates
137+
Cylindrical(r, θ, z)
138+
139+
3D cylindrical coordinates
122140
"""
123141
struct Cylindrical{T,A}
124142
r::T
@@ -137,17 +155,41 @@ end
137155
Base.show(io::IO, x::Cylindrical) = print(io, "Cylindrical(r=$(x.r), θ=$(x.θ) rad, z=$(x.z))")
138156
Base.isapprox(p1::Cylindrical, p2::Cylindrical; kwargs...) = isapprox(p1.r, p2.r; kwargs...) && isapprox(p1.θ, p2.θ; kwargs...) && isapprox(p1.z, p2.z; kwargs...)
139157

140-
"`SphericalFromCartesian()` - transformation from 3D point to `Spherical` type"
158+
"""
159+
SphericalFromCartesian()
160+
161+
Transformation from 3D point to `Spherical` type
162+
"""
141163
struct SphericalFromCartesian <: Transformation; end
142-
"`CartesianFromSpherical()` - transformation from `Spherical` type to `SVector{3}` type"
164+
"""
165+
CartesianFromSpherical()
166+
167+
Transformation from `Spherical` type to `SVector{3}` type
168+
"""
143169
struct CartesianFromSpherical <: Transformation; end
144-
"`CylindricalFromCartesian()` - transformation from 3D point to `Cylindrical` type"
170+
"""
171+
CylindricalFromCartesian()
172+
173+
Transformation from 3D point to `Cylindrical` type
174+
"""
145175
struct CylindricalFromCartesian <: Transformation; end
146-
"`CartesianFromCylindrical()` - transformation from `Cylindrical` type to `SVector{3}` type"
176+
"""
177+
CartesianFromCylindrical()
178+
179+
Transformation from `Cylindrical` type to `SVector{3}` type
180+
"""
147181
struct CartesianFromCylindrical <: Transformation; end
148-
"`CylindricalFromSpherical()` - transformation from `Spherical` type to `Cylindrical` type"
182+
"""
183+
CylindricalFromSpherical()
184+
185+
Transformation from `Spherical` type to `Cylindrical` type
186+
"""
149187
struct CylindricalFromSpherical <: Transformation; end
150-
"`SphericalFromCylindrical()` - transformation from `Cylindrical` type to `Spherical` type"
188+
"""
189+
SphericalFromCylindrical()
190+
191+
Transformation from `Cylindrical` type to `Spherical` type
192+
"""
151193
struct SphericalFromCylindrical <: Transformation; end
152194

153195
Base.show(io::IO, trans::SphericalFromCartesian) = print(io, "SphericalFromCartesian()")

src/perspective.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ This transformation is designed to be used in composition with other coordinate
1313
transformations, defining e.g. the position and orientation of the camera. For
1414
example:
1515
16-
cam_transform = PerspectiveMap() ∘ inv(AffineMap(cam_rotation, cam_position))
17-
screen_points = map(cam_transform, points)
16+
```julia
17+
cam_transform = PerspectiveMap() ∘ inv(AffineMap(cam_rotation, cam_position))
18+
screen_points = map(cam_transform, points)
19+
```
1820
19-
(see also `cameramap`)
21+
(see also [`cameramap`](@ref))
2022
"""
2123
struct PerspectiveMap <: Transformation
2224
end
@@ -55,7 +57,7 @@ plane. For instance, you may wish to have the point (0,0) represent the top-left
5557
corner of your imaging sensor. This measurement is in the units after applying
5658
`scale` (e.g. pixels).
5759
58-
(see also `PerspectiveMap`)
60+
(see also [`PerspectiveMap`](@ref))
5961
"""
6062
cameramap() = PerspectiveMap()
6163
cameramap(scale::Number) =
@@ -66,4 +68,3 @@ cameramap(scale::Number, offset::Tuple{Number,Number}) =
6668
AffineMap(UniformScaling(scale), SVector(-offset[1], -offset[2])) PerspectiveMap()
6769
cameramap(scale::Tuple{Number, Number}, offset::Tuple{Number,Number}) =
6870
AffineMap(@SMatrix([scale[1] 0; 0 scale[2]]), SVector(-offset[1], -offset[2])) PerspectiveMap()
69-

0 commit comments

Comments
 (0)