Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/elements/tools.py
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2014-03-07 19:44:11 (GMT)
committer Walter Bender <walter@sugarlabs.org>2014-03-07 19:44:11 (GMT)
commit8ba9d4ae100be129b255230790149f488032fa3c (patch)
tree791c00f957b6a04c8fd32e1c8059ce1e690b8ee7 /elements/tools.py
parent3d36a1c34a7c49f4265bb669aefcacededc94e55 (diff)
elements cleanupgtk3
Diffstat (limited to 'elements/tools.py')
-rw-r--r--elements/tools.py35
1 files changed, 20 insertions, 15 deletions
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 <http://www.gnu.org/licenses/>.
+along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# 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