File: curves.c

package info (click to toggle)
d1x-rebirth 0.58.1-1.2
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye, sid
  • size: 5,876 kB
  • sloc: ansic: 95,642; asm: 1,228; ada: 364; objc: 243; python: 121; cpp: 118; makefile: 23
file content (487 lines) | stat: -rw-r--r-- 17,293 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
*/

/*
 *
 * curve generation stuff
 *
 */

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include "inferno.h"
#include "vecmat.h"
#include "gr.h"
#include "key.h"
#include "editor.h"
#include "editor/esegment.h"
#include "gameseg.h"
#include "console.h"
#define ONE_OVER_SQRT2 F1_0 * 0.707106781
#define CURVE_RIGHT 1
#define CURVE_UP 2

segment *OriginalSeg;
segment *OriginalMarkedSeg;
int OriginalSide;
int OriginalMarkedSide;
segment *CurveSegs[MAX_SEGMENTS];
int CurveNumSegs;
const fix Mh[4][4] = { { 2*F1_0, -2*F1_0,  1*F1_0,  1*F1_0 },
                       {-3*F1_0,  3*F1_0, -2*F1_0, -1*F1_0 },
                       { 0*F1_0,  0*F1_0,  1*F1_0,  0*F1_0 },
                       { 1*F1_0,  0*F1_0,  0*F1_0,  0*F1_0 } };

void generate_banked_curve(fix maxscale, vms_equation coeffs);

void create_curve(vms_vector *p1, vms_vector *p4, vms_vector *r1, vms_vector *r4, vms_equation *coeffs) {
// Q(t) = (2t^3 - 3t^2 + 1) p1 + (-2t^3 + 3t^2) p4 + (t~3 - 2t^2 + t) r1 + (t^3 - t^2 ) r4

    coeffs->n.x3 = fixmul(2*F1_0,p1->x) - fixmul(2*F1_0,p4->x) + r1->x + r4->x;
    coeffs->n.x2 = fixmul(-3*F1_0,p1->x) + fixmul(3*F1_0,p4->x) - fixmul(2*F1_0,r1->x) - fixmul(1*F1_0,r4->x);
    coeffs->n.x1 = r1->x;
    coeffs->n.x0 = p1->x;
    coeffs->n.y3 = fixmul(2*F1_0,p1->y) - fixmul(2*F1_0,p4->y) + r1->y + r4->y;
    coeffs->n.y2 = fixmul(-3*F1_0,p1->y) + fixmul(3*F1_0,p4->y) - fixmul(2*F1_0,r1->y) - fixmul(1*F1_0,r4->y);
    coeffs->n.y1 = r1->y;
    coeffs->n.y0 = p1->y;
    coeffs->n.z3 = fixmul(2*F1_0,p1->z) - fixmul(2*F1_0,p4->z) + r1->z + r4->z;
    coeffs->n.z2 = fixmul(-3*F1_0,p1->z) + fixmul(3*F1_0,p4->z) - fixmul(2*F1_0,r1->z) - fixmul(1*F1_0,r4->z);
    coeffs->n.z1 = r1->z;
    coeffs->n.z0 = p1->z;

}

vms_vector evaluate_curve(vms_equation *coeffs, int degree, fix t) {
    fix t2, t3;
    vms_vector coord;

    if (degree!=3) con_printf(CON_CRITICAL," for Hermite Curves degree must be 3\n");

    t2 = fixmul(t,t); t3 = fixmul(t2,t);

    coord.x = fixmul(coeffs->n.x3,t3) + fixmul(coeffs->n.x2,t2) + fixmul(coeffs->n.x1,t) + coeffs->n.x0;
    coord.y = fixmul(coeffs->n.y3,t3) + fixmul(coeffs->n.y2,t2) + fixmul(coeffs->n.y1,t) + coeffs->n.y0;
    coord.z = fixmul(coeffs->n.z3,t3) + fixmul(coeffs->n.z2,t2) + fixmul(coeffs->n.z1,t) + coeffs->n.z0;

    return coord;
}


fix curve_dist(vms_equation *coeffs, int degree, fix t0, vms_vector *p0, fix dist) {
	 vms_vector coord;
    fix t, diff;

    if (degree!=3) con_printf(CON_CRITICAL," for Hermite Curves degree must be 3\n");

    for (t=t0;t<1*F1_0;t+=0.001*F1_0) {
        coord = evaluate_curve(coeffs, 3, t);
        diff = dist - vm_vec_dist(&coord, p0);
        if (diff<ACCURACY)   //&&(diff>-ACCURACY))
            return t;
    }
    return -1*F1_0;

}

