Ticket #13191: trac_13191_reviewer.patch

File trac_13191_reviewer.patch, 1.9 KB (added by novoselt, 10 years ago)
  • sage/geometry/fan.py

    # HG changeset patch
    # User Andrey Novoseltsev <novoselt@gmail.com>
    # Date 1341766571 21600
    # Node ID 47834f92296d920484962f45b00d3ccc90d80a22
    # Parent  1a8071ec224bb3f478ce3cc78e09474f531a8137
    Reviewer adjustments to Fan2d.
    
    diff --git a/sage/geometry/fan.py b/sage/geometry/fan.py
    a b  
    794794    """
    795795    if len(rays) == 0:
    796796        if lattice is None or lattice.dimension() != 2:
    797             raise ValueError('you must specify a 2-dimensional lattice when you construct a fan without rays.')
     797            raise ValueError('you must specify a 2-dimensional lattice when '
     798                             'you construct a fan without rays.')
    798799        return RationalPolyhedralFan(cones=((), ), rays=(), lattice=lattice)
    799800
    800801    # remove multiple rays without changing order
     
    809810    lattice = rays[0].parent()
    810811    if lattice.dimension() != 2:
    811812        raise ValueError('the lattice must be 2-dimensional.')
    812          
     813    n = len(rays)
     814    if n == 1 or n == 2 and rays[0] == -rays[1]:
     815        cones = [(i, ) for i in range(n)]
     816        return RationalPolyhedralFan(cones, rays, lattice, False)
     817
    813818    import math
    814819    # each sorted_rays entry = (angle, ray, original_ray_index)
    815820    sorted_rays = sorted( (math.atan2(r[0],r[1]), r, i) for i,r in enumerate(rays) )
    816     sorted_rays = [ r for i,r in enumerate(sorted_rays) if r[1] != sorted_rays[i-1][1] ]
    817821    cones = []
    818822    is_complete = True
    819     for i in range(len(sorted_rays)):
     823    for i in range(n):
    820824        r0 = sorted_rays[i-1][1]
    821825        r1 = sorted_rays[i][1]
    822826        if r1.is_zero():
     
    829833            cones.append((sorted_rays[r0_index][2], sorted_rays[r1_index][2]))
    830834        else:
    831835            is_complete = False
    832     if cones == []:
    833         cones = [ (i,) for i in range(len(rays)) ]
    834         is_complete = False
    835836    return RationalPolyhedralFan(cones, rays, lattice, is_complete)
    836837
    837838