From: dpvc v. a. <we...@ma...> - 2008-09-16 03:28:38
|
Log Message: ----------- Allow graphs of single-variable functions in diagnostics. Modified Files: -------------- pg/macros: parserFormulaUpToConstant.pl Revision Data ------------- Index: parserFormulaUpToConstant.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/parserFormulaUpToConstant.pl,v retrieving revision 1.17 retrieving revision 1.18 diff -Lmacros/parserFormulaUpToConstant.pl -Lmacros/parserFormulaUpToConstant.pl -u -r1.17 -r1.18 --- macros/parserFormulaUpToConstant.pl +++ macros/parserFormulaUpToConstant.pl @@ -118,7 +118,6 @@ # my $context = (Value::isContext($_[0]) ? shift : $self->context)->copy; $context->{parser}{Variable} = 'FormulaUpToConstant::Variable'; - $context->{diagnostics}{formulas}{showGraphs} = 0; # # Create a formula from the user's input. # @@ -191,15 +190,6 @@ } # -# Provide diagnostics based on the adapted function used to check -# the student's answer -# -sub cmp_diagnostics { - my $self = shift; - $self->inherit($self->{adapt})->SUPER::cmp_diagnostics(@_); -} - -# # Return the {adapt} formula with test points adjusted # sub adapt { @@ -262,6 +252,30 @@ sub cmp_defaults {((shift)->SUPER::cmp_defaults,showHints => 1, showLinearityHints => 1)}; # +# Provide diagnostics based on the adapted function used to check +# the student's answer +# +sub cmp_diagnostics { + my $self = shift; + $self->inherit($self->{adapt})->SUPER::cmp_diagnostics(@_); +} + +# +# Make it possible to graph single-variable formulas by setting +# the arbitrary constants to 0 first. +# +sub cmp_graph { + my $self = shift; my $diagnostics = shift; + my $F1 = shift; my $F2; ($F1,$F2) = @{$F1} if (ref($F1) eq 'ARRAY'); + my %subs; my $context = $self->context; + foreach my $v ($context->variables->variables) + {$subs{$v} = 0 if ($context->variables->get($v)->{arbitraryConstant})} + $F1 = $F1->inherit($F1->{adapt})->substitute(%subs)->reduce; + $F2 = $F2->inherit($F2->{adapt})->substitute(%subs)->reduce; + $self->SUPER::cmp_graph($diagnostics,[$F1,$F2]); +} + +# # Add useful messages, if the author requested them # sub cmp_postprocess { |