void curve_dir(vms_equation *coeffs, int degree, fix t0, vms_vector *dir) {
    fix t2;

    if (degree!=3) con_printf(CON_CRITICAL," for Hermite Curves degree must be 3\n");

    t2 = fixmul(t0,t0);

    dir->x = fixmul(3*F1_0,fixmul(coeffs->n.x3,t2)) + fixmul(2*F1_0,fixmul(coeffs->n.x2,t0)) + coeffs->n.x1;
    dir->y = fixmul(3*F1_0,fixmul(coeffs->n.y3,t2)) + fixmul(2*F1_0,fixmul(coeffs->n.y2,t0)) + coeffs->n.y1;
    dir->z = fixmul(3*F1_0,fixmul(coeffs->n.z3,t2)) + fixmul(2*F1_0,fixmul(coeffs->n.z2,t0)) + coeffs->n.z1;
    vm_vec_normalize( dir );

}

void plot_parametric(vms_equation *coeffs, fix min_t, fix max_t, fix del_t) {
    vms_vector coord, dcoord;
    fix t, dt;

    gr_setcolor(15);
    gr_box(  75,  40, 325, 290 );
    gr_box(  75, 310, 325, 560 );
    gr_box( 475, 310, 725, 560 );
    //gr_pal_fade_in( grd_curscreen->pal );

    for (t=min_t;t<max_t-del_t;t+=del_t) {
        dt = t+del_t;

        coord = evaluate_curve(coeffs, 3, t);
        dcoord = evaluate_curve(coeffs, 3, dt);

        gr_setcolor(9);
        gr_line (  75*F1_0 + coord.x, 290*F1_0 - coord.z,  75*F1_0 + dcoord.x, 290*F1_0 - dcoord.z );
        gr_setcolor(10);
        gr_line (  75*F1_0 + coord.x, 560*F1_0 - coord.y,  75*F1_0 + dcoord.x, 560*F1_0 - dcoord.y );
        gr_setcolor(12);
        gr_line ( 475*F1_0 + coord.z, 560*F1_0 - coord.y, 475*F1_0 + dcoord.z, 560*F1_0 - dcoord.y );

    }

}


vms_vector *vm_vec_interp(vms_vector *result, vms_vector *v0, vms_vector *v1, fix scale) {
    vms_vector tvec;

	vm_vec_sub(&tvec, v1, v0);
    vm_vec_scale_add(result, v0, &tvec, scale);
    vm_vec_normalize(result);
    return result;
}

vms_vector p1, p4, r1, r4;
vms_vector r4t, r1save;

