gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx/libpaper colors.py


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx/libpaper colors.py
Date: Wed, 25 Sep 2002 10:00:20 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/09/25 10:00:19

Modified files:
        gfx/libpaper   : colors.py 

Log message:
        Print the area of the convex hull of the (A,B) coordinates of colors

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libpaper/colors.py.diff?tr1=1.8&tr2=1.9&r1=text&r2=text

Patches:
Index: gzz/gfx/libpaper/colors.py
diff -c gzz/gfx/libpaper/colors.py:1.8 gzz/gfx/libpaper/colors.py:1.9
*** gzz/gfx/libpaper/colors.py:1.8      Wed Sep 25 08:33:54 2002
--- gzz/gfx/libpaper/colors.py  Wed Sep 25 10:00:19 2002
***************
*** 22,28 ****
                      for i in range(0,4) ]
              if 120 - self._AB_angle(col) > 90 * rnd.nextFloat(): break
              #if self._AB_angle(col) < 180: break
!         print self._AB_angle(col)
  
          while 0:
            col = [
--- 22,28 ----
                      for i in range(0,4) ]
              if 120 - self._AB_angle(col) > 90 * rnd.nextFloat(): break
              #if self._AB_angle(col) < 180: break
!         print "ANGLE=", self._AB_angle(col), "AREA=", self._AB_area(col)*100
  
          while 0:
            col = [
***************
*** 86,90 ****
  
          return reduce(lambda x,y: x+y, dots) / len(dots)
      
!     def _AB_area(seld, cols):
!         pass
--- 86,127 ----
  
          return reduce(lambda x,y: x+y, dots) / len(dots)
      
!     def _AB_area(self, cols):
!         ab = [ (lab[1]/100.0,lab[2]/100.0) for lab in map(RGBtoLAB, cols) ]
!         #print [ (int(100*a),int(100*b)) for (a,b) in ab ]
!         ab = convex_hull(ab)
!         #print [ (int(100*a),int(100*b)) for (a,b) in ab ]
!         return polygon_area(ab)
! 
! def polygon_area(pts):
!     A = 0
!     for i in range(0, len(pts)):
!         A += pts[i-1][0] * pts[i][1] - pts[i][0] * pts[i-1][1]
!     return A
! 
! def convex_hull(pts):
!     if len(pts) < 2: return pts
!     pts.sort()
!     
!     #print "P=", [ (int(100*a),int(100*b)) for (a,b) in pts ]
! 
!     def dir(p,q,r):
!         """Return positive if p,q,r turns cw, neg if ccw, zero if linear."""
!         return (q[1]-p[1])*(r[0]-p[0]) - (q[0]-p[0])*(r[1]-p[1])
! 
! 
!     U = pts[0:2]
!     L = pts[0:2]
! 
!     for p in pts[2:]:
!         while len(U) > 1 and dir(U[-2], U[-1], p) <= 0: U.pop()
!         while len(L) > 1 and dir(L[-2], L[-1], p) >= 0: L.pop()
!         U.append(p)
!         L.append(p)
! 
!     #print "L=", [ (int(100*a),int(100*b)) for (a,b) in L ]
!     #print "U=", [ (int(100*a),int(100*b)) for (a,b) in U ]
! 
!     U.reverse()
!     return U + L[1:-1]
! 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]