Skip to content

Commit

Permalink
PolyhedralGeometry: restrict signature of visualize, add visualize(Su…
Browse files Browse the repository at this point in the history
…bdivisionOfPoints) (#2863)

Co-authored-by: Lars Göttgens <[email protected]>
  • Loading branch information
2 people authored and fieker committed Sep 29, 2023
1 parent 533c929 commit 82022ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/src/PolyhedralGeometry/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fan for its construction, see [`polyhedral_fan`](@ref).
Lower dimensional polyhedral objects can be visualized through polymake's backend.

```@docs
visualize(P::PolyhedralObject{T}) where T<:Union{QQFieldElem, Float64}
visualize(P::Union{Polyhedron{T}, Cone{T}, PolyhedralFan{T}, PolyhedralComplex{T}}) where T<:Union{QQFieldElem, Float64}
```


Expand Down
39 changes: 26 additions & 13 deletions src/PolyhedralGeometry/visualization.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
@doc raw"""
visualize(P::Union{Polyhedron{T}, Cone{T}, PolyhedralFan{T}, PolyhedralComplex{T}}) where T<:Union{QQFieldElem, Float64}
visualize(P::Union{Polyhedron{T}, Cone{T}, PolyhedralFan{T}, PolyhedralComplex{T}, SubdivisionOfPoints{T}}) where T<:Union{QQFieldElem, Float64}
Visualize a polyhedral object of dimension at most four (in 3-space).
In dimensions up to 3 a usual embedding is shown.
Four-dimensional polytopes are visualized as a Schlegel diagram, which is a projection onto one of the facets; e.g., see Chapter 5 of [Zie95](@cite).
In higher dimensions there is no standard method; use projections to lower dimensions or try ideas from [GJRW10](@cite).
"""
function visualize(P::PolyhedralObject{T}) where T<:Union{QQFieldElem, Float64}
function visualize(P::Union{Polyhedron{T}, Cone{T}, PolyhedralFan{T}, PolyhedralComplex{T}}) where T<:Union{QQFieldElem, Float64}
d = ambient_dim(P)
b = P isa Polyhedron
if d < 4 || (d == 4 && b && dim(P) == 4)
# polymake will by default use 0:n-1 as ray labels so we assign labels
# starting from 1 here if there are no labels yet
# (note: labels are mutable, i.e. they can be changed again later)
if !Polymake.exists(pm_object(P), "RAY_LABELS")
pm_object(P).RAY_LABELS = string.(1:Oscar.pm_object(P).N_RAYS)
end
pmo = pm_object(P)
Polymake.visual(pmo)
if b && d == 4
@req is_fulldimensional(P) "Can only visualize full-dimensional $(typeof(P)) of ambient dimension $d"
else
d == 4 && b && throw(ArgumentError("Can only visualize full-dimensional $(typeof(P)) of ambient dimension $d"))
throw(ArgumentError("Can not visualize $(typeof(P)) of ambient dimension $d. Supported range: 1 <= d <= $(3 + b)"))
@req d < 4 "Can not visualize $(typeof(P)) of ambient dimension $d. Supported range: 1 <= d <= $(3 + b)"
end
# polymake will by default use 0:n-1 as ray labels so we assign labels
# starting from 1 here if there are no labels yet
# (note: labels are mutable, i.e. they can be changed again later)
if !Polymake.exists(pm_object(P), "RAY_LABELS")
pm_object(P).RAY_LABELS = string.(1:Oscar.pm_object(P).N_RAYS)
end
pmo = pm_object(P)
Polymake.visual(pmo)
end

function visualize(P::SubdivisionOfPoints{T}) where T<:Union{QQFieldElem, Float64}
d = ambient_dim(P)
@req d <= 3 "Can not visualize $(typeof(P)) of ambient dimension $d. Supported range: 1 <= d <= 3"
# polymake will by default use 0:n-1 as labels so we assign labels
# starting from 1 here if there are no labels yet
# (note: labels are mutable, i.e. they can be changed again later)
if !Polymake.exists(pm_object(P), "POINT_LABELS")
pm_object(P).POINT_LABELS = string.(1:Oscar.pm_object(P).N_POINTS)
end
pmo = pm_object(P)
Polymake.visual(pmo)
end

0 comments on commit 82022ef

Please sign in to comment.