option:color=" " precision=" " eqweight split default="empty"
!! how to get value of "precision" from canvas code?
!set precision=!getopt precision in $(replyoption$i)
!set tmp=!select $(oef_answer_option$i) where precision iswordof column 1
!default precision=!word 2 of $tmp
!if $precision=0
  !reset precision
!endif
!default precision=1000
!set xysize=!line 1 of $(oef_answer_option$i)
!set replygood$i=!lines2rows $(replygood$i)

!set type=$(replygood$i[2;1])
!if $type iswordof polyline
  replist=!lines2rows $(reply$i)
  replist=!exec pari [$replist]~
  replist=!replace internal ; by , in $replist
!else
    replist=$(reply$i)
!endif
!if $wims_read_parm=nocompare
  type=!line -1 of $(oef_answer_option$i)
  type=!word 1 of $type
  !set draw_reply_cnt=!itemcnt $replist
  !if $type iswordof arrows arrows2 segments and $[$draw_reply_cnt%4]!=0 and $replist notsametext empty
    test=NaN $i
    error=draw_bad_object
    !exit
  !endif
  !if $draw_reply_cnt <= 1
    !set parm3=!line 1 to -2 of $(oef_answer_option$i)
    !read oef/canvasdraw.phtml $parm3
  !else
    !set parm3=!line 1 to -2 of $(oef_answer_option$i)
    !set parm3_=!line -1 of $(oef_answer_option$i)
    !if $type iswordof poly3 poly4 poly5 poly6 poly7 poly8 poly9
      !set parm3_=!replace internal $type by polygon in $parm3_
    !endif
    !if $type iswordof curvedarrows curvedarrows2
      !set tmp=!itemcnt $replist
      !set tmp_=!values 6*x+1,6*x+2,6*x+5,6*x+6,6*x+3,6*x+4 for x=0 to $[$tmp/6-1]
      !set replist=$(replist[$tmp_])
    !endif
    !read oef/canvasdraw.phtml $parm3\
    $parm3_ $replist
  !endif
  reply_$i=$canvasdraw_out
  !exit
!endif
!set parm3=!line 1 to -2 of $(oef_answer_option$i)

!! first line : the code
!! second line : segments, list of segments

!set listtype1=segments arrows2 arrows rects circles points crosshairs curvedarrows curvedarrows2
!set listtype2=lines demilines
!!only one object
!set listtype3=polyline polygon
!set listtype=$listtype1 $listtype2
!set type=$(replygood$i[2;1])
!if $type iswordof poly3 poly4 poly5 poly6 poly7 poly8 poly9
  !set type=polygon
!endif
!set rlist=!sort lines $replist
!set good=$(replygood$i[2;2..-1])
!if $type iswordof polygon
  !set good=$good,$(good[1]),$(good[2])
!endif
!set good_cnt=!itemcnt $good

!if $type iswordof arrows arrows2
  !set arrow_head=!getopt arrow_head in $(replyoption$i)
  !default arrow_head=10
  option=$arrow_head,
!endif

!if $type iswordof $listtype $listtype3
  !set type_cnt=4
  !if $type iswordof circles
    !set type_cnt=3
  !endif
  !if $type iswordof points crosshairs $listtype3
    !set type_cnt=2
  !endif
  !if $type iswordof curvedarrows curvedarrows2
    !set type_cnt=6
  !endif
!endif
!set type_cnt2=$type_cnt
!if $type iswordof $listtype3
  !set type_cnt2=4
!endif

!if $[$good_cnt%$type_cnt]!=0
  Test=bad $i
  !exit
!endif
!reset g_cnt2 glist
!for s=1 to $[$good_cnt/$type_cnt]
  rg=$[($s-1)*$type_cnt]
  !if $rg+$type_cnt2 <= $good_cnt
    !increase g_cnt2
    !!need of the numero if we add some other tests
    glist=!append line $s,$(good[$rg+1 ..$rg+$type_cnt2]) to $glist
    !if $type iswordof segments arrows2 rects
      glist=!append line $s,$(good[$rg+3,$rg+4,$rg+1,$rg+2]) to $glist
    !endif
    !if $type iswordof curvedarrows2
      glist=!append line $s,$(good[$rg+3,$rg+4,$rg+1,$rg+2,$rg+5,$rg+6]) to $glist
    !endif
  !endif
!next
!set g_cnt=$[$good_cnt/$type_cnt]
!set g_cnt1=$g_cnt
!if $type iswordof segments arrows2
  g_cnt1=$[2*$g_cnt]
!endif
!set r_cnt=!itemcnt $rlist
!reset Rlist
!for s=1 to $r_cnt
  Rlist=!append line $(rlist[($s-1)*$type_cnt+1 ..($s-1)*$type_cnt+$type_cnt2]) to $Rlist
!next

!if $type iswordof $listtype3
  !if $type=polyline
    Rlist=!line 1 to -2 of $Rlist
  !else
    Rlist=$Rlist,$(rlist[1]),$(rlist[2])
  !endif
!else
  glist=!sort lines $glist
!endif

rlist=!sort lines $Rlist
r_cnt=!linecnt $rlist
!!g_cnt=!linecnt $glist

rlist=!lines2rows $rlist
glist=!lines2rows $glist
glist=!exec pari [$glist]
!reset goodrg goodrr

!set parm3=$parm3\
linewidth 3
!read anstype/draw.inc

goodrg=!listuniq $goodrg
totalr=!makelist x for x=1 to $r_cnt
totalg=!makelist x for x=1 to $g_cnt2
badr=!listcomplement $goodrr in $totalr
missing_r=!listcomplement $goodrg in $totalg
goodr_cnt=!itemcnt $goodrr
badr_cnt=$[$r_cnt - $goodr_cnt]
missing_r_cnt=!itemcnt $missing_r

!if $badr!=$empty
  !for u in $badr
    !if $type iswordof curvedarrows curvedarrows2
      parm3=!append line $type red,$option$(rlist[$u;1,2,5,6,3,4]) to $parm3
    !else
      parm3=!append line $type red,$option$(rlist[$u;1..$type_cnt2]) to $parm3
    !endif
  !next
!endif
!! display of good answer according to oef setup
!if $presentgood=1
  !if $missing_r_cnt!=0
    !for v in $missing_r
      parm3=!append line dashed\
$type blue, $option$(glist[$v;2..$type_cnt2+1]) to $parm3
    !next
  !endif
!endif
!if split iswordof $(replyoption$i) or partialscore iswordof $(replyoption$i) or eqweight iswordof $(replyoption$i)
  !if eqweight iswordof $(replyoption$i)
    coeff=0.5
  !else
    coeff=1
  !endif
!else
  coeff=0
!endif
!if $coeff=0
  !if $goodr_cnt=$g_cnt2 and $badr_cnt=0 and $missing_r_cnt=0
    score=1
  !else
    score=0
  !endif
!else
  score=$[max(0,min(1,($goodr_cnt-$coeff*(max($badr_cnt,$missing_r_cnt)))/$g_cnt2))]
!endif
!if $score=1
  diareply$i=good
  !increase freegot
!else
  !if $score>0.1
    partialgood$i=yes
    diareply$i=good
    freegot=$[$freegot+$score]
  !else
    diareply$i=bad
  !endif
!endif
!set parm3=!nonempty lines $parm3
!read oef/canvasdraw.phtml $xysize\
$parm3

reply_$i=$canvasdraw_out
reply__$i=&nbsp;
