1
# tangent.rb: code for drawing tangents
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# General Public License for more details (in the COPYING file).
15
require 'ctioga2/graphics/elements/primitive'
17
# This module contains all the classes used by ctioga
20
Version::register_svn_info('$Revision: 171 $', '$Date: 2010-10-22 17:07:52 +0200 (Fri, 22 Oct 2010) $')
36
}.update(TiogaPrimitiveCall::ArrowOptions)
39
primitive("tangent", "tangent", [ 'data-point'],
40
TangentOptions) do |t, point,options|
42
nb = options['nbavg'] || 7
45
slope = point.slope(nb)
47
# Now, we parse the head/tail spec.
48
if d = options['xextent']
49
options['tail'] = [x, y]
50
options['head'] = [x+d, y + d*slope]
51
elsif d = options['yextent']
52
options['tail'] = [x, y]
53
options['head'] = [x+d/slope, y + d]
54
elsif options['xfrom'] || options['yfrom'] ||
55
options['xto'] || options['yto']
56
if xf = options['xfrom']
57
options['tail'] = [xf, y - (x - xf)*slope]
58
elsif yf = options['yfrom']
59
options['tail'] = [x - (y-yf)/slope, yf]
61
options['tail'] = [x,y]
64
if xt = options['xto']
65
options['head'] = [xt, y - (x - xt)*slope]
66
elsif yt = options['yto']
67
options['head'] = [x - (y-yt)/slope, yt]
69
options['head'] = [x,y]
72
# We don't bother too much about the head/tail
73
options['head'] = [x, y]
74
dx = point.dx(nb) * 10
75
options['tail'] = [x-dx, y - dx*slope]
76
options['line_width'] = 0
77
options['tail_marker'] = "None"
80
# We look for any color argument:
81
if ! (options['color'] || options['tail_color'] ||
82
options['head_color'])
83
options['color'] = $last_curve_style.line.color
86
# Now, we delete elements from the hash that don't have
87
# anything to do there:
88
for k in TangentOptions.keys -
89
TiogaPrimitiveCall::ArrowOptions.keys