#
# Some tests of ray traps of n curves.
#
#						Gershon Elber, Aug 99
#

RayTrapTris = function( Crvs, SubEps, NumEps ): Pts: i: j: Pt: Points:
    Pts = raytraps( Crvs, SubEps, NumEps ):
    return = nil():
    for ( i = 1, 1, sizeof( Pts ),
        Pt = coord( Pts, i ):
	printf("Error = %16.14f\\n", list( GetAttr( Pt, "Error" ) ) ):
        Points = nil():
        for ( j = 1, 1, sizeof( Crvs ),
	    snoc( ceval( nth( Crvs, j ), coord( Pt, j ) ), Points ) ):
        snoc( poly( Points, false ), return ) );

save_mat = view_mat;
view_mat = sc( 0.5 );

#############################################################################

Crv1 = cbezier( list( ctlpt( E2, -1.5, 0 ),
		      ctlpt( E2,  0,   2 ),
		      ctlpt( E2,  1.5, 0 ) ) ) * ty( -1.5 );
Crv2 = Crv1 * rz( 110 );
Crv3 = Crv1 * rz( 230 );
Crvs = list( Crv1, Crv2, Crv3 );
view( list( view_mat, Crvs ), 1 );

Tris1 = RayTrapTris( Crvs, 1, 1e-6 );
Tris2 = RayTrapTris( Crvs, 0.5, 1e-6 );
Tris = list( Tris1, Tris2 );
interact( list( Crvs, Tris1, Tris2 ) );
save( "raytrap1", list( Crvs, Tris1, Tris2 ) );

for ( Trs = 0, 5, 50,
    Crv3a = Crv3 * rz( Trs ) * ty( Trs / 100 ):
    Crvs = list( Crv1, Crv2, Crv3a ):
    Tris = RayTrapTris( Crvs, 0.5, 1e-6 ):
    view( list( Crvs, Tris ), 1 ) );

for ( Trs = 0, 10, 100,
    Crv3a = Crv3 * tx( -Trs / 100 ) * ty( Trs / 100 ):
    Crvs = list( Crv1, Crv2, Crv3a ):
    Tris = RayTrapTris( Crvs, 0.5, 1e-6 ):
    view( list( Crvs, Tris ), 1 ) );

free( Crv3a );
free( Trs );
pause();

#############################################################################

Crv1 = cbezier( list( ctlpt( E2, -0.5, 0 ),
		      ctlpt( E2,  0,   2 ),
		      ctlpt( E2,  0.5, 0 ) ) ) * ty( -1.5 );
Crv2 = Crv1 * rz( 50 ) * ty( 0.4 ) * tx( 0.2 );
Crv3 = Crv1 * rz( 170 );
Crv4 = Crv1 * rz( 300 );
Crvs = list( Crv1, Crv2, Crv3, Crv4 );
view( list( view_mat, Crvs ), 1 );

Tris = RayTrapTris( Crvs, 0.1, 0.001 );
interact( list( Crvs, Tris ) );
save( "raytrap2", list( Crvs, Tris ) );

#############################################################################

Crv1 = pcircle( vector( -0.75, -0.75, 0 ), 0.5 );
Crv2 = Crv1 * sc( 1.5 ) * tx( 2 );
Crv3 = Crv1 * sc( 0.5 ) * tx( 0.2 ) * ty( 0.6 );
Crvs = list( Crv1, Crv2, Crv3 );
view( list( Crvs ), 1 );

Tris = RayTrapTris( Crvs, 0.1, -1e-6 );
interact( list( Crvs, Tris ) );
save( "raytrap3", list( Crvs, Tris ) );

#############################################################################

free( Crv1 );
free( Crv2 );
free( Crv3 );
free( Crv4 );
free( Crvs );
free( Tris );
free( Tris1 );
free( Tris2 );

view_mat = save_mat;
