Skip to content

Commit 113c047

Browse files
committed
Make multipath allow points.
Hmm... It seems a dataset should just be made to allow curve parts, and the multipath should be eliminated.
1 parent bb4eec7 commit 113c047

File tree

4 files changed

+52
-30
lines changed

4 files changed

+52
-30
lines changed

lib/Plots/JSXGraph.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ sub add_multipath {
417417
for (0 .. $#paths) {
418418
my $path = $paths[$_];
419419

420+
if (ref $path eq 'ARRAY') {
421+
$self->{JS} .= "board.create('curve', [[$path->[0]], [$path->[1]]], { visible: false }),\n";
422+
next;
423+
}
424+
420425
($start_x, $start_y) =
421426
(', ' . $path->{Fx}->eval($var => $path->{tmin}), ', ' . $path->{Fy}->eval($var => $path->{tmin}))
422427
if $cycle && $_ == 0;

lib/Plots/Plot.pm

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,17 @@ sub add_multipath {
297297
my $steps = (delete $options{steps}) || 30;
298298
$data->{context} = $self->context;
299299
$data->{paths} = [
300-
map { {
301-
Fx => $data->get_math_object($_->[0], $var),
302-
Fy => $data->get_math_object($_->[1], $var),
303-
tmin => $data->str_to_real($_->[2]),
304-
tmax => $data->str_to_real($_->[3]),
305-
@$_[ 4 .. $#$_ ]
306-
} } @$paths
300+
map {
301+
@$_ == 2
302+
? [@$_]
303+
: {
304+
Fx => $data->get_math_object($_->[0], $var),
305+
Fy => $data->get_math_object($_->[1], $var),
306+
tmin => $data->str_to_real($_->[2]),
307+
tmax => $data->str_to_real($_->[3]),
308+
@$_[ 4 .. $#$_ ]
309+
}
310+
} @$paths
307311
];
308312
$data->{function} = { var => $var, steps => $steps };
309313
$data->style(color => 'default_color', width => 2, mark_size => 2, %options);

lib/Plots/Tikz.pm

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,21 +620,27 @@ sub draw {
620620
for (0 .. $#paths) {
621621
my $path = $paths[$_];
622622

623-
my $xfunction = $data->function_string($path->{Fx}, 'PGF', $var);
624-
my $yfunction = $data->function_string($path->{Fy}, 'PGF', $var);
625-
626623
++$count while $self->{names}{"${curve_name}_$count"};
624+
push(@pathData, ["${curve_name}_$count"]);
625+
$self->{names}{ $pathData[-1][0] } = 1;
626+
627+
if (ref $path eq 'ARRAY') {
628+
$tikzCode .=
629+
"\\addplot[name path=$pathData[-1][0], draw=none] coordinates {($path->[0], $path->[1])};\n";
630+
push(@{ $pathData[-1] }, @$path, @$path);
631+
next;
632+
}
633+
627634
push(
628-
@pathData,
629-
[
630-
"${curve_name}_$count",
631-
$path->{Fx}->eval($var => $path->{tmin}),
632-
$path->{Fy}->eval($var => $path->{tmin}),
633-
$path->{Fx}->eval($var => $path->{tmax}),
634-
$path->{Fy}->eval($var => $path->{tmax})
635-
]
635+
@{ $pathData[-1] },
636+
$path->{Fx}->eval($var => $path->{tmin}),
637+
$path->{Fy}->eval($var => $path->{tmin}),
638+
$path->{Fx}->eval($var => $path->{tmax}),
639+
$path->{Fy}->eval($var => $path->{tmax})
636640
);
637-
$self->{names}{ $pathData[-1][0] } = 1;
641+
642+
my $xfunction = $data->function_string($path->{Fx}, 'PGF', $var);
643+
my $yfunction = $data->function_string($path->{Fy}, 'PGF', $var);
638644

639645
my $steps = $path->{steps} // $data->{function}{steps};
640646

macros/graph/plots.pl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,22 @@ =head2 PLOT FUNCTIONS
197197
198198
=head2 PLOT MULTIPATH FUNCTIONS
199199
200-
A multipath function is defined using multiple parametric paths pieced together
201-
into into a single curve, whose primary use is to create a closed region to be
202-
filled using multiple boundaries. This is done by providing a list of
203-
parametric functions, the name of the parameter, and a list of options.
200+
A multipath function is defined using multiple parametric paths and points
201+
pieced together into into a single curve. This is done by providing a list of
202+
parametric functions and points, the name of the parameter, and a list of
203+
options. A parametric function is specified by a reference to an array
204+
containing an x function, a y function, the minimum value for the parameter, and
205+
the maximum value for the parameter, followed by options. A point is specified
206+
by a reference to an array containing the coordinates of the point. One reason
207+
for creating a multipath is to create a closed region to be filled using
208+
multiple boundaries.
204209
205210
$plot->add_multipath(
206211
[
207-
[ $function_x1, $function_y1, $min1, $max1, %path_options ],
208-
[ $function_x2, $function_y2, $min2, $max2, %path_options ],
212+
[ $function_x1, $function_y1, $min1, $max1, %path_options1 ],
213+
[ $function_x2, $function_y2, $min2, $max2, %path_options2 ],
214+
[ $point_x1, $point_x2 ]
215+
[ $function_x3, $function_y3, $min3, $max3, %path_options3 ],
209216
...
210217
],
211218
$variable,
@@ -222,19 +229,19 @@ =head2 PLOT MULTIPATH FUNCTIONS
222229
The paths have to be listed in the order they are followed, but the
223230
minimum/maximum values of the parameter can match the parametrization. The
224231
following example creates a sector of radius 5 between pi/4 and 3pi/4, by first
225-
drawing the line from (0,0) to (5sqrt(2),5/sqrt(2)), then the arc of the circle
226-
of radius 5 from pi/4 to 3pi/4, followed by the final line from (-5sqrt(2),
227-
5sqrt(2)) back to the origin.
232+
drawing the arc of the circle of radius 5 from pi/4 to 3pi/4, followed by the
233+
line from (-5 sqrt(2), 5 sqrt(2)) to the origin, and then drawing the line from
234+
the origin to (5 sqrt(2), 5 sqrt(2)).
228235
229236
$plot->add_multipath(
230237
[
231-
[ 't', 't', 0, '5/sqrt(2)' ],
232238
[ '5cos(t)', '5sin(t)', 'pi/4', '3pi/4' ],
233-
[ '-t', 't', '5/sqrt(2)', 0 ],
239+
[ 0, 0 ],
234240
],
235241
't',
236242
color => 'green',
237243
fill => 'self',
244+
cycle => 1
238245
);
239246
240247
Note that the ending point of one path does not need to be the same as the

0 commit comments

Comments
 (0)