File:  [LON-CAPA] / loncom / homework / imageresponse.pm
Revision 1.42: download - view: text, annotated - select for diffs
Tue Nov 11 00:39:33 2003 UTC (20 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_X, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, HEAD
- now shows the area of correctness after it is graded correct
  (I am open to comments about this bad idea? good idea?)

    1: # The LearningOnline Network with CAPA
    2: # image click response style
    3: #
    4: # $Id: imageresponse.pm,v 1.42 2003/11/11 00:39:33 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #FIXME LATER assumes multiple possible submissions but only one is possible 
   29: #currently
   30: 
   31: package Apache::imageresponse;
   32: use strict;
   33: use Image::Magick;
   34: use Apache::randomlylabel;
   35: use Apache::Constants qw(:common :http);
   36: 
   37: BEGIN {
   38:     &Apache::lonxml::register('Apache::imageresponse',('imageresponse'));
   39: }
   40: 
   41: sub start_imageresponse {
   42:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   43:     my $result;
   44:     #when in a radiobutton response use these
   45:     &Apache::lonxml::register('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));
   46:     push (@Apache::lonxml::namespace,'imageresponse');
   47:     my $id = &Apache::response::start_response($parstack,$safeeval);
   48:     if ($target eq 'meta') {
   49: 	$result=&Apache::response::meta_package_write('imageresponse');
   50:     } elsif ($target eq 'analyze') {
   51: 	my $part_id="$Apache::inputtags::part.$id";
   52: 	push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
   53:     }
   54:     return $result;
   55: }
   56: 
   57: sub end_imageresponse {
   58:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   59:     &Apache::response::end_response;
   60:     pop @Apache::lonxml::namespace;
   61:     &Apache::lonxml::deregister('Apache::imageresponse',('foilgroup','foil','text','image','rectangle','conceptgroup'));
   62:     my $result;
   63:     if ($target eq 'edit') { $result=&Apache::edit::end_table(); }
   64:     return $result;
   65: }
   66: 
   67: %Apache::response::foilgroup=();
   68: sub start_foilgroup {
   69:     %Apache::response::foilgroup=();
   70:     $Apache::imageresponse::conceptgroup=0;
   71:     &Apache::response::setrandomnumber();
   72:     return '';
   73: }
   74: 
   75: sub getfoilcounts {
   76:     my ($parstack,$safeeval)=@_;
   77: 
   78:     my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
   79:     # +1 since instructors will count from 1
   80:     my $count = $#{ $Apache::response::foilgroup{'names'} }+1;
   81:     if (&Apache::response::showallfoils()) { $max=$count; }
   82:     return ($count,$max);
   83: }
   84: 
   85: sub whichfoils {
   86:     my ($max)=@_;
   87:     if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
   88:     my @names = @{ $Apache::response::foilgroup{'names'} };
   89:     my @whichopt =();
   90:     while ((($#whichopt+1) < $max) && ($#names > -1)) {
   91: 	&Apache::lonxml::debug("Have $#whichopt max is $max");
   92: 	my $aopt;
   93: 	if (&Apache::response::showallfoils()) {
   94: 	    $aopt=0;
   95: 	} else {
   96: 	    $aopt=int(&Math::Random::random_uniform() * ($#names+1));
   97: 	}
   98: 	&Apache::lonxml::debug("From $#names elms, picking $aopt");
   99: 	$aopt=splice(@names,$aopt,1);
  100: 	&Apache::lonxml::debug("Picked $aopt");
  101: 	push (@whichopt,$aopt);
  102:     }
  103:     return @whichopt;
  104: }
  105: 
  106: sub prep_image {
  107:     my ($image,$mode,$name)=@_;
  108:     my $part=$Apache::inputtags::part;
  109:     my $respid=$Apache::inputtags::response['-1'];
  110:     my $id=&Apache::loncommon::get_cgi_id();
  111:     my %x;
  112:     $x{"cgi.$id.BGIMG"}=$image;
  113:     my ($x,$y)=split(/:/,$Apache::lonhomework::history{"resource.$part.$respid.submission"});
  114:     #draws 2 xs on the image at the clicked location
  115:     #one in white and then one in red on top of the one in white
  116:     if (defined($x) && defined($y)) {
  117: 	$x{"cgi.$id.LINECOUNT"}=4;
  118: 	my $length = 6;
  119: 	my $width = 1;
  120: 	my $extrawidth = 2;
  121: 	$x{"cgi.$id.LINE0"}=
  122: 	    join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
  123: 		      "FFFFFF",($width+$extrawidth)));
  124: 	$x{"cgi.$id.LINE1"}=
  125: 	    join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
  126: 		      "FFFFFF",($width+$extrawidth)));
  127: 	$x{"cgi.$id.LINE2"}=
  128: 	    join(':',(($x-$length),($y-$length),($x+$length),($y+$length),
  129: 		      "FF0000",($width)));
  130: 	$x{"cgi.$id.LINE3"}=
  131: 	    join(':',(($x-$length),($y+$length),($x+$length),($y-$length),
  132: 		      "FF0000",($width)));
  133:     }
  134:     if ($mode eq 'answer') {
  135: 	my $width = 1;
  136: 	my $extrawidth = 2;
  137: 	my @areas = @{ $Apache::response::foilgroup{"$name.area"} };
  138: 	foreach my $area (@areas) {
  139: 	    my ($x1,$y1,$x2,$y2)=
  140: 		($area=~m/rectangle:\(([0-9]+),([0-9]+)\)\-\(([0-9]+),([0-9]+)\)/);
  141: 	    my $i=$x{"cgi.$id.BOXCOUNT"}++;
  142: 	    $x{"cgi.$id.BOX$i"}=join(':',($x1,$y1,$x2,$y2,"FFFFFF",
  143: 					  ($width+$extrawidth)));
  144: 	    $i=$x{"cgi.$id.BOXCOUNT"}++;
  145: 	    $x{"cgi.$id.BOX$i"}=join(':',($x1,$y1,$x2,$y2,"00FF00",$width));
  146: 	}
  147:     }
  148:     &Apache::lonnet::appenv(%x);
  149:     return $id;
  150: }
  151: 
  152: sub displayfoils {
  153:     my ($target,@whichopt) = @_;
  154:     my $result ='';
  155:     my $name;
  156:     my $temp=1;
  157:     foreach $name (@whichopt) {
  158: 	$result.=$Apache::response::foilgroup{"$name.text"};
  159: 	&Apache::lonxml::debug("Text is $result");
  160: 	if ($target eq 'tex') {$result.="\\vskip 0 mm \n";} else {$result.="<br />\n";}
  161: 	my $image=$Apache::response::foilgroup{"$name.image"};
  162: 	&Apache::lonxml::debug("image is $image");
  163: 	if ( $target eq 'web' && $image !~ /^http:/ ) {
  164: 	    $image=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$image);
  165: 	    if (&Apache::lonnet::repcopy($image) ne OK) {
  166: 		$image='/home/httpd/html/adm/lonKaputt/lonlogo_broken.gif';
  167: 	    }
  168: 	}
  169: 	&Apache::lonxml::debug("image is $image");
  170: 	if ( &Apache::response::show_answer() ) {
  171: 	    if ($target eq 'tex') {
  172: 		$result.=$Apache::response::foilgroup{"$name.image"}."\\vskip 0 mm \n";
  173: 	    } else {
  174: 		my $token=&prep_image($image,'answer',$name);
  175: 		$result.="<img src=\"/adm/randomlabel.png?token=$token\" /><br />\n";
  176: 	    }
  177: 	} else {
  178: 	    if ($target eq 'tex') {
  179: 		$result.=$Apache::response::foilgroup{"$name.image"}."\\vskip 0 mm \n";
  180: 	    } else {
  181: 		my $id=$Apache::inputtags::response['-1'];
  182: 		my $token=&prep_image($image);
  183: 		my $temp=1;
  184: 		$result.="<input type=\"image\" name=\"HWVAL_$id:$temp\" ".
  185: 		    "src=\"/adm/randomlabel.png?token=$token\" /><br />\n";
  186: 	    }
  187: 	}
  188: 	$temp++;
  189:     }
  190:     return $result;
  191: }
  192: 
  193: sub gradefoils {
  194:     my (@whichopt) = @_;
  195:     my $x;
  196:     my $y;
  197:     my $result;
  198:     my $id=$Apache::inputtags::response['-1'];
  199:     my $temp=1;
  200:     foreach my $name (@whichopt) {
  201: 	$x=$ENV{"form.HWVAL_$id:$temp.x"};
  202: 	$y=$ENV{"form.HWVAL_$id:$temp.y"};
  203: 	&Apache::lonxml::debug("Got a x of $x and a y of $y for $name");
  204: 	if (defined($x) && defined($y) &&
  205: 	    defined(@{ $Apache::response::foilgroup{"$name.area"} })) {
  206: 	    my @areas = @{ $Apache::response::foilgroup{"$name.area"} };
  207: 	    my $grade="INCORRECT";
  208: 	    foreach my $area (@areas) {
  209: 		&Apache::lonxml::debug("Area is $area for $name");
  210: 		$area =~ m/([a-z]*):/;
  211: 		&Apache::lonxml::debug("Area of type $1");
  212: 		if ($1 eq 'rectangle') {
  213: 		    $grade=&grade_rectangle($area,$x,$y);
  214: 		} else {
  215: 		    &Apache::lonxml::error("Unknown area style $area");
  216: 		}
  217: 		&Apache::lonxml::debug("Area said $grade");
  218: 		if ($grade eq 'APPROX_ANS') { last; }
  219: 	    }
  220: 	    &Apache::lonxml::debug("Foil was $grade");
  221: 	    if ($grade eq 'INCORRECT') { $result= 'INCORRECT'; }
  222: 	    if (($grade eq 'APPROX_ANS') && ($result ne 'APPROX_ANS')) { $result=$grade; }
  223: 	    &Apache::lonxml::debug("Question is $result");
  224: 	    $temp++;
  225: 	}
  226:     }
  227:     $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}="$x:$y";
  228:     $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}=$result;
  229:     return '';
  230: }
  231: 
  232: sub end_foilgroup {
  233:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  234:     my $result='';
  235:     my @whichopt;
  236:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex' ||
  237: 	$target eq 'analyze') {
  238: 	my ($count,$max) = &getfoilcounts($parstack,$safeeval);
  239: 	if ($count>$max) { $count=$max }
  240: 	&Apache::lonxml::debug("Count is $count from $max");
  241: 	@whichopt = &whichfoils($max);
  242: 	if ($target eq 'web' || $target eq 'tex') {
  243: 	    $result=&displayfoils($target,@whichopt);
  244: 	} elsif ($target eq 'grade') {
  245: 	    if ( defined $ENV{'form.submitted'}) { &gradefoils(@whichopt); }
  246: 	} elsif ( $target eq 'analyze') {
  247: 	    &Apache::response::analyze_store_foilgroup(\@whichopt,
  248: 						      ['text','image','area']);
  249: 	}
  250:     } elsif ($target eq 'edit') {
  251: 	$result=&Apache::edit::end_table();
  252:     }
  253:     return $result;
  254: }
  255: 
  256: sub start_conceptgroup {
  257:     $Apache::imageresponse::conceptgroup=1;
  258:     %Apache::response::conceptgroup=();
  259:     return '';
  260: }
  261: 
  262: sub end_conceptgroup {
  263:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  264:     $Apache::imageresponse::conceptgroup=0;
  265:     my $result;
  266:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex' ||
  267: 	$target eq 'analyze') {
  268: 	&Apache::response::pick_foil_for_concept($target,
  269: 						 ['area','text','image'],
  270: 						 \%Apache::hint::image,
  271: 						 $parstack,$safeeval);
  272:     } elsif ($target eq 'edit') {
  273: 	$result=&Apache::edit::end_table();
  274:     }
  275:     return $result;
  276: }
  277: 
  278: sub insert_foil {
  279:     return '
  280:        <foil>
  281:            <image></image>
  282:            <text></text>
  283:            <rectangle></rectangle>
  284:        </foil>
  285: ';
  286: }
  287: 
  288: $Apache::imageresponse::curname='';
  289: sub start_foil {
  290:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  291:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex' ||
  292: 	$target eq 'analyze') {
  293: 	my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
  294: 	if ($name eq '') { $name=$Apache::lonxml::curdepth; }
  295: 	if ( $Apache::imageresponse::conceptgroup
  296: 	     && !&Apache::response::showallfoils()) {
  297: 	    push(@{ $Apache::response::conceptgroup{'names'} }, $name);
  298: 	} else {
  299: 	    push(@{ $Apache::response::foilgroup{'names'} }, $name);
  300: 	}
  301: 	$Apache::imageresponse::curname=$name;
  302:     }
  303:     return '';
  304: }
  305: 
  306: sub end_foil {
  307:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  308:     my $result;
  309:     if ($target eq 'edit') {
  310: 	$result=&Apache::edit::end_table();
  311:     }
  312:     return $result;
  313: }
  314: 
  315: sub start_text {
  316:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  317:     my $result='';
  318:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
  319: 	&Apache::lonxml::startredirection; 
  320:     } elsif ($target eq 'edit') {
  321: 	my $descr=&Apache::lonxml::get_all_text('/text',$parser);
  322: 	$result=&Apache::edit::tag_start($target,$token,'Task Description').
  323: 	    &Apache::edit::editfield($token->[1],$descr,'Text',60,2).
  324: 	    &Apache::edit::end_row();
  325:     } elsif ($target eq "modified") {
  326: 	$result=$token->[4].&Apache::edit::modifiedfield('/text',$parser);
  327:     }
  328:     return $result;
  329: }
  330: 
  331: sub end_text {
  332:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  333:     my $result;
  334:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') {
  335: 	my $name = $Apache::imageresponse::curname;
  336: 	if ( $Apache::imageresponse::conceptgroup
  337: 	     && !&Apache::response::showallfoils() ) {
  338: 	    $Apache::response::conceptgroup{"$name.text"} = &Apache::lonxml::endredirection;
  339: 	} else {
  340: 	    $Apache::response::foilgroup{"$name.text"} = &Apache::lonxml::endredirection;
  341: 	}
  342:     } elsif ($target eq 'edit') {
  343: 	$result=&Apache::edit::end_table();
  344:     }
  345:     return $result;
  346: }
  347: 
  348: sub start_image {
  349:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  350:     my $result='';
  351:     if ($target eq 'web' || $target eq 'tex' || $target eq 'analyze') { 
  352: 	&Apache::lonxml::startredirection; 
  353:     } elsif ($target eq 'edit') {
  354: 	my $bgimg=&Apache::lonxml::get_all_text('/image',$parser);
  355: 	$Apache::edit::bgimgsrc=$bgimg;
  356: 	$Apache::edit::bgimgsrcdepth=$Apache::lonxml::curdepth;
  357: 
  358: 	$result=&Apache::edit::tag_start($target,$token,'Clickable Image').
  359: 	    &Apache::edit::editline($token->[1],$bgimg,'Image Source File',40);
  360: 	$result.=&Apache::edit::browse(undef,'textnode').' ';
  361: 	$result.=&Apache::edit::search(undef,'textnode').
  362: 	    &Apache::edit::end_row();
  363:     } elsif ($target eq "modified") {
  364: 	$result=$token->[4].&Apache::edit::modifiedfield('/image',$parser);
  365:     }
  366:     return $result;
  367: }
  368: 
  369: sub end_image {
  370:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  371:     my $result;
  372:     my $name = $Apache::imageresponse::curname;
  373:     if ($target eq 'web') {
  374: 	my $image = &Apache::lonxml::endredirection;
  375: 	&Apache::lonxml::debug("original image is $image");
  376: 	if ( $Apache::imageresponse::conceptgroup
  377: 	     && !&Apache::response::showallfoils()) {
  378: 	    $Apache::response::conceptgroup{"$name.image"} = $image;
  379: 	} else {
  380: 	    $Apache::response::foilgroup{"$name.image"} = $image;
  381: 	}
  382:     } elsif ($target eq 'analyze') {
  383: 	my $image = &Apache::lonxml::endredirection;
  384: 	if ( $Apache::imageresponse::conceptgroup
  385: 	     && !&Apache::response::showallfoils()) {
  386: 	    $Apache::response::conceptgroup{"$name.image"} = $image;
  387: 	} else {
  388: 	    $Apache::response::foilgroup{"$name.image"} = $image;
  389: 	}
  390:     } elsif ($target eq 'edit') {
  391: 	$result=&Apache::edit::end_table();
  392:     } elsif ($target eq 'tex') {
  393: 	my $src = &Apache::lonxml::endredirection;
  394: 	$src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
  395: 	my $width_param = '';
  396: 	my $height_param = '';
  397: 	my $scaling = .3;
  398: 	my $image = Image::Magick->new;
  399: 	my $current_figure = $image->Read($src);
  400: 	$width_param = $image->Get('width') * $scaling;;
  401: 	$height_param = $image->Get('height') * $scaling;;
  402: 	undef $image;
  403: 	my $epssrc = $src;
  404: 	$epssrc =~ s/(\.gif|\.jpg)$/\.eps/i;
  405: 	if (not -e $epssrc) {
  406: 	    my $localfile = $epssrc;
  407: 	    $localfile =~ s/.*(\/res)/$1/;	
  408: 	    my $file;
  409: 	    my $path;	
  410: 	    if ($localfile =~ m!(.*)/([^/]*)$!) {
  411: 		$file = $2;
  412: 		$path = $1.'/'; 
  413: 	    }	
  414: 	    my $signal_eps = 0;
  415: 	    my @content_directory = &Apache::lonnet::dirlist($path);
  416: 	    for (my $iy=0;$iy<=$#content_directory;$iy++) {
  417: 		my @tempo_array = split(/&/,$content_directory[$iy]);
  418: 		$content_directory[$iy] = $tempo_array[0];
  419: 		if ($file eq $tempo_array[0]) {
  420: 		    $signal_eps = 1;
  421: 		    last;
  422: 		}
  423: 	    }
  424: 	    if ($signal_eps) {
  425: 		my $eps_file = &Apache::lonnet::getfile($localfile);
  426: 	    } else {
  427: 		$localfile = $src;
  428: 		$localfile =~ s/.*(\/res)/$1/;	
  429: 		my $as = &Apache::lonnet::getfile($src);		      
  430: 	    }
  431: 	}
  432: 	my $file;
  433: 	my $path;	
  434: 	if ($src =~ m!(.*)/([^/]*)$!) {
  435: 	    $file = $2;
  436: 	    $path = $1.'/'; 
  437: 	}
  438: 	my $newsrc = $src;
  439: 	$newsrc =~ s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
  440: 	$file=~s/(\.gif|\.jpg|\.jpeg)$/\.eps/i;
  441: 	#do we have any specified size of the picture?
  442: 	my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval); 
  443: 	my $TeXheight = &Apache::lonxml::get_param('TeXheight',$parstack,$safeeval); 
  444: 	my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval);
  445: 	if ($TeXwidth ne '') { 
  446: 	    $width_param = $TeXwidth; 
  447: 	} elsif ($TeXheight ne '') { 
  448: 	    $width_param = $TeXheight/$height_param*$width_param;
  449: 	} elsif ($width ne '') {
  450: 	    $width_param = $width*$scaling;      
  451: 	}
  452: 	#where can we find the picture?
  453: 	if (-e $newsrc) {
  454: 	    if ($path) {
  455: 		$Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \noindent\graphicspath{{'.$path.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
  456: 	    }
  457: 	} else {
  458: 	    my $temp_file;
  459: 	    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.dat";
  460: 	    $temp_file = Apache::File->new('>>'.$filename); 
  461: 	    print $temp_file "$src\n";
  462: 	    $Apache::response::foilgroup{"$name.image"} ='\vskip 0 mm \graphicspath{{/home/httpd/prtspool/}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
  463: 	}
  464:     } 
  465:     return $result;
  466: }
  467: 
  468: sub start_rectangle {
  469:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  470:     my $result='';
  471:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex' ||
  472: 	$target eq 'analyze') { 
  473: 	&Apache::lonxml::startredirection; 
  474:     } elsif ($target eq 'edit') {
  475: 	my $coords=&Apache::lonxml::get_all_text('/rectangle',$parser);
  476: 	$result=&Apache::edit::tag_start($target,$token,'Rectangle').
  477: 	    &Apache::edit::editline($token->[1],$coords,'Coordinate Pairs',40).
  478: 	    &Apache::edit::entercoordpair(undef,'textnode').
  479: 	    &Apache::edit::end_row();
  480:     } elsif ($target eq "modified") {
  481: 	$result=$token->[4].&Apache::edit::modifiedfield('/rectangle',$parser);
  482:     }
  483:     return $result;
  484: }
  485: 
  486: sub grade_rectangle {
  487:     my ($spec,$x,$y) = @_;
  488:     &Apache::lonxml::debug("Spec is $spec");
  489:     $spec=~m/rectangle:\(([0-9]+),([0-9]+)\)\-\(([0-9]+),([0-9]+)\)/;
  490:     my $x1=$1;
  491:     my $y1=$2;
  492:     my $x2=$3;
  493:     my $y2=$4;
  494:     &Apache::lonxml::debug("Point $x1,$y1,$x2,$y2");
  495:     if ($x1 > $x2) { my $temp=$x1;$x1=$x2;$x2=$temp; }
  496:     if ($y1 > $y2) { my $temp=$y1;$y1=$y2;$y2=$temp; }
  497:     if (($x >= $x1) && ($x <= $x2) && ($y >= $y1) && ($y <= $y2)) {
  498: 	return 'APPROX_ANS';
  499:     }
  500:     return 'INCORRECT';
  501: }
  502: 
  503: sub end_rectangle {
  504:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  505:     my $result;
  506:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex' ||
  507: 	$target eq 'analyze') {
  508: 	my $name = $Apache::imageresponse::curname;
  509: 	my $area = &Apache::lonxml::endredirection;
  510: 	&Apache::lonxml::debug("out is $area for $name");
  511: 	if ( $Apache::imageresponse::conceptgroup
  512: 	     && !&Apache::response::showallfoils()) {
  513: 	    push @{ $Apache::response::conceptgroup{"$name.area"} },"rectangle:$area";
  514: 	} else {
  515: 	    push @{ $Apache::response::foilgroup{"$name.area"} },"rectangle:$area";
  516: 	}
  517:     } elsif ($target eq 'edit') {
  518: 	$result=&Apache::edit::end_table();
  519:     }
  520:     return $result;
  521: }
  522: 1;
  523: __END__
  524:  

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>