int generate_curve( fix r1scale, fix r4scale ) {
    vms_vector vec_dir, tvec;
    vms_vector coord,prev_point;
    vms_equation coeffs;
    fix enddist, nextdist;
    int firstsegflag;
    fix t, maxscale;
    fixang rangle, uangle;

    compute_center_point_on_side( &p1, Cursegp, Curside );

    switch( Curside ) {
        case WLEFT:
            extract_right_vector_from_segment(Cursegp, &r1);
            vm_vec_scale( &r1, -F1_0 );
            break;
        case WTOP:
            extract_up_vector_from_segment(Cursegp, &r1);
            break;
        case WRIGHT:
            extract_right_vector_from_segment(Cursegp, &r1);
            break;
        case WBOTTOM:
            extract_up_vector_from_segment(Cursegp, &r1);
            vm_vec_scale( &r1, -F1_0 );
            break;
        case WBACK:
            extract_forward_vector_from_segment(Cursegp, &r1);
            break;
        case WFRONT:
            extract_forward_vector_from_segment(Cursegp, &r1);
            vm_vec_scale( &r1, -F1_0 );
            break;
        }            

    compute_center_point_on_side( &p4, Markedsegp, Markedside );

    switch( Markedside ) {
        case WLEFT:
            extract_right_vector_from_segment(Markedsegp, &r4);
            extract_up_vector_from_segment(Markedsegp, &r4t);
            break;
        case WTOP:
            extract_up_vector_from_segment(Markedsegp, &r4);
            vm_vec_scale( &r4, -F1_0 );
            extract_forward_vector_from_segment(Markedsegp, &r4t);
            vm_vec_scale( &r4t, -F1_0 );
            break;
        case WRIGHT:
            extract_right_vector_from_segment(Markedsegp, &r4);
            vm_vec_scale( &r4, -F1_0 );
            extract_up_vector_from_segment(Markedsegp, &r4t);
            break;
        case WBOTTOM:
            extract_up_vector_from_segment(Markedsegp, &r4);
            extract_forward_vector_from_segment(Markedsegp, &r4t);
            break;
        case WBACK:
            extract_forward_vector_from_segment(Markedsegp, &r4);
            vm_vec_scale( &r4, -F1_0 );
            extract_up_vector_from_segment(Markedsegp, &r4t);
            break;
        case WFRONT:
            extract_forward_vector_from_segment(Markedsegp, &r4);
            extract_up_vector_from_segment(Markedsegp, &r4t);
            break;
        }

    r1save = r1;
    tvec = r1;
    vm_vec_scale(&r1,r1scale);
    vm_vec_scale(&r4,r4scale);

    create_curve( &p1, &p4, &r1, &r4, &coeffs );
    OriginalSeg = Cursegp;
    OriginalMarkedSeg = Markedsegp;
    OriginalSide = Curside;
    OriginalMarkedSide = Markedside;
    CurveNumSegs = 0;
    coord = prev_point = p1;

    t=0;
    firstsegflag = 1;
    enddist = F1_0; nextdist = 0;
    while ( enddist > fixmul( nextdist, 1.5*F1_0 )) {
            vms_matrix  rotmat,rotmat2;
			vms_vector	tdest;

            if (firstsegflag==1)
                firstsegflag=0;
            else
                extract_forward_vector_from_segment(Cursegp, &tvec);
            nextdist = vm_vec_mag(&tvec);                                   // nextdist := distance to next point
            t = curve_dist(&coeffs, 3, t, &prev_point, nextdist);               // t = argument at which function is forward vector magnitude units away from prev_point (in 3-space, not along curve)
            coord = evaluate_curve(&coeffs, 3, t);                                          // coord := point about forward vector magnitude units away from prev_point
            enddist = vm_vec_dist(&coord, &p4);                  // enddist := distance from current to end point, vec_dir used as a temporary variable
            //vm_vec_normalize(vm_vec_sub(&vec_dir, &coord, &prev_point));
            vm_vec_normalized_dir(&vec_dir, &coord, &prev_point);
        if (!med_attach_segment( Cursegp, &New_segment, Curside, AttachSide )) {
            med_extract_matrix_from_segment( Cursegp,&rotmat );                   // rotmat := matrix describing orientation of Cursegp
			vm_vec_rotate(&tdest,&vec_dir,&rotmat);	// tdest := vec_dir in reference frame of Cursegp
			vec_dir = tdest;

            vm_vector_2_matrix(&rotmat2,&vec_dir,NULL,NULL);

            med_rotate_segment( Cursegp, &rotmat2 );
			prev_point = coord;
            Curside = Side_opposite[AttachSide];

            CurveSegs[CurveNumSegs]=Cursegp;
            CurveNumSegs++;
        } else return 0;
	}

    extract_up_vector_from_segment( Cursegp,&tvec );
    uangle = vm_vec_delta_ang( &tvec, &r4t, &r4 );
    if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4;
    if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4;
    if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4;
    if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4;
    extract_right_vector_from_segment( Cursegp,&tvec );
    rangle = vm_vec_delta_ang( &tvec, &r4t, &r4 );
    if (rangle >= F1_0/8) rangle -= F1_0/4;
    if (rangle >= F1_0/8) rangle -= F1_0/4;
    if (rangle <= -F1_0/8) rangle += F1_0/4;
    if (rangle <= -F1_0/8) rangle += F1_0/4;

    if ((uangle != 0) && (rangle != 0)) {
        maxscale = CurveNumSegs*F1_0;
        generate_banked_curve(maxscale, coeffs);
    }

    if (CurveNumSegs) {
        med_form_bridge_segment( Cursegp, Side_opposite[AttachSide], Markedsegp, Markedside );
        CurveSegs[CurveNumSegs] = &Segments[ Markedsegp->children[Markedside] ];
        CurveNumSegs++;
	}

    Cursegp = OriginalSeg;
    Curside = OriginalSide;

	med_create_new_segment_from_cursegp();

	//warn_if_concave_segments();

    if (CurveNumSegs) return 1;
        else return 0;
}

