Skip to content

Commit

Permalink
MakieExt (#163)
Browse files Browse the repository at this point in the history
* MakieExt

* Support plot

* Add disk/circle plotting

* Add 3D plots and fix plotting

* start tests and Point support

* Update tests

* Update test_makieext.jl

* Update DomainSetsMakieExt.jl

* v0.7.13
  • Loading branch information
dlfivefifty authored Apr 29, 2024
1 parent 1cbe675 commit 4e36278
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.jl.mem
Manifest.toml
/docs/build/
.DS_Store
12 changes: 10 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DomainSets"
uuid = "5b8099bc-c8ec-5219-889f-1d9e522a28bf"
version = "0.7.12"
version = "0.7.13"

[deps]
CompositeTypes = "b152e2b5-7a66-4b01-a709-34e65c35f657"
Expand All @@ -9,11 +9,18 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
DomainSetsMakieExt = "Makie"

[compat]
Aqua = "0.8"
CompositeTypes = "0.1.4"
IntervalSets = "0.7.4"
LinearAlgebra = "1"
Makie = "0.19, 0.20"
Random = "1"
StableRNGs = "1"
StaticArrays = "1"
Expand All @@ -22,8 +29,9 @@ julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Aqua", "StableRNGs"]
test = ["Test", "Aqua", "Makie", "StableRNGs"]
25 changes: 25 additions & 0 deletions examples/domainplotting.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using DomainSets, StaticArrays
using CairoMakie: plot, plot!
using DomainSets: Sphere


##
# 2D
##
p = plot((0..1) × (1..2))
plot!(UnitDisk())
plot!(Sphere(2.0, SVector(1.0, 0.5)))
plot!(Sphere(3.0, [1.0, 0.5]))
plot!(Point(SVector(2,3)))
p



##
# 3D
##
p = plot((0..1) × (1..2) × (3..4))
plot!(UnitBall())
plot!(Sphere(2.0, SVector(1.0, 0.5,0.5)))
plot!(Sphere(3.0, [1.0, 0.5,0.5]))
p
37 changes: 37 additions & 0 deletions ext/DomainSetsMakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module DomainSetsMakieExt
using DomainSets
using DomainSets.StaticArrays
import Makie
using DomainSets: leftendpoint, rightendpoint, Rectangle, HyperRectangle, Point, DomainPoint, pointval, point
import Makie: Point2f, Rect, Circle, Poly, Lines, convert_arguments, HyperSphere, Vec, Scatter, PointBased
import Base: convert

function convert(::Type{Makie.HyperRectangle}, r::Rectangle{<:SVector{N}}) where N
l = leftendpoint(r)
r = rightendpoint(r)
Rect(convert(Vec{N}, l), convert(Vec{N}, r .- l))
end

convert(::Type{<:HyperSphere}, r::Union{Sphere{SVector{N,T}},Ball{SVector{N,T}}}) where {N,T} = HyperSphere{N,T}(Point(center(r)), radius(r))

function convert(::Type{<:HyperSphere}, r::Union{Sphere{<:AbstractVector{T}}, Ball{<:AbstractVector{T}}}) where T
N = length(center(r))
HyperSphere{N,T}(Makie.Point{N}(center(r)), radius(r))
end

convert(::Type{<:Makie.Point}, r::Point) = Makie.Point(pointval(r))
convert(::Type{<:Makie.Point}, r::DomainPoint) = convert(Makie.Point, point(r))

convert_arguments(::Type{Plt}, r::HyperRectangle; kwds...) where Plt <: Poly = convert_arguments(Plt, convert(Makie.HyperRectangle, r); kwds...)
convert_arguments(::Type{Plt}, r::Ball; kwds...) where Plt <: Poly = convert_arguments(Plt, convert(HyperSphere, r); kwds...)
convert_arguments(::Type{Plt}, r::Sphere; kwds...) where Plt <: Lines = convert_arguments(Plt, convert(HyperSphere, r); kwds...)
convert_arguments(::Type{Plt}, r::Point; kwds...) where Plt <: Scatter = convert_arguments(Plt, convert(Makie.Point, r); kwds...)



Makie.plottype(a::HyperRectangle) = Poly
Makie.plottype(a::Sphere) = Lines
Makie.plottype(a::Ball) = Poly
Makie.plottype(a::Union{DomainPoint,Point}) = Scatter

end # module
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ include("test_setoperations.jl")
include("test_interface.jl")
include("test_applications.jl")
include("test_readme.jl")

if isdefined(Base, :get_extension)
println("#############################")
println("# Tests of extensions")
println("#############################")

include("test_makieext.jl")
end
24 changes: 24 additions & 0 deletions test/test_makieext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module DomainSetsMakieTests
using DomainSets, StaticArrays, Test
import Makie
import Makie: plot, Poly, Lines, Scatter
using DomainSets: Sphere, ×

@testset "Plotting" begin
@testset "2D" begin
@test plot((0..1) × (1..2)).plot isa Poly
@test plot(UnitCircle()).plot isa Lines
@test plot(UnitDisk()).plot isa Poly
@test plot(Sphere(2.0, SVector(1.0, 0.5))).plot isa Lines
@test plot(Sphere(3.0, [1.0, 0.5])).plot isa Lines
@test plot(Point(SVector(0.1,0.2))).plot isa Scatter
end

@testset "3D" begin
@test plot((0..1) × (1..2) × (3..4)).plot isa Poly
@test plot(UnitBall()).plot isa Poly
@test plot(Sphere(2.0, SVector(1.0, 0.5,0.5))).plot isa Lines
@test plot(Sphere(3.0, [1.0, 0.5,0.5])).plot isa Lines
end
end
end # module

2 comments on commit 4e36278

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105849

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.13 -m "<description of version>" 4e36278622df67839cea860a5d0f958c849db988
git push origin v0.7.13

Please sign in to comment.