Skip to content

Commit

Permalink
Polyhedron: allow lattice_points for non-rational polytopes
Browse files Browse the repository at this point in the history
  • Loading branch information
benlorenz committed Jul 10, 2024
1 parent 686205b commit 34fc1bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/PolyhedralGeometry/Polyhedron/properties.jl
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ julia> dim(P)
dim(P::Polyhedron) = Polymake.polytope.dim(pm_object(P))::Int

@doc raw"""
lattice_points(P::Polyhedron{QQFieldElem})
lattice_points(P::Polyhedron)
Return the integer points contained in the bounded polyhedron `P`.
Expand All @@ -757,15 +757,15 @@ julia> matrix(ZZ, lattice_points(S))
[2 0]
```
"""
function lattice_points(P::Polyhedron{QQFieldElem})
function lattice_points(P::Polyhedron)
@req pm_object(P).BOUNDED "Polyhedron not bounded"
return SubObjectIterator{PointVector{ZZRingElem}}(
P, _lattice_point, size(pm_object(P).LATTICE_POINTS_GENERATORS[1], 1)
)
end

_lattice_point(
T::Type{PointVector{ZZRingElem}}, P::Polyhedron{QQFieldElem}, i::Base.Integer
T::Type{PointVector{ZZRingElem}}, P::Polyhedron, i::Base.Integer
) = point_vector(ZZ, @view pm_object(P).LATTICE_POINTS_GENERATORS[1][i, 2:end])::T

_point_matrix(::Val{_lattice_point}, P::Polyhedron; homogenized=false) =
Expand All @@ -774,7 +774,7 @@ _point_matrix(::Val{_lattice_point}, P::Polyhedron; homogenized=false) =
_matrix_for_polymake(::Val{_lattice_point}) = _point_matrix

@doc raw"""
interior_lattice_points(P::Polyhedron{QQFieldElem})
interior_lattice_points(P::Polyhedron)
Return the integer points contained in the interior of the bounded polyhedron
`P`.
Expand All @@ -792,15 +792,15 @@ julia> matrix(ZZ, interior_lattice_points(c))
[0 0 0]
```
"""
function interior_lattice_points(P::Polyhedron{QQFieldElem})
function interior_lattice_points(P::Polyhedron)
@req pm_object(P).BOUNDED "Polyhedron not bounded"
return SubObjectIterator{PointVector{ZZRingElem}}(
P, _interior_lattice_point, size(pm_object(P).INTERIOR_LATTICE_POINTS, 1)
)
end

_interior_lattice_point(
T::Type{PointVector{ZZRingElem}}, P::Polyhedron{QQFieldElem}, i::Base.Integer
T::Type{PointVector{ZZRingElem}}, P::Polyhedron, i::Base.Integer
) = point_vector(ZZ, @view pm_object(P).INTERIOR_LATTICE_POINTS[i, 2:end])::T

_point_matrix(::Val{_interior_lattice_point}, P::Polyhedron; homogenized=false) =
Expand All @@ -813,7 +813,7 @@ _point_matrix(::Val{_interior_lattice_point}, P::Polyhedron; homogenized=false)
_matrix_for_polymake(::Val{_interior_lattice_point}) = _point_matrix

@doc raw"""
boundary_lattice_points(P::Polyhedron{QQFieldElem})
boundary_lattice_points(P::Polyhedron)
Return the integer points contained in the boundary of the bounded polyhedron
`P`.
Expand Down Expand Up @@ -841,15 +841,15 @@ julia> matrix(ZZ, boundary_lattice_points(c))
[ 1 0 0]
```
"""
function boundary_lattice_points(P::Polyhedron{QQFieldElem})
function boundary_lattice_points(P::Polyhedron)
@req pm_object(P).BOUNDED "Polyhedron not bounded"
return SubObjectIterator{PointVector{ZZRingElem}}(
P, _boundary_lattice_point, size(pm_object(P).BOUNDARY_LATTICE_POINTS, 1)
)
end

_boundary_lattice_point(
T::Type{PointVector{ZZRingElem}}, P::Polyhedron{QQFieldElem}, i::Base.Integer
T::Type{PointVector{ZZRingElem}}, P::Polyhedron, i::Base.Integer
) = point_vector(ZZ, @view pm_object(P).BOUNDARY_LATTICE_POINTS[i, 2:end])::T

_point_matrix(::Val{_boundary_lattice_point}, P::Polyhedron; homogenized=false) =
Expand Down
2 changes: 1 addition & 1 deletion test/PolyhedralGeometry/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
@test !([-1, -1] in Q0)
@test n_vertices(Q0) == 3
@test n_vertices.(faces(Q0, 1)) == [2, 2, 2]
if T == QQFieldElem
@test lattice_points(Q0) isa SubObjectIterator{PointVector{ZZRingElem}}
@test point_matrix(lattice_points(Q0)) == matrix(ZZ, [0 0; 0 1; 1 0])
@test matrix(ZZ, lattice_points(Q0)) == matrix(ZZ, [0 0; 0 1; 1 0])
Expand All @@ -63,6 +62,7 @@
@test length(boundary_lattice_points(square)) == 8
@test boundary_lattice_points(square) ==
[[-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1]]
if T == QQFieldElem
@test is_smooth(Q0)
@test is_normal(Q0)
@test is_lattice_polytope(Q0)
Expand Down
5 changes: 5 additions & 0 deletions test/PolyhedralGeometry/scalar_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
@test _edge_length_for_test.(faces(sd, 1)) == repeat([4], 18)
# scaling the Polyhedron by 3 yields edge lengths of 6
@test _edge_length_for_test.(faces(3 * sd, 1)) == repeat([36], 18)
# there are 11 lattice points
@test length(lattice_points(sd)) == 11

let pc = polyhedral_complex(
E, IncidenceMatrix(facets(sd)), vertices(sd); non_redundant=true
)
Expand All @@ -62,6 +65,8 @@
@test number_of_vertices(qp) == 3
@test number_of_facets(qp) == 3

@test length(lattice_points(qp)) == 1

@testset "Scalar detection" begin
let j = johnson_solid(12)
@test j isa Polyhedron{QQFieldElem}
Expand Down

0 comments on commit 34fc1bf

Please sign in to comment.