Added noarg item to example to show director default constructor.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5203 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-10-25 06:19:26 +00:00
commit 81c6cff05a
4 changed files with 69 additions and 2 deletions

View file

@ -18,3 +18,33 @@ void draw_shape_coverage( shape *s, int div_x, int div_y ) {
printf( "\n" );
}
}
void draw_depth_map( volume *v, int div_x, int div_y ) {
double i,j;
char depth_map_chars[] = "#*+;:,. ";
double lowbound, highbound;
double current = 0.0;
bool bounds_set = false;
for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
current = v->depth( j,i );
if( !bounds_set ) {
lowbound = current; highbound = current; bounds_set = true;
}
if( current < lowbound ) lowbound = current;
if( current > highbound ) highbound = current;
}
}
for( i = 0; i < 1.0; i += 1.0 / ((float)div_y) ) {
for( j = 0; j < 1.0; j += 1.0 / ((float)div_x) ) {
current = ((v->depth( j,i ) - lowbound) /
(highbound - lowbound)) * 8;
putchar(depth_map_chars[(int)current]);
}
putchar('\n');
}
}
double volume::depth( double x, double y ) { return 0.0; }

View file

@ -8,6 +8,12 @@ public:
virtual bool cover( double x, double y ); // does this shape cover this point?
};
class volume {
public:
virtual double depth( double x, double y );
};
extern void draw_shape_coverage( shape *s, int div_x, int div_y );
extern void draw_depth_map( volume *v, int div_x, int div_y );
#endif//EXAMPLE_H

View file

@ -2,7 +2,7 @@
%module(directors="1") example
#ifndef SWIGSEXP
%{
#include "example.h"
#include "example.h"
%}
#endif

View file

@ -35,11 +35,42 @@ let triangle_class pts ob meth args =
pts (get_float x_arg) (get_float y_arg))
| _ -> raise (Failure "cover needs two double arguments."))
| _ -> (invoke ob) meth args ;;
let dist (ax,ay) (bx,by) =
let dx = ax -. bx and dy = ay -. by in
sqrt ((dx *. dx) +. (dy *. dy))
let waveplot_depth events distance pt =
(List.fold_left (+.) 0.0
(List.map
(fun (x,y,d) ->
let t = dist pt (x,y) in
((sin t) /. t) *. d)
events)) +. distance
let waveplot_class events distance ob meth args =
match meth with
"depth" ->
(match args with
C_list [ x_arg ; y_arg ] ->
let xa = get_float x_arg and ya = get_float y_arg in
C_double
(waveplot_depth events distance
(get_float x_arg,get_float y_arg))
| _ -> raise (Failure "cover needs two double arguments."))
| _ -> (invoke ob) meth args ;;
let triangle =
new_derived_object
new_shape
(triangle_class ((0.0,0.0),(0.5,1.0),(1.0,0.6)))
C_void ;;
let waveplot =
new_derived_object
new_volume
(waveplot_class [ 0.01,0.01,3.0 ; 1.01,-2.01,1.5 ] 5.0)
C_void ;;
let _ = _draw_shape_coverage (C_list [ triangle ; C_int 60 ; C_int 20 ]) ;;
let _ = _draw_depth_map (C_list [ waveplot ; C_int 60 ; C_int 20 ]) ;;