|
291 | 291 | # https://www.gnu.org/licenses/
|
292 | 292 | ########################################################################
|
293 | 293 |
|
| 294 | +import sage.geometry.abc |
| 295 | + |
294 | 296 | from sage.rings.integer_ring import ZZ
|
295 | 297 | from sage.rings.real_double import RDF
|
296 | 298 | from sage.rings.real_mpfr import RR
|
@@ -470,6 +472,13 @@ def Polyhedron(vertices=None, rays=None, lines=None,
|
470 | 472 | ...
|
471 | 473 | ValueError: invalid base ring
|
472 | 474 |
|
| 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 | +
|
473 | 482 | Converting from other objects to a polyhedron::
|
474 | 483 |
|
475 | 484 | sage: quadrant = Cone([(1,0), (0,1)])
|
@@ -612,20 +621,34 @@ def Polyhedron(vertices=None, rays=None, lines=None,
|
612 | 621 | """
|
613 | 622 | # Special handling for first argument, for coercion-like uses
|
614 | 623 | constructor = None
|
| 624 | + first_arg = vertices |
| 625 | + if isinstance(first_arg, sage.geometry.abc.Polyhedron): |
| 626 | + constructor = first_arg.change_ring |
615 | 627 | try:
|
616 | 628 | # PolyhedronFace.as_polyhedron (it also has a "polyhedron" method with a different purpose)
|
617 |
| - constructor = vertices.as_polyhedron |
| 629 | + constructor = first_arg.as_polyhedron |
618 | 630 | except AttributeError:
|
619 | 631 | try:
|
620 | 632 | # ConvexRationalPolyhedralCone, LatticePolytopeClass, MixedIntegerLinearProgram, Hyperplane
|
621 |
| - constructor = vertices.polyhedron |
| 633 | + constructor = first_arg.polyhedron |
622 | 634 | except AttributeError:
|
623 | 635 | pass
|
624 | 636 | if constructor:
|
625 | 637 | if not all(x is None for x in (rays, lines, ieqs, eqns, ambient_dim)):
|
626 | 638 | 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) |
629 | 652 |
|
630 | 653 | got_Vrep = not ((vertices is None) and (rays is None) and (lines is None))
|
631 | 654 | got_Hrep = not ((ieqs is None) and (eqns is None))
|
|
0 commit comments