Skip to content

Commit

Permalink
Specialize show for QuatVec and Rotor (#44)
Browse files Browse the repository at this point in the history
Update CI
  • Loading branch information
moble authored Mar 2, 2023
1 parent 4f0930d commit a03dfa7
Show file tree
Hide file tree
Showing 15 changed files with 167 additions and 101 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: CI
on:
push:
branches:
- main
tags: ['*']
pull_request:
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
if: >-
!contains(github.ref, 'refs/tags/')
&& !contains(github.event.head_commit.message, '[skip ci]')
&& !contains(github.event.head_commit.message, '[skip tests]')
strategy:
fail-fast: false
matrix:
version:
- '1'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
include:
- version: 'nightly'
os: ubuntu-latest
arch: x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
show-versioninfo: true
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
if: "matrix.version == '1' && matrix.os == 'ubuntu-latest'"
with:
files: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
if: >-
!contains(github.event.head_commit.message, '[skip ci]')
&& !contains(github.event.head_commit.message, '[skip docs]')
permissions:
contents: write
statuses: write
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
- run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using Quaternionic
DocMeta.setdocmeta!(Quaternionic, :DocTestSetup, :(using Quaternionic); recursive=true)
doctest(Quaternionic)'
31 changes: 0 additions & 31 deletions .github/workflows/docs.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/register.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Register Package

on:
workflow_dispatch:
inputs:
version:
description: Version to register or component to bump
description: Version to register or component to bump (major, minor, or patch)
required: true
default: "patch"

jobs:
register:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: julia-actions/RegisterAction@latest
with:
Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/tests.yml

This file was deleted.

1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
Quaternionic = "0756cd96-85bf-4b6f-a009-b5012ea7a443"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ makedocs(;
deploydocs(;
repo="github.com/moble/Quaternionic.jl",
devbranch="main",
push_preview=true,
)
17 changes: 17 additions & 0 deletions scripts/docs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Run this script from any directory as
#
# julia -t 4 scripts/docs.jl
#
# The docs will build and the browser should open automatically. `LiveServer`
# will monitor the docs for any changes, then rebuild them and refresh the browser
# until this script is stopped.

import Dates
println("Building docs starting at ", Dates.format(Dates.now(), "HH:MM:SS"), ".")

using Pkg
cd((@__DIR__) * "/..")
Pkg.activate("docs")

using LiveServer
servedocs(launch_browser=true)
20 changes: 20 additions & 0 deletions scripts/test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Dates
println("Running tests starting at ", Dates.format(Dates.now(), "HH:MM:SS"), ".")

using Pkg
cd((@__DIR__) * "/..")
Pkg.activate(".")

try
Ξ”t = @elapsed Pkg.test("Quaternionic"; coverage=true, test_args=ARGS)
println("Running tests took $Ξ”t seconds.")
catch e
println("Tests failed; proceeding to coverage")
end

Pkg.activate() # Activate Julia's base (home) directory
using Coverage
cd((@__DIR__) * "/..")
coverage = Coverage.process_folder()
Coverage.writefile("lcov.info", coverage)
Coverage.clean_folder(".")
10 changes: 8 additions & 2 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,19 @@ function Base.show(io::IO, q::AbstractQuaternion)
end
print(
io,
q[1],
q isa QuatVec ? "" : q[1],
pm(q[2]), "𝐒",
pm(q[3]), "𝐣",
pm(q[4]), "𝐀"
)
end

function Base.show(io::IO, q::Rotor)
print(io, "Rotor(")
invoke(Base.show, Tuple{IO, AbstractQuaternion}, io, q)
print(io, ")")
end

function Base.show(io::IO, ::MIME"text/latex", q::AbstractQuaternion)
function pm(x)
s = latexify(x, env=:raw, bracket=true)
Expand All @@ -133,7 +139,7 @@ function Base.show(io::IO, ::MIME"text/latex", q::AbstractQuaternion)
s
end
s = latexstring(
latexify(q[1], env=:raw, bracket=true),
q isa QuatVec ? "" : latexify(q[1], env=:raw, bracket=true),
pm(q[2]), "\\,\\mathbf{i}",
pm(q[3]), "\\,\\mathbf{j}",
pm(q[4]), "\\,\\mathbf{k}"
Expand Down
4 changes: 2 additions & 2 deletions src/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ return the orientation as a `Rotor`, followed by the angular velocity as a
julia> R, ω⃗, Ṙ = precessing_nutating_example();
julia> R(12.34)
0.9944579779058746 + 0.09804177421238346𝐒 - 0.00084850453525312𝐣 + 0.03795287510453948𝐀
Rotor(0.9944579779058746 + 0.09804177421238346𝐒 - 0.00084850453525312𝐣 + 0.03795287510453948𝐀)
julia> Ο‰βƒ—(345.67)
0.0 + 0.00046343007342867023𝐒 - 0.0007032818419003181𝐣 + 0.006214814810035088𝐀
+ 0.00046343007342867023𝐒 - 0.0007032818419003181𝐣 + 0.006214814810035088𝐀
julia> Ο΅ = 1e-6; (R(Ο΅) - R(-Ο΅)) / 2Ο΅ # Approximate derivative at t=0
-3.8491432263754177e-7 + (3.9080960689830135e-6)𝐒 - (6.861695854245619e-5)𝐣 + 0.003076329202503836𝐀
julia> Ṙ(0)
Expand Down
8 changes: 4 additions & 4 deletions src/interpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ julia> q = [imx, -imx, imx, -imx];
julia> unflip(q)
4-element Vector{QuatVec{Int64}}:
0 + 1𝐒 + 0𝐣 + 0𝐀
0 + 1𝐒 + 0𝐣 + 0𝐀
0 + 1𝐒 + 0𝐣 + 0𝐀
0 + 1𝐒 + 0𝐣 + 0𝐀
+ 1𝐒 + 0𝐣 + 0𝐀
+ 1𝐒 + 0𝐣 + 0𝐀
+ 1𝐒 + 0𝐣 + 0𝐀
+ 1𝐒 + 0𝐣 + 0𝐀
```
"""
function unflip(q::AbstractArray{<:AbstractQuaternion}; dim::Integer=1)
Expand Down
4 changes: 2 additions & 2 deletions src/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ scalar part exactly 0.
# Examples
```jldoctest
julia> log(exp(1.2imy))
0.0 + 0.0𝐒 + 1.2𝐣 + 0.0𝐀
+ 0.0𝐒 + 1.2𝐣 + 0.0𝐀
julia> log(Quaternion(exp(7)))
7.0 + 0.0𝐒 + 0.0𝐣 + 0.0𝐀
Expand Down Expand Up @@ -135,7 +135,7 @@ Exponential of a quaternion
# Examples
```jldoctest
julia> exp(imx*Ο€/4) # Rotation through Ο€/2 (note the extra 1/2) about the x axis
0.7071067811865476 + 0.7071067811865475𝐒 + 0.0𝐣 + 0.0𝐀
Rotor(0.7071067811865476 + 0.7071067811865475𝐒 + 0.0𝐣 + 0.0𝐀)
```
"""
function Base.exp(q::Quaternion{T}) where {T}
Expand Down
24 changes: 12 additions & 12 deletions src/quaternion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ function and get the desired result.
```jldoctest
julia> Rotor(1, 2, 3, 4)
0.18257418583505536 + 0.3651483716701107𝐒 + 0.5477225575051661𝐣 + 0.7302967433402214𝐀
Rotor(0.18257418583505536 + 0.3651483716701107𝐒 + 0.5477225575051661𝐣 + 0.7302967433402214𝐀)
julia> Rotor(Quaternion(1, 2, 3, 4))
0.18257418583505536 + 0.3651483716701107𝐒 + 0.5477225575051661𝐣 + 0.7302967433402214𝐀
Rotor(0.18257418583505536 + 0.3651483716701107𝐒 + 0.5477225575051661𝐣 + 0.7302967433402214𝐀)
julia> Rotor{Float16}(1, 2, 3, 4)
0.1826 + 0.3652𝐒 + 0.548𝐣 + 0.7305𝐀
Rotor(0.1826 + 0.3652𝐒 + 0.548𝐣 + 0.7305𝐀)
julia> Rotor(2, 3, 4)
0.0 + 0.3713906763541037𝐒 + 0.5570860145311556𝐣 + 0.7427813527082074𝐀
Rotor(0.0 + 0.3713906763541037𝐒 + 0.5570860145311556𝐣 + 0.7427813527082074𝐀)
julia> Rotor(1)
1 + 0𝐒 + 0𝐣 + 0𝐀
Rotor(1 + 0𝐒 + 0𝐣 + 0𝐀)
```
"""
struct Rotor{T<:Number} <: AbstractQuaternion{T}
Expand Down Expand Up @@ -145,13 +145,13 @@ always set to 0.
```jldoctest
julia> QuatVec(1, 2, 3, 4)
0 + 2𝐒 + 3𝐣 + 4𝐀
+ 2𝐒 + 3𝐣 + 4𝐀
julia> QuatVec(Quaternion(1, 2, 3, 4))
0 + 2𝐒 + 3𝐣 + 4𝐀
+ 2𝐒 + 3𝐣 + 4𝐀
julia> QuatVec(2, 3, 4)
0 + 2𝐒 + 3𝐣 + 4𝐀
+ 2𝐒 + 3𝐣 + 4𝐀
julia> QuatVec(1)
0 + 0𝐒 + 0𝐣 + 0𝐀
+ 0𝐒 + 0𝐣 + 0𝐀
```
"""
struct QuatVec{T<:Number} <: AbstractQuaternion{T}
Expand Down Expand Up @@ -236,7 +236,7 @@ bold: `𝐒`.
julia> imx * imx
-1 + 0𝐒 + 0𝐣 + 0𝐀
julia> 1.2imx
0.0 + 1.2𝐒 + 0.0𝐣 + 0.0𝐀
+ 1.2𝐒 + 0.0𝐣 + 0.0𝐀
```
"""
const imx = QuatVec(false, true, false, false)
Expand All @@ -253,7 +253,7 @@ bold: `𝐣`.
julia> imy * imy
-1 + 0𝐒 + 0𝐣 + 0𝐀
julia> 1.2imy
0.0 + 0.0𝐒 + 1.2𝐣 + 0.0𝐀
+ 0.0𝐒 + 1.2𝐣 + 0.0𝐀
```
"""
const imy = QuatVec(false, false, true, false)
Expand All @@ -270,7 +270,7 @@ bold: `𝐀`.
julia> imz * imz
-1 + 0𝐒 + 0𝐣 + 0𝐀
julia> 1.2imz
0.0 + 0.0𝐒 + 0.0𝐣 + 1.2𝐀
+ 0.0𝐒 + 0.0𝐣 + 1.2𝐀
```
"""
const imz = QuatVec(false, false, false, true)
Expand Down
18 changes: 18 additions & 0 deletions test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@
Base.show(io, MIME("text/latex"), Quaternion(a-b, b*c, c/d, d+e))
@test String(take!(io)) == "\$a - b + b c\\,\\mathbf{i} + \\frac{c}{d}\\,\\mathbf{j} + \\left(d + e\\right)\\,\\mathbf{k}\$"

Base.show(io, MIME("text/plain"), QuatVec{Float64}(1, 2, 3, 4))
@test String(take!(io)) == " + 2.0𝐒 + 3.0𝐣 + 4.0𝐀"
Base.show(io, MIME("text/plain"), QuatVec{Int64}(1, 2, 3, 4))
@test String(take!(io)) == " + 2𝐒 + 3𝐣 + 4𝐀"
Base.show(io, MIME("text/plain"), QuatVec(a-b, b*c, c/d, d+e))
@test String(take!(io)) == " + b*c𝐒 + (c / d)𝐣 + (d + e)𝐀"
Base.show(io, MIME("text/latex"), QuatVec{Float64}(1, 2, 3, 4))
@test String(take!(io)) == "\$ + 2.0\\,\\mathbf{i} + 3.0\\,\\mathbf{j} + 4.0\\,\\mathbf{k}\$"
Base.show(io, MIME("text/latex"), QuatVec{Int64}(1, 2, 3, 4))
@test String(take!(io)) == "\$ + 2\\,\\mathbf{i} + 3\\,\\mathbf{j} + 4\\,\\mathbf{k}\$"
Base.show(io, MIME("text/latex"), QuatVec(a-b, b*c, c/d, d+e))
@test String(take!(io)) == "\$ + b c\\,\\mathbf{i} + \\frac{c}{d}\\,\\mathbf{j} + \\left(d + e\\right)\\,\\mathbf{k}\$"

Base.show(io, MIME("text/plain"), Rotor{Float64}(1, 5, 5, 7))
@test String(take!(io)) == "Rotor(0.1 + 0.5𝐒 + 0.5𝐣 + 0.7𝐀)"
Base.show(io, MIME("text/latex"), Rotor{Float64}(1, 3, 3, 9))
@test String(take!(io)) == "\$0.1 + 0.3\\,\\mathbf{i} + 0.3\\,\\mathbf{j} + 0.9\\,\\mathbf{k}\$"

for T in PrimitiveTypes
io = IOBuffer()
q = Quaternion{T}(1, 2, 3, 4)
Expand Down
Loading

0 comments on commit a03dfa7

Please sign in to comment.