Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 0f83724

Browse files
author
Matthias Koeppe
committed
Polyhedron: Allow converting from a given polyhedron
1 parent 8b3cd6a commit 0f83724

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/sage/geometry/polyhedron/constructor.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@
291291
# https://www.gnu.org/licenses/
292292
########################################################################
293293

294+
import sage.geometry.abc
295+
294296
from sage.rings.integer_ring import ZZ
295297
from sage.rings.real_double import RDF
296298
from sage.rings.real_mpfr import RR
@@ -470,6 +472,13 @@ def Polyhedron(vertices=None, rays=None, lines=None,
470472
...
471473
ValueError: invalid base ring
472474
475+
Converting from a given polyhedron::
476+
477+
sage: cb = polytopes.cube(); cb
478+
A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices
479+
sage: Polyhedron(cb, base_ring=QQ)
480+
A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 8 vertices
481+
473482
Converting from other objects to a polyhedron::
474483
475484
sage: quadrant = Cone([(1,0), (0,1)])
@@ -612,20 +621,34 @@ def Polyhedron(vertices=None, rays=None, lines=None,
612621
"""
613622
# Special handling for first argument, for coercion-like uses
614623
constructor = None
624+
first_arg = vertices
625+
if isinstance(first_arg, sage.geometry.abc.Polyhedron):
626+
constructor = first_arg.change_ring
615627
try:
616628
# PolyhedronFace.as_polyhedron (it also has a "polyhedron" method with a different purpose)
617-
constructor = vertices.as_polyhedron
629+
constructor = first_arg.as_polyhedron
618630
except AttributeError:
619631
try:
620632
# ConvexRationalPolyhedralCone, LatticePolytopeClass, MixedIntegerLinearProgram, Hyperplane
621-
constructor = vertices.polyhedron
633+
constructor = first_arg.polyhedron
622634
except AttributeError:
623635
pass
624636
if constructor:
625637
if not all(x is None for x in (rays, lines, ieqs, eqns, ambient_dim)):
626638
raise ValueError('if a polyhedron is given, cannot provide H- and V-representations objects')
627-
return constructor(base_ring=base_ring, minimize=minimize,
628-
verbose=verbose, backend=backend, mutable=False)
639+
# Only pass non-default arguments
640+
kwds = {}
641+
if base_ring is not None:
642+
kwds['base_ring'] = base_ring
643+
if verbose is not False:
644+
kwds['verbose'] = verbose
645+
if backend is not None:
646+
kwds['backend'] = backend
647+
if minimize is not True:
648+
kwds['minimize'] = minimize
649+
if mutable is not False:
650+
kwds['mutable'] = mutable
651+
return constructor(**kwds)
629652

630653
got_Vrep = not ((vertices is None) and (rays is None) and (lines is None))
631654
got_Hrep = not ((ieqs is None) and (eqns is None))

0 commit comments

Comments
 (0)