diff --git a/docs/src/PolyhedralGeometry/intro.md b/docs/src/PolyhedralGeometry/intro.md index f185306a969b..f393093a77b3 100644 --- a/docs/src/PolyhedralGeometry/intro.md +++ b/docs/src/PolyhedralGeometry/intro.md @@ -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} ``` diff --git a/src/PolyhedralGeometry/visualization.jl b/src/PolyhedralGeometry/visualization.jl index e27999a9c580..54b38f0874e4 100644 --- a/src/PolyhedralGeometry/visualization.jl +++ b/src/PolyhedralGeometry/visualization.jl @@ -1,5 +1,5 @@ @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. @@ -7,20 +7,33 @@ Four-dimensional polytopes are visualized as a Schlegel diagram, which is a proj 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