Code

option to add endpoints on x-axis (Bug 628266)
authorAlvin Penner <penner@vaxxine.com>
Thu, 16 Sep 2010 00:27:36 +0000 (20:27 -0400)
committerAlvin Penner <penner@vaxxine.com>
Thu, 16 Sep 2010 00:27:36 +0000 (20:27 -0400)
share/extensions/funcplot.inx
share/extensions/funcplot.py

index 3867cab8265860c683df4e97f13be46d63b4d696..8eaf33f011289126b6e518f38c6e5694d03ff165 100644 (file)
@@ -1,33 +1,33 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
-    <_name>Function Plotter</_name>
-    <id>org.inkscape.effect.funcplot</id>
-    <dependency type="executable" location="extensions">funcplot.py</dependency>
-    <dependency type="executable" location="extensions">inkex.py</dependency>
-    <param name="tab" type="notebook">
-        <page name="sampling" _gui-text="Range and sampling">
-            <param name="xstart" type="float" min="-1000.0" max="1000.0" _gui-text="Start X value:">0.0</param>
-            <param name="xend" type="float" min="-1000.0" max="1000.0" _gui-text="End X value:">1.0</param>
-            <param name="times2pi" type="boolean" _gui-text="Multiply X range by 2*pi">false</param>
-            <param name="ybottom" type="float" min="-1000.0" max="1000.0" _gui-text="Y value of rectangle's bottom:">0.0</param>
-            <param name="ytop" type="float" min="-1000.0" max="1000.0" _gui-text="Y value of rectangle's top:">1.0</param>
-            <param name="samples" type="int" min="2" max="1000" _gui-text="Number of samples:">8</param>
-            <param name="isoscale" type="boolean" _gui-text="Isotropic scaling">false</param>
-            <_param name="isoscaledesc" type="description">When set, Isotropic scaling uses smallest of width/xrange or height/yrange</_param>
-            <param name="polar" type="boolean" _gui-text="Use polar coordinates">true</param>
-        </page>
-        <page name="use" _gui-text="Use">
-            <_param name="funcplotuse" type="description" xml:space="preserve">Select a rectangle before calling the extension,
-it will determine X and Y scales.
+       <_name>Function Plotter</_name>
+       <id>org.inkscape.effect.funcplot</id>
+       <dependency type="executable" location="extensions">funcplot.py</dependency>
+       <dependency type="executable" location="extensions">inkex.py</dependency>
+       <param name="tab" type="notebook">
+               <page name="sampling" _gui-text="Range and sampling">
+                       <param name="xstart" type="float" min="-1000.0" max="1000.0" _gui-text="Start X value:">0.0</param>
+                       <param name="xend" type="float" min="-1000.0" max="1000.0" _gui-text="End X value:">1.0</param>
+                       <param name="times2pi" type="boolean" _gui-text="Multiply X range by 2*pi">false</param>
+                       <param name="ybottom" type="float" min="-1000.0" max="1000.0" _gui-text="Y value of rectangle's bottom:">0.0</param>
+                       <param name="ytop" type="float" min="-1000.0" max="1000.0" _gui-text="Y value of rectangle's top:">1.0</param>
+                       <param name="samples" type="int" min="2" max="1000" _gui-text="Number of samples:">8</param>
+                       <param name="isoscale" type="boolean" _gui-text="Isotropic scaling">false</param>
+                       <_param name="isoscaledesc" type="description">When set, Isotropic scaling uses smallest of width/xrange or height/yrange</_param>
+                       <param name="polar" type="boolean" _gui-text="Use polar coordinates">true</param>
+               </page>
+               <page name="use" _gui-text="Use">
+                       <_param name="funcplotuse" type="description" xml:space="preserve">Select a rectangle before calling the extension,
+it will determine X and Y scales. If you wish to fill the area, then add x-axis endpoints.
 
 With polar coordinates:
    Start and end X values define the angle range in radians.
    X scale is set so that left and right edges of rectangle are at +/-1.
    Isotropic scaling is disabled.
    First derivative is always determined numerically.</_param>
-        </page>
-        <page name="desc" _gui-text="Functions">
-            <_param name="pythonfunctions" type="description" xml:space="preserve">Standard Python math functions are available:
+               </page>
+               <page name="desc" _gui-text="Functions">
+                       <_param name="pythonfunctions" type="description" xml:space="preserve">Standard Python math functions are available:
 
 ceil(x); fabs(x); floor(x); fmod(x,y); frexp(x); ldexp(x,i); 
 modf(x); exp(x); log(x [, base]); log10(x); pow(x,y); sqrt(x); 
