# 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
|
|
794 | 794 | """ |
795 | 795 | if len(rays) == 0: |
796 | 796 | 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.') |
798 | 799 | return RationalPolyhedralFan(cones=((), ), rays=(), lattice=lattice) |
799 | 800 | |
800 | 801 | # remove multiple rays without changing order |
… |
… |
|
809 | 810 | lattice = rays[0].parent() |
810 | 811 | if lattice.dimension() != 2: |
811 | 812 | 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 | |
813 | 818 | import math |
814 | 819 | # each sorted_rays entry = (angle, ray, original_ray_index) |
815 | 820 | 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] ] |
817 | 821 | cones = [] |
818 | 822 | is_complete = True |
819 | | for i in range(len(sorted_rays)): |
| 823 | for i in range(n): |
820 | 824 | r0 = sorted_rays[i-1][1] |
821 | 825 | r1 = sorted_rays[i][1] |
822 | 826 | if r1.is_zero(): |
… |
… |
|
829 | 833 | cones.append((sorted_rays[r0_index][2], sorted_rays[r1_index][2])) |
830 | 834 | else: |
831 | 835 | is_complete = False |
832 | | if cones == []: |
833 | | cones = [ (i,) for i in range(len(rays)) ] |
834 | | is_complete = False |
835 | 836 | return RationalPolyhedralFan(cones, rays, lattice, is_complete) |
836 | 837 | |
837 | 838 | |