From 8ba9d4ae100be129b255230790149f488032fa3c Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Fri, 07 Mar 2014 19:44:11 +0000 Subject: elements cleanup --- (limited to 'elements/tools.py') diff --git a/elements/tools.py b/elements/tools.py index 9851ff8..3c81eb2 100644 --- a/elements/tools.py +++ b/elements/tools.py @@ -8,7 +8,7 @@ Home: http://elements.linuxuser.at IRC: #elements on irc.freenode.org Code: http://www.assembla.com/wiki/show/elements - svn co http://svn2.assembla.com/svn/elements + svn co http://svn2.assembla.com/svn/elements License: GPLv3 | See LICENSE for the full text This program is free software: you can redistribute it and/or modify @@ -22,19 +22,24 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with this program. If not, see . +along with this program. If not, see . """ # Some Hex Tools + + def hex2dec(hex): """ Convert and hex value in a decimal number - """ + """ return int(hex, 16) -def hex2rgb(hex): + +def hex2rgb(hex): """ Convert a hex color (#123abc) in RGB ((r), (g), (b)) """ - if hex[0:1] == '#': hex = hex[1:]; - return (hex2dec(hex[:2]), hex2dec(hex[2:4]), hex2dec(hex[4:6])) + if hex[0: 1] == '#': + hex = hex[1:] + return (hex2dec(hex[:2]), hex2dec(hex[2: 4]), hex2dec(hex[4: 6])) + def rgb2floats(rgb): """Convert a color in the RGB (0..255,0..255,0..255) format to the @@ -45,21 +50,21 @@ def rgb2floats(rgb): ret.append(float(c) / 255) return ret + def point_in_poly(point, poly): #print ">", point, poly x, y = point n = len(poly) inside = False - p1x,p1y = poly[0] - for i in range(n+1): - p2x,p2y = poly[i % n] - if y > min(p1y,p2y): - if y <= max(p1y,p2y): - if x <= max(p1x,p2x): + p1x, p1y = poly[0] + for i in range(n + 1): + p2x, p2y = poly[i % n] + if y > min(p1y, p2y): + if y <= max(p1y, p2y): + if x <= max(p1x, p2x): if p1y != p2y: - xinters = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x + xinters = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x if p1x == p2x or x <= xinters: inside = not inside - p1x,p1y = p2x,p2y + p1x, p1y = p2x, p2y return inside - \ No newline at end of file -- cgit v0.9.1