@@ -36,20 +36,21 @@ cos(x); sin(x); tan(x); degrees(x); radians(x);
 cosh(x); sinh(x); tanh(x).
 
 The constants pi and e are also available.</_param>
-        </page>
-    </param>
-    <param name="fofx" type="string" _gui-text="Function:">exp(-x*x)</param>
-    <param name="fponum" type="boolean" _gui-text="Calculate first derivative numerically">true</param>
-    <param name="fpofx" type="string" _gui-text="First derivative:">x</param>
-    <param name="remove" type="boolean" _gui-text="Remove rectangle">true</param>
-    <param name="drawaxis" type="boolean" _gui-text="Draw Axes">false</param>
-    <effect>
-        <object-type>rect</object-type>
-        <effects-menu>
-            <submenu _name="Render"/>
-        </effects-menu>
-    </effect>
-    <script>
-        <command reldir="extensions" interpreter="python">funcplot.py</command>
-    </script>
+               </page>
+       </param>
+       <param name="fofx" type="string" _gui-text="Function:">exp(-x*x)</param>
+       <param name="fponum" type="boolean" _gui-text="Calculate first derivative numerically">true</param>
+       <param name="fpofx" type="string" _gui-text="First derivative:">x</param>
+       <param name="remove" type="boolean" _gui-text="Remove rectangle">true</param>
+       <param name="drawaxis" type="boolean" _gui-text="Draw Axes">false</param>
+       <param name="endpts" type="boolean" _gui-text="Add x-axis endpoints">false</param>
+       <effect>
+               <object-type>rect</object-type>
+               <effects-menu>
+                       <submenu _name="Render"/>
+               </effects-menu>
+       </effect>
+       <script>
+               <command reldir="extensions" interpreter="python">funcplot.py</command>
+       </script>
 </inkscape-extension>
index 1264298532fd574fc81c57776e700803449a61ea..b94fda278707c4ed5672bd3b94e1d2b281aead18 100644 (file)
@@ -30,7 +30,7 @@ from math import *
 from random import *
 
 def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bottom, 
-    fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, polar = False, isoscale = True, drawaxis = True):
+    fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, polar = False, isoscale = True, drawaxis = True, endpts = False):
 
     if times2pi == True:
         xstart = 2 * pi * xstart
@@ -122,7 +122,11 @@ def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bott
         dy0 = fp(xstart)
 
     # Start curve
-    a.append([' M ',[coordx(x0), coordy(y0)]]) # initial moveto
+    if endpts:
+        a.append([' M ',[left, coordy(0)]])
+        a.append([' L ',[coordx(x0), coordy(y0)]])
+    else:
+        a.append([' M ',[coordx(x0), coordy(y0)]]) # initial moveto
 
     for i in range(int(samples-1)):
         x1 = (i+1) * step + xstart
@@ -153,7 +157,9 @@ def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bott
         x0  = x1  # Next segment's start is this segments end
         y0  = y1
         dx0 = dx1 # Assume the function is smooth everywhere, so carry over the derivative too
-        dy0 = dy1    
+        dy0 = dy1
+    if endpts:
+        a.append([' L ',[left + width, coordy(0)]])
     return a
 
 class FuncPlot(inkex.Effect):
@@ -211,6 +217,10 @@ class FuncPlot(inkex.Effect):
                         action="store", type="inkbool", 
                         dest="drawaxis", default=True,
                         help="If True, axis are drawn") 
+        self.OptionParser.add_option("--endpts",
+                        action="store", type="inkbool",
+                        dest="endpts", default=False,
+                        help="If True, end points are added")
         self.OptionParser.add_option("--tab",
                         action="store", type="string", 
                         dest="tab", default="sampling",
@@ -257,7 +267,8 @@ class FuncPlot(inkex.Effect):
                                 self.options.times2pi,
                                 self.options.polar,
                                 self.options.isoscale,
-                                self.options.drawaxis)))
+                                self.options.drawaxis,
+                                self.options.endpts)))
                 newpath.set('title', self.options.fofx)
                 
                 #newpath.setAttribute('desc', '!func;' + self.options.fofx + ';'