xc=!eval $xx_size*($click_x-$border)/$inssize+$x_size1
yc=!eval $yy_size*(-$click_y+$border)/$inssize+$x_size2

!if $status=waiting
	!if $inv=0
		!if $opar1<2
			pt=0
			!for i=1 to $n
				u=$(abscisse$i)
				v=$(ordonnee$i)
				d=$[(abs((($xc) - ($u))^2 + (($yc) - ($v))^2))^(1/2)]
				!if $d < $incert
					pt=$i
				!endif
			!next i
			!if $pt=0
				error=pas_de_point
			!else
				!if $etp=0
					ar=$pt
					ptabs=$(abscisse$pt)
					ptord=$(ordonnee$pt)
					etp=1
				!else
					ar=$ar,$pt
!! L'arte a dj t dessine ?
					I=!item 1 of $ar
					J=$pt
					L=!line $I of $GCM
					u=!item $J of $L
					L=!line $J of $GCM
					v=!item $I of $L
!! w=prsence d'une arte entre i et j ou de i vers j
					!if $gor=0
						!if ($u=1) or ($v=1)
							w=1
						!else
							w=0
						!endif
					!else
						w=$u
					!endif
					essai=$w
					!if $opar1=0
						!if $w = 0
							GC=!exec pari M=[$GC]; M[$I,$J]=1; print(M)
							GCM=!translate internal ; to $\
$ in $GC
						!else
							error=arete_existe_deja
						!endif
					!else
						!if $w=1
							!if $gor=0
								GC=!exec pari M=[$GC]; M[$I,$J]=0; M[$J,$I]=0; print(M)
							!else
								GC=!exec pari M=[$GC]; M[$I,$J]=0; print(M)
							!endif
							GCM=!translate internal ; to $\
$ in $GC
						!else
							error=arete_n_existe_pas
						!endif
					!endif
					etp=0
				!endif
			!endif
!! Prparation du trac des artes
			dessin_aretes=$empty
			!for i=1 to $n
				!for j=1 to $n
					L=!line $i of $GCM
					u=!item $j of $L
					!if $u=1
						param=$empty
							x1=$(abscisse$i)
							y1=$(ordonnee$i)
							x2=$(abscisse$j)
							y2=$(ordonnee$j)
								!if $gor=1
									x=$[$x1+$k*($x2-$x1)]
									y=$[$y1+$k*($y2-$y1)]
									param=arrow $x1, $y1, $x, $y, $kf, $color2
								!endif
								param=$param\
line $x1, $y1, $x2, $y2, $color2
dessin_aretes=$dessin_aretes\
$param
					!endif
			!next j
		!next i
		!if $etp=1
			dessin_aretes=$dessin_aretes\
disk $ptabs,$ptord, 6, $color3
		!endif
	!else
		!if $gor=0
			GC=!exec pari {A=[$GC];\
			A=matrix($n,$n,i,j,max(A[i,j],A[j,i]));print(A)}
			GCM=!translate internal ; to $\
$ in $GC
			GCM=!trim $GCM
		!endif
		D=!exec pari print([$G]-[$GC]);
		DM=!translate internal ; to $\
$ in $D
		test=!exec pari [$D]==0
		!if $test=1
			module_score=10
		!else
			nbar=0
			nberrp=0
			nberrm=0
			!for i=1 to $n
				!for j=1 to $n
					L=!line $i of $DM
					u=!item $j of $L
						!if $u = 1
							!advance nberrm
						!endif
						!if $u = -1
							!advance nberrp
						!endif
						L=!line $i of $GM
						u=!item $j of $L
						!if $u = 1
							!advance nbar
						!endif
					!next j
				!next i
				module_score=$[floor(10*max(0,10*(1-$nberrm/$nbar-$nberrp/($n^2-$nbar))))/10]
!! Trac du graphe corrig
				dessin_aretes=$empty
				!for i=1 to $n
					!if $gor=0
						w=$i
					!else
						w=$n
					!endif
					!for j=1 to $w
					L=!line $i of $GM
					u=!item $j of $L
					L=!line $i of $GCM
					v=!item $j of $L
					color0=$empty
						!if ($u=1) and ($v=1)
							color0=$color2
						!endif
						!if ($u=1) and ($v=0)
							color0=$color3
						!endif
						!if ($u=0) and ($v=1)
							color0=$color4
						!endif
						!if $color0<>$empty
							param=$empty
							x1=$(abscisse$i)
							y1=$(ordonnee$i)
							x2=$(abscisse$j)
							y2=$(ordonnee$j)
							!if $gor=1
								x=$[$x1+$k*($x2-$x1)]
								y=$[$y1+$k*($y2-$y1)]
								param=arrow $x1, $y1, $x, $y, $kf, $color0
							!endif
							param=$param\
line $x1, $y1, $x2, $y2, $color0
							dessin_aretes=$dessin_aretes\
$param
					!endif
				!next j
			!next i
		!endif
!! Trac du graphe correct
		dessin_correct=$dessin_sommets
			!for i=1 to $n
				!for j=1 to $n
					L=!line $i of $GM
					u=!item $j of $L
					!if $u=1
						param=$empty
						x1=$(abscisse$i)
						y1=$(ordonnee$i)
						x2=$(abscisse$j)
						y2=$(ordonnee$j)
						!if $gor=1
							x=$[$x1+$k*($x2-$x1)]
							y=$[$y1+$k*($y2-$y1)]
							param=arrow $x1, $y1, $x, $y, $kf, $color2
						!endif
						param=$param\
line $x1, $y1, $x2, $y2, $color2
						dessin_correct=$dessin_correct\
		$param
					!endif
				!next j
			!next i
			status=done
		!endif
	!endif	
		xc=0
		yc=0
		click_x=0
		click_y=0
	!if $inv=1
		nbar=0
		listerep=$empty
		perm=$empty
		!for i=1 to $n
			!if $(np$i) notitemof $listemixte
				error=$error, erreur_nom
				!exit
			!endif	
			listerep=!append item  $(np$i) to $listerep
		!next i
		listerep=!nonempty items $listerep
		listerepunic=!listuniq $listerep
		cnt_listepunic= !itemcnt $listerepunic
		!if $cnt_listepunic <> $n
			error=$error, erreur_nombre
			!exit
		!endif
		uu=!sort item $listerep
		L= !item $listepos of  $wims_sort_order
		MR= !exec  pari L=Vec([$L]); M=Mat([$G]);print(matrix($n,$n, i,j,M[L[i],L[j]]))
		cnt_erreur=!exec pari M=Mat([$G]);MR=Mat([$MR]);norml2((MR-M)/2)

		!if $cnt_erreur=0
			module_score=10
		!else
			module_score=$[max(0,min(10,floor(100- 200*$cnt_erreur/$n)/10))]
			GMR= !translate internal ; to $\
$ in $MR
			dessin_faux=xrange $x_size\
yrange $y_size
			!for i=1 to $n
				dessin_faux=$dessin_faux\
				disk $(abscisse$i), $(ordonnee$i), 6, $color6\
				text $color1, 1.3*$(abscisse$i)-0.05,1.3*$(ordonnee$i)+0.1, medium, $(N$i)
			!next i
			!for i=1 to $n
				!for j=1 to $n
					L=!line $i of $GMR
					u=!item $j of $L
					!if $u=1
						x1=$(abscisse$i)
						y1=$(ordonnee$i)
						x2=$(abscisse$j)
						y2=$(ordonnee$j)
						dessin_faux=$dessin_faux\
line $x1, $y1, $x2, $y2, $color2
					!endif
				!next j
			!next i
		!endif
		status=done
	!endif	
!endif
	
