[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm
www
www at source.lon-capa.org
Mon Nov 21 15:20:48 EST 2011
www Mon Nov 21 20:20:48 2011 EDT
Modified files:
/loncom/homework functionplotresponse.pm
Log:
Sum-Vector rule works with comma-separated list
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.81 loncom/homework/functionplotresponse.pm:1.82
--- loncom/homework/functionplotresponse.pm:1.81 Mon Nov 21 19:48:52 2011
+++ loncom/homework/functionplotresponse.pm Mon Nov 21 20:20:48 2011
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# Functionplot responses
#
-# $Id: functionplotresponse.pm,v 1.81 2011/11/21 19:48:52 www Exp $
+# $Id: functionplotresponse.pm,v 1.82 2011/11/21 20:20:48 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -894,14 +894,12 @@
my $id=$Apache::inputtags::response[-1];
my $partid=$Apache::inputtags::part;
my $internalid = $partid.'_'.$id;
- my $object=&Apache::lonxml::get_param('object',$parstack,$safeeval);
- $object=~s/\W//gs;
- $object=ucfirst($object);
+ my $vectors=&Apache::lonxml::get_param('vectors',$parstack,$safeeval);
push(@Apache::functionplotresponse::functionplotvectorrules,join(':',(
$label,
'sum',
$internalid,
- $object,
+ $vectors,
&Apache::lonxml::get_param('length',$parstack,$safeeval),
&Apache::lonxml::get_param('angle',$parstack,$safeeval),
&Apache::lonxml::get_param('lengtherror',$parstack,$safeeval),
@@ -911,8 +909,8 @@
$result=&Apache::edit::tag_start($target,$token,'Function Plot Vector Sum Rule').
&Apache::edit::text_arg('Index/Name:','index',
$token,'10').' '.
- &Apache::edit::text_arg('Vectors attached to object:','object',
- $token,'16').'<br />'.
+ &Apache::edit::text_arg('Comma-separated list of vectors:','vectors',
+ $token,'30').'<br />'.
&Apache::edit::text_arg('Sum vector length:','length',
$token,'16').
&Apache::edit::text_arg('Sum vector angle:','angle',
@@ -925,7 +923,7 @@
} elsif ($target eq 'modified') {
$env{'form.'.&Apache::edit::html_element_name('object')}=ucfirst($env{'form.'.&Apache::edit::html_element_name('object')});
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
- $safeeval,'index','object',
+ $safeeval,'index','vectors',
'length','angle',
,'lengtherror','angleerror');
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
@@ -1520,9 +1518,16 @@
sub sumcheck {
my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_;
- my ($label,$type,$id,$object,$length,$angle,$lengtherror,$angleerror)=split(/\:/,$rule);
- &addlog("Vector Sum Rule $label for vectors attached to ".$object);
-
+ my ($label,$type,$id,$vectors,$length,$angle,$lengtherror,$angleerror)=split(/\:/,$rule);
+ &addlog("Vector Sum Rule $label for vectors ".$vectors);
+ my $sumx=0;
+ my $sumy=0;
+ foreach my $sv (split(/\s*\,\s*/,$vectors)) {
+ my ($rx,$ry)=&relvector(&vectorcoords($id,$sv));
+ $sumx+=$rx;
+ $sumy+=$ry;
+ }
+ &addlog("Sum vector ($sumx,$sumy)");
&addlog("Rule $label passed.");
return 1;
}
More information about the LON-CAPA-cvs
mailing list