[Rdkit-devel] [PATCH 09/17] Move _getLinePoints() to CanvasBase
Open-Source Cheminformatics and Machine Learning
Brought to you by:
glandrum
|
From: Gianluca S. <gi...@gm...> - 2011-03-19 09:44:39
|
---
rdkit/Chem/Draw/aggCanvas.py | 24 ------------------------
rdkit/Chem/Draw/cairoCanvas.py | 24 ------------------------
rdkit/Chem/Draw/canvasbase.py | 24 ++++++++++++++++++++++++
rdkit/Chem/Draw/spingCanvas.py | 24 ------------------------
4 files changed, 24 insertions(+), 72 deletions(-)
diff --git a/rdkit/Chem/Draw/aggCanvas.py b/rdkit/Chem/Draw/aggCanvas.py
index dc18451..9d41858 100644
--- a/rdkit/Chem/Draw/aggCanvas.py
+++ b/rdkit/Chem/Draw/aggCanvas.py
@@ -31,30 +31,6 @@ class Canvas(CanvasBase):
self.image.setantialias(True)
self.size = self.image.size
- def _getLinePoints(self, p1, p2, dash):
- x1,y1=p1
- x2,y2=p2
- dx = x2-x1
- dy = y2-y1
- lineLen = math.sqrt(dx*dx+dy*dy)
- theta = math.atan2(dy,dx)
- cosT = math.cos(theta)
- sinT = math.sin(theta)
-
- pos = (x1,y1)
- pts = [pos]
- dist = 0
- currDash = 0
- while dist < lineLen:
- currL = dash[currDash%len(dash)]
- if(dist+currL > lineLen): currL = lineLen-dist
- endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
- pts.append(endP)
- pos = endP
- dist += currL
- currDash += 1
- return pts
-
def _doLine(self, p1, p2, pen, **kwargs):
if kwargs.get('dashes',(0,0)) == (0,0):
self.image.line((p1[0],p1[1],p2[0],p2[1]),pen)
diff --git a/rdkit/Chem/Draw/cairoCanvas.py b/rdkit/Chem/Draw/cairoCanvas.py
index 3c688a3..0e23e6f 100644
--- a/rdkit/Chem/Draw/cairoCanvas.py
+++ b/rdkit/Chem/Draw/cairoCanvas.py
@@ -96,30 +96,6 @@ class Canvas(CanvasBase):
return buffer
- def _getLinePoints(self, p1, p2, dash):
- x1,y1 = p1
- x2,y2 = p2
- dx = x2-x1
- dy = y2-y1
- lineLen = math.sqrt(dx*dx+dy*dy)
- theta = math.atan2(dy,dx)
- cosT = math.cos(theta)
- sinT = math.sin(theta)
-
- pos = (x1,y1)
- pts = [pos]
- dist = 0
- currDash = 0
- while dist < lineLen:
- currL = dash[currDash%len(dash)]
- if(dist+currL > lineLen): currL = lineLen-dist
- endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
- pts.append(endP)
- pos = endP
- dist += currL
- currDash += 1
- return pts
-
def _doLine(self, p1, p2, **kwargs):
if kwargs.get('dashes',(0,0)) == (0,0):
self.ctx.move_to(p1[0],p1[1])
diff --git a/rdkit/Chem/Draw/canvasbase.py b/rdkit/Chem/Draw/canvasbase.py
index 0a5801e..548c256 100644
--- a/rdkit/Chem/Draw/canvasbase.py
+++ b/rdkit/Chem/Draw/canvasbase.py
@@ -57,3 +57,27 @@ class CanvasBase:
saving it
"""
assert False, 'This should be implemented'
+
+ def _getLinePoints(self, p1, p2, dash):
+ x1, y1 = p1
+ x2, y2 = p2
+ dx = x2 - x1
+ dy = y2 - y1
+ lineLen = math.sqrt(dx * dx + dy * dy)
+ theta = math.atan2(dy, dx)
+ cosT = math.cos(theta)
+ sinT = math.sin(theta)
+
+ pos = (x1, y1)
+ pts = [pos]
+ dist = 0
+ currDash = 0
+ while dist < lineLen:
+ currL = dash[currDash % len(dash)]
+ if (dist + currL > lineLen): currL = lineLen - dist
+ endP = (pos[0] + currL * cosT, pos[1] + currL * sinT)
+ pts.append(endP)
+ pos = endP
+ dist += currL
+ currDash += 1
+ return pts
diff --git a/rdkit/Chem/Draw/spingCanvas.py b/rdkit/Chem/Draw/spingCanvas.py
index 98bbe3d..e656fd8 100644
--- a/rdkit/Chem/Draw/spingCanvas.py
+++ b/rdkit/Chem/Draw/spingCanvas.py
@@ -21,30 +21,6 @@ def convertColor(color):
color = pid.Color(color[0],color[1],color[2])
return color
-def _getLinePoints(p1,p2,dash):
- x1,y1=p1
- x2,y2=p2
- dx = x2-x1
- dy = y2-y1
- lineLen = math.sqrt(dx*dx+dy*dy)
- theta = math.atan2(dy,dx)
- cosT = math.cos(theta)
- sinT = math.sin(theta)
-
- pos = (x1,y1)
- pts = [pos]
- dist = 0
- currDash = 0
- while dist < lineLen:
- currL = dash[currDash%len(dash)]
- if(dist+currL > lineLen): currL = lineLen-dist
- endP = (pos[0] + currL*cosT, pos[1] + currL*sinT)
- pts.append(endP)
- pos = endP
- dist += currL
- currDash += 1
- return pts
-
class Canvas(CanvasBase):
--
1.7.4
|