void generate_banked_curve(fix maxscale, vms_equation coeffs) {
    vms_vector vec_dir, tvec, b4r4t;
    vms_vector coord,prev_point;
    fix enddist, nextdist;
    int firstsegflag;
    fixang rangle, uangle, angle, scaled_ang=0;
    fix t;

    if (CurveNumSegs) {

    extract_up_vector_from_segment( Cursegp,&b4r4t );
    uangle = vm_vec_delta_ang( &b4r4t, &r4t, &r4 );
    if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4;
    if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4;
    if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4;
    if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4;

    extract_right_vector_from_segment( Cursegp,&b4r4t );
    rangle = vm_vec_delta_ang( &b4r4t, &r4t, &r4 );
    if (rangle >= F1_0/8) rangle -= F1_0/4;
    if (rangle >= F1_0/8) rangle -= F1_0/4;
    if (rangle <= -F1_0/8) rangle += F1_0/4;
    if (rangle <= -F1_0/8) rangle += F1_0/4;

    angle = uangle;
    if (abs(rangle) < abs(uangle)) angle = rangle;

	delete_curve();

    coord = prev_point = p1;

#define MAGIC_NUM 0.707*F1_0

    if (maxscale)
        scaled_ang = fixdiv(angle,fixmul(maxscale,MAGIC_NUM));

    t=0; 
    tvec = r1save;
    firstsegflag = 1;
    enddist = F1_0; nextdist = 0;
    while ( enddist > fixmul( nextdist, 1.5*F1_0 )) {
            vms_matrix  rotmat,rotmat2;
            vms_vector  tdest;

            if (firstsegflag==1)
                firstsegflag=0;
            else
                extract_forward_vector_from_segment(Cursegp, &tvec);
            nextdist = vm_vec_mag(&tvec);                                   // nextdist := distance to next point
            t = curve_dist(&coeffs, 3, t, &prev_point, nextdist);               // t = argument at which function is forward vector magnitude units away from prev_point (in 3-space, not along curve)
            coord = evaluate_curve(&coeffs, 3, t);                                          // coord := point about forward vector magnitude units away from prev_point
            enddist = vm_vec_dist(&coord, &p4);                  // enddist := distance from current to end point, vec_dir used as a temporary variable
            //vm_vec_normalize(vm_vec_sub(&vec_dir, &coord, &prev_point));
            vm_vec_normalized_dir(&vec_dir, &coord, &prev_point);
        if (!med_attach_segment( Cursegp, &New_segment, Curside, AttachSide )) {
            med_extract_matrix_from_segment( Cursegp,&rotmat );                   // rotmat := matrix describing orientation of Cursegp
			vm_vec_rotate(&tdest,&vec_dir,&rotmat);	// tdest := vec_dir in reference frame of Cursegp
			vec_dir = tdest;
            vm_vec_ang_2_matrix(&rotmat2,&vec_dir,scaled_ang);

			med_rotate_segment( Cursegp, &rotmat2 );
			prev_point = coord;
            Curside = Side_opposite[AttachSide];

            CurveSegs[CurveNumSegs]=Cursegp;
            CurveNumSegs++;
        }
      }
    }
}


void delete_curve() {
    int i;

	for (i=0; i<CurveNumSegs; i++) {
        if (CurveSegs[i]->segnum != -1)
            med_delete_segment(CurveSegs[i]);
    }
    Markedsegp = OriginalMarkedSeg;
    Markedside = OriginalMarkedSide;
    Cursegp = OriginalSeg;
    Curside = OriginalSide;
	med_create_new_segment_from_cursegp();
    CurveNumSegs = 0;

	//editor_status("");
	//warn_if_concave_segments();
}

/*
void main() {
    vms_vector p1;
    vms_vector p4;
    vms_vector r1;
    vms_vector r4;
    vms_equation coeffs;
    float x, y, z;
    vms_vector test, test2, tvec;
    fix t, t0;
    fix distance, dist;
    int key;


    key_init();
    printf("Enter p1 (x,y,z): ");
    scanf("%f %f %f", &x, &y, &z);
    p1.x = x*F1_0; p1.y = y*F1_0; p1.z = z*F1_0;
    printf("Enter p4 (x,y,z): ");
    scanf("%f %f %f", &x, &y, &z);
    p4.x = x*F1_0; p4.y = y*F1_0; p4.z = z*F1_0;
    printf("Enter r1 <x,y,z>: ");
    scanf("%f %f %f", &x, &y, &z);
    r1.x = x*F1_0; r1.y = y*F1_0; r1.z = z*F1_0;
    printf("Enter r4 <x,y,z>: ");
    scanf("%f %f %f", &x, &y, &z);
    r4.x = x*F1_0; r4.y = y*F1_0; r4.z = z*F1_0;

    create_curve( &p1, &p4, &r1, &r4, &coeffs );

    printf("\nQ(t) = ");
    printf("x [%6.3f %6.3f %6.3f %6.3f]\n", f2fl(coeffs.n.x3), f2fl(coeffs.n.x2), f2fl(coeffs.n.x1), f2fl(coeffs.n.x0));
    printf("       y [%6.3f %6.3f %6.3f %6.3f]\n", f2fl(coeffs.n.y3), f2fl(coeffs.n.y2), f2fl(coeffs.n.y1), f2fl(coeffs.n.y0));
    printf("       z [%6.3f %6.3f %6.3f %6.3f]\n", f2fl(coeffs.n.z3), f2fl(coeffs.n.z2), f2fl(coeffs.n.z1), f2fl(coeffs.n.z0));

    printf("\nChecking direction vectors.\n");

    for (t=0*F1_0;t<1*F1_0;t+=0.1*F1_0) {
        curve_dir(&coeffs, 3, t, &test);
        printf(" t = %.3f  dir = <%6.3f, %6.3f, %6.3f >\n", f2fl(t), f2fl(test.x), f2fl(test.y), f2fl(test.z) );
    }

    printf("\nChecking distance function.\n");
    printf("Enter a distance: ");
    scanf("%f", &x);
    distance = x*F1_0;
    printf("Enter a (0<t<1) value: ");
    scanf("%f", &y);
    t0 = y*F1_0;

    gr_init(15);  // 800x600 mode
    plot_parametric(&coeffs, 0*F1_0, 1*F1_0, 0.05*F1_0);

    test = evaluate_curve(&coeffs, 3, t0);
    t = curve_dist(&coeffs, 3, t0, &test, distance);
    test2 = evaluate_curve(&coeffs, 3, t);

    dist = vm_vec_mag(vm_vec_sub(&tvec, &test, &test2));

    if (t != -1*F1_0) {
        gr_setcolor(14);
        gr_rect(  74+f2fl(test.x), 289-f2fl(test.z),  76+f2fl(test.x), 291-f2fl(test.z) );
        gr_rect(  74+f2fl(test.x), 559-f2fl(test.y),  76+f2fl(test.x), 561-f2fl(test.y) );
        gr_rect( 474+f2fl(test.z), 559-f2fl(test.y), 476+f2fl(test.z), 561-f2fl(test.y) );
        gr_setcolor(13);
        gr_rect(  74+f2fl(test2.x), 289-f2fl(test2.z),  76+f2fl(test2.x), 291-f2fl(test2.z) );
        gr_rect(  74+f2fl(test2.x), 559-f2fl(test2.y),  76+f2fl(test2.x), 561-f2fl(test2.y) );
        gr_rect( 474+f2fl(test2.z), 559-f2fl(test2.y), 476+f2fl(test2.z), 561-f2fl(test2.y) );
    }

    key = -1;
    while (1)
        if (key == KEY_ESC) break;
        else key = key_getch();

    gr_close();
    key_close();

    if (t == -1*F1_0) {
        printf("From t=%.3f to t=1.000, ", f2fl(t0));
        printf("two points separated by the distance %.3f\n do not exist on this curve.\n", x);
    }
    else {
        printf("\nThe distance between points at:\n");
        printf(" t0 = %.3f  ( %6.3f,%6.3f,%6.3f ) and\n", f2fl(t0), f2fl(test.x), f2fl(test.y), f2fl(test.z));
        printf(" t  = %.3f  ( %6.3f,%6.3f,%6.3f ) is:\n", f2fl(t), f2fl(test2.x), f2fl(test2.y), f2fl(test2.z));
        printf(" expected: %.3f\n", x);
        printf("  actual : %.3f\n", f2fl(dist) );
    }

}
*/