aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 16:51:34 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 16:51:34 +0000
commit6232f4f5cb2302ee569f73ebe7528a51ac4277c1 (patch)
tree7937854e0346a6cb33008867af7c6b74340428c4
parentcbbf1113a6f90d0ab804bae416a2f61550f8b421 (diff)
code refactorisation, and functionality addition
svn path=/trunk/externals/pmpd/; revision=17110
-rw-r--r--pmpd_deprecated.c350
-rw-r--r--pmpd_stat.c680
-rw-r--r--pmpd_test.c344
3 files changed, 1374 insertions, 0 deletions
diff --git a/pmpd_deprecated.c b/pmpd_deprecated.c
new file mode 100644
index 0000000..15a969a
--- /dev/null
+++ b/pmpd_deprecated.c
@@ -0,0 +1,350 @@
+void pmpd_massesPosL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_mass];
+
+ for (i=0; i < x->nb_mass; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->mass[i].posX);
+ }
+ outlet_anything(x->main_outlet, gensym("massesPosL"),x->nb_mass , pos_list);
+}
+
+void pmpd_massesForcesL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_mass];
+
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->mass[i].forceX);
+ }
+ outlet_anything(x->main_outlet, gensym("massesForcesL"),x->nb_mass , pos_list);
+}
+
+void pmpd_massesSpeedsL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_mass];
+
+ for (i=0; i< x->nb_mass; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->mass[i].speedX);
+ }
+ outlet_anything(x->main_outlet, gensym("massesSpeedsL"),x->nb_mass , pos_list);
+}
+
+// --------------------------------------------
+
+void pmpd_linksPosL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_link];
+
+ for (i=0; i < x->nb_link; i++)
+ {
+ SETFLOAT(&(pos_list[i]),(x->link[i].mass1->posX + x->link[i].mass2->posX)/2);
+ }
+ outlet_anything(x->main_outlet, gensym("linksPosXL"),x->nb_link , pos_list);
+}
+
+void pmpd_linksLengthL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_link];
+
+ for (i=0; i < x->nb_link; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->link[i].mass2->posX - x->link[i].mass1->posX);
+ }
+ outlet_anything(x->main_outlet, gensym("linksLengthXL"),x->nb_link , pos_list);
+}
+
+void pmpd_linksPosSpeedL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_link];
+
+ for (i=0; i < x->nb_link; i++)
+ {
+ SETFLOAT(&(pos_list[i]),(x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2);
+ }
+ outlet_anything(x->main_outlet, gensym("linksPosSpeedXL"),x->nb_link , pos_list);
+}
+
+void pmpd_linksLengthSpeedL(t_pmpd *x)
+{
+ int i;
+ t_atom pos_list[x->nb_link];
+
+ for (i=0; i < x->nb_link; i++)
+ {
+ SETFLOAT(&(pos_list[i]),x->link[i].mass2->speedX - x->link[i].mass1->speedX);
+ }
+ outlet_anything(x->main_outlet, gensym("linksLengthSpeedXL"),x->nb_link , pos_list);
+}
+
+// --------------------------------------------
+
+void pmpd_massesPosMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ }
+
+ sommeX /= j;
+
+ SETFLOAT(&(mean[0]),sommeX);
+
+ outlet_anything(x->main_outlet, gensym("massesPosMean"),1 , mean);
+}
+
+void pmpd_massesPosStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ stdX += sqr(x->mass[i].posX-sommeX);
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ stdX += sqr(x->mass[i].posX-sommeX);
+ }
+ }
+
+ stdX = sqrt(stdX/j);
+
+ SETFLOAT(&(std_out[0]),stdX);
+
+ outlet_anything(x->main_outlet, gensym("massesPosStd"),1 , std_out);
+}
+
+void pmpd_massesForcesMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ }
+
+ sommeX /= j;
+
+ SETFLOAT(&(mean[0]),sommeX);
+
+ outlet_anything(x->main_outlet, gensym("massesForcesMean"),1 , mean);
+}
+
+void pmpd_massesForcesStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ stdX += sqr(x->mass[i].forceX-sommeX);
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ stdX += sqr(x->mass[i].forceX-sommeX);
+ }
+ }
+
+ stdX = sqrt(stdX/j);
+
+ SETFLOAT(&(std_out[0]),stdX);
+
+ outlet_anything(x->main_outlet, gensym("massesForcesStd"),1 , std_out);
+}
+
+void pmpd_massesSpeedsMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ }
+
+ sommeX /= j;
+
+ SETFLOAT(&(mean[0]),sommeX);
+
+ outlet_anything(x->main_outlet, gensym("massesSpeedsMean"),1 , mean);
+}
+
+void pmpd_massesSpeedsStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ stdX += sqr(x->mass[i].speedX-sommeX);
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ stdX += sqr(x->mass[i].speedX-sommeX);
+ }
+ }
+
+ stdX = sqrt(stdX/j);
+
+ SETFLOAT(&(std_out[0]),stdX);
+
+ outlet_anything(x->main_outlet, gensym("massesSpeedsStd"),1 , std_out);
+}
+
diff --git a/pmpd_stat.c b/pmpd_stat.c
new file mode 100644
index 0000000..bedd489
--- /dev/null
+++ b/pmpd_stat.c
@@ -0,0 +1,680 @@
+void pmpd_massPosMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ }
+
+ sommeX /= j;
+ SETFLOAT(&(mean[0]),sommeX);
+ outlet_anything(x->main_outlet, gensym("massPosMean"),1 , mean);
+}
+
+void pmpd_massPosStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ stdX += sqr(x->mass[i].posX-sommeX);
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].posX;
+ j++;
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ stdX += sqr(x->mass[i].posX-sommeX);
+ }
+ }
+
+ stdX = sqrt(stdX/j);
+ SETFLOAT(&(std_out[0]),stdX);
+ outlet_anything(x->main_outlet, gensym("massPosStd"),1 , std_out);
+}
+
+void pmpd_massForceMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ }
+
+ sommeX /= j;
+ SETFLOAT(&(mean[0]),sommeX);
+ outlet_anything(x->main_outlet, gensym("massForceMean"),1 , mean);
+}
+
+void pmpd_massForceStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ stdX += sqr(x->mass[i].forceX-sommeX);
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].forceX;
+ j++;
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ stdX += sqr(x->mass[i].forceX-sommeX);
+ }
+ }
+
+ stdX = sqrt(stdX/j);
+
+ SETFLOAT(&(std_out[0]),stdX);
+
+ outlet_anything(x->main_outlet, gensym("massForceStd"),1 , std_out);
+}
+
+void pmpd_massSpeedMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ }
+
+ sommeX /= j;
+
+ SETFLOAT(&(mean[0]),sommeX);
+
+ outlet_anything(x->main_outlet, gensym("massSpeedMean"),1 , mean);
+}
+
+void pmpd_massSpeedStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ stdX += sqr(x->mass[i].speedX-sommeX);
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ sommeX += x->mass[i].speedX;
+ j++;
+ }
+ sommeX /= j;
+ for (i=0; i< x->nb_mass; i++)
+ {
+ stdX += sqr(x->mass[i].speedX-sommeX);
+ }
+ }
+
+ stdX = sqrt(stdX/j);
+ SETFLOAT(&(std_out[0]),stdX);
+ outlet_anything(x->main_outlet, gensym("massSpeedStd"),1 , std_out);
+}
+
+//-----------------------------
+
+void pmpd_linkPosMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += (x->link[i].mass1->posX + x->link[i].mass2->posX)/2;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += (x->link[i].mass1->posX + x->link[i].mass2->posX)/2;
+ j++;
+ }
+ }
+
+ if ( j> 0)
+ {
+ sommeX /= j;
+ }
+
+ SETFLOAT(&(mean[0]),sommeX);
+ outlet_anything(x->main_outlet, gensym("linkPosMean"),1 , mean);
+}
+
+void pmpd_linkLengthMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX, somme;
+ t_int i,j;
+ t_atom mean[2];
+
+ sommeX = 0;
+ somme = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += x->link[i].mass1->posX - x->link[i].mass2->posX;
+ somme += x->link[i].distance;
+ j+=1;
+ }
+ }
+ }
+ else if (argc == 0)
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += x->link[i].mass1->posX - x->link[i].mass2->posX;
+ somme += x->link[i].distance;
+ j+=1;
+ }
+ }
+
+ if (j>0)
+ {
+ sommeX /= j;
+ somme /= j;
+ }
+
+ SETFLOAT(&(mean[0]),sommeX);
+ SETFLOAT(&(mean[1]),somme);
+ outlet_anything(x->main_outlet, gensym("linkLengthMean"),2 , mean);
+}
+
+void pmpd_linkPosSpeedMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += (x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += (x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2;
+ j++;
+ }
+ }
+
+ if (j>0)
+ {
+ sommeX /= j;
+ }
+
+ SETFLOAT(&(mean[0]),sommeX);
+ outlet_anything(x->main_outlet, gensym("linkPosSpeedMean"),1 , mean);
+}
+
+void pmpd_linkLengthSpeedMean(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX, tmp;
+ t_int i,j;
+ t_atom mean[1];
+
+ sommeX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += fabs(x->link[i].mass1->speedX - x->link[i].mass2->speedX);
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += fabs(x->link[i].mass1->speedX - x->link[i].mass2->speedX);
+ j++;
+ }
+ }
+
+ if (j>0)
+ {
+ sommeX /= j;
+ }
+
+ SETFLOAT(&(mean[0]),sommeX);
+ outlet_anything(x->main_outlet, gensym("linkLengthSpeedMean"),0 , mean);
+}
+
+void pmpd_linkPosStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_int i,j;
+ t_float stdX;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += (x->link[i].mass1->posX + x->link[i].mass2->posX)/2;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += (x->link[i].mass1->posX + x->link[i].mass2->posX)/2;
+ j++;
+ }
+ }
+
+ if (j>0)
+ {
+ sommeX /= j;
+ }
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ stdX += sqr((x->link[i].mass1->posX + x->link[i].mass2->posX)/2 - sommeX);
+ j+=1;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ stdX += sqr((x->link[i].mass1->posX + x->link[i].mass2->posX)/2 - sommeX);
+ j+=1;
+ }
+ }
+
+ if ( j > 0)
+ {
+ stdX = sqrt(stdX/j);
+ }
+
+ SETFLOAT(&(std_out[0]),stdX);
+ outlet_anything(x->main_outlet, gensym("linkPosStd"),1 , std_out);
+}
+
+void pmpd_linkLengthStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX, somme, tmp;
+ t_int i,j;
+ t_float stdX, std;
+ t_atom std_out[2];
+
+ sommeX = 0;
+ somme = 0;
+ stdX = 0;
+ std = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += x->link[i].mass1->posX - x->link[i].mass2->posX;
+ somme += x->link[i].distance;
+ j+=1;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += x->link[i].mass1->posX - x->link[i].mass2->posX;
+ somme += x->link[i].distance;
+ j+=1;
+ }
+ }
+
+ if ( j> 0)
+ {
+ sommeX /= j;
+ somme /= j;
+ }
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ stdX += sqr((x->link[i].mass1->posX - x->link[i].mass2->posX)-sommeX);
+ std += sqr(x->link[i].distance - somme);
+ j+=1;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ stdX += sqr((x->link[i].mass1->posX - x->link[i].mass2->posX) - sommeX);
+ std += sqr(x->link[i].distance - somme);
+ j+=1;
+ }
+ }
+
+ if ( j > 0)
+ {
+ stdX = sqrt(stdX/j);
+ }
+
+ SETFLOAT(&(std_out[0]),stdX);
+ SETFLOAT(&(std_out[1]),std);
+ outlet_anything(x->main_outlet, gensym("linkLengthStd"),2 , std_out);
+}
+
+void pmpd_linkPosSpeedStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX;
+ t_float stdX;
+ t_int i,j;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += (x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2;
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += (x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2;
+ j++;
+ }
+ }
+
+ if ( j> 0)
+ {
+ sommeX /= j;
+ }
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ stdX += sqr((x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2-sommeX);
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ stdX += sqr((x->link[i].mass1->speedX + x->link[i].mass2->speedX)/2-sommeX);
+ j++;
+ }
+ }
+
+ if ( j > 0)
+ {
+ stdX = sqrt(stdX/j);
+ }
+
+ SETFLOAT(&(std_out[0]),stdX);
+ outlet_anything(x->main_outlet, gensym("linkPosSpeedStd"),1 , std_out);
+}
+
+void pmpd_linkLengthSpeedStd(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_float sommeX, tmp;
+ t_float stdX;
+ t_int i,j;
+ t_atom std_out[1];
+
+ sommeX = 0;
+ stdX = 0;
+ j = 0;
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ sommeX += fabs(x->link[i].mass1->speedX - x->link[i].mass2->speedX);
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ sommeX += fabs(x->link[i].mass1->speedX - x->link[i].mass2->speedX);
+ j++;
+ }
+ }
+
+ if ( j> 0)
+ {
+ sommeX /= j;
+ }
+
+ if ( (argc >= 1) && (argv[0].a_type == A_SYMBOL) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if (atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ stdX += sqr(fabs(x->link[i].mass1->speedX - x->link[i].mass2->speedX) - sommeX);
+ j++;
+ }
+ }
+ }
+ else
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ stdX += sqr(fabs(x->link[i].mass1->speedX - x->link[i].mass2->speedX) - sommeX);
+ j++;
+ }
+ }
+
+ if ( j > 0)
+ {
+ stdX = sqrt(stdX/j);
+
+ }
+
+ SETFLOAT(&(std_out[0]),stdX);
+ outlet_anything(x->main_outlet, gensym("linkLengthSpeedStd"),1 , std_out);
+}
diff --git a/pmpd_test.c b/pmpd_test.c
new file mode 100644
index 0000000..7ccfbdc
--- /dev/null
+++ b/pmpd_test.c
@@ -0,0 +1,344 @@
+int test_1d_mass(int i, t_pmpd *x, int argc, t_atom *argv)
+{
+ t_float tmp, tmp2;
+ t_int j = 1;
+ while (j < argc)
+ {
+ if (argv[j].a_type != A_SYMBOL)
+ {
+ j++;
+ }
+ else
+ {
+ if (atom_getsymbolarg(j,argc,argv) == gensym("Id") )
+ {
+ if ( x->mass[i].Id != atom_getsymbolarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("posXSup") )
+ {
+ if ( x->mass[i].posX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("posXInf") )
+ {
+ if ( x->mass[i].posX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("speedXSup") )
+ {
+ if ( x->mass[i].speedX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("speedXInf") )
+ {
+ if ( x->mass[i].speedX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("speedSup") )
+ {
+ if ( x->mass[i].speedX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+= 2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("speedInf") )
+ {
+ if ( x->mass[i].speedX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("distanceInf"))
+ {
+ tmp = sqr(x->mass[i].posX - atom_getfloatarg(j+1,argc,argv));
+ if ( tmp >= sqr(atom_getfloatarg(j+2,argc,argv)) ) { return(0); }
+ j += 3;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("distanceSup"))
+ {
+ tmp = sqr(x->mass[i].posX - atom_getfloatarg(j+1,argc,argv));
+ if ( tmp < sqr(atom_getfloatarg(j+4,argc,argv)) ) { return(0); }
+ j += 3;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("massSup"))
+ {
+ if ( 1/ x->mass[i].invM < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j += 2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("massInf"))
+ {
+ if ( 1/ x->mass[i].invM >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j += 2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("forceSup") )
+ {
+ if ( x->mass[i].forceX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+= 2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("forceInf") )
+ {
+ if ( x->mass[i].forceX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+= 2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("forceXSup") )
+ {
+ if ( x->mass[i].forceX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("forceXInf") )
+ {
+ if ( x->mass[i].forceX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else
+ {
+ post("Option \"%s\" not reconized, stoping test",atom_getsymbolarg(j,argc,argv)->s_name);
+ return(-1);
+ }
+ }
+ }
+ return(1);
+}
+
+int test_1d_link(int i, t_pmpd *x, int argc, t_atom *argv)
+{
+ t_int j;
+ t_float tmp, tmp2;
+ j = 1;
+
+ while (j < argc)
+ {
+ if (argv[j].a_type != A_SYMBOL)
+ {
+ j++;
+ }
+ else
+ {
+ if (atom_getsymbolarg(j,argc,argv) == gensym("Id") )
+ {
+ if ( x->link[i].Id != atom_getsymbolarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("forceXSup") )
+ {
+ if ( x->link[i].forceX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("forceXInf") )
+ {
+ if ( x->link[i].forceX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("forceSup") )
+ {
+ if ( x->link[i].forceX < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("forceInf") )
+ {
+ if ( x->link[i].forceX >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if (atom_getsymbolarg(j,argc,argv) == gensym("lengthSup") )
+ {
+ if ( x->link[i].distance < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("lengthInf") )
+ {
+ if ( x->link[i].distance >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("lengthXInf") )
+ {
+ tmp = fabs(x->link[i].mass1->posX - x->link[i].mass2->posX);
+ if ( tmp >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("lengthXSup") )
+ {
+ tmp = fabs(x->link[i].mass1->posX - x->link[i].mass2->posX);
+ if ( tmp < atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("lengthYInf") )
+ {
+ tmp = fabs(x->link[i].mass1->posY - x->link[i].mass2->posY);
+ if ( tmp >= atom_getfloatarg(j+1,argc,argv) ) { return(0); }
+ j+=2;
+ }
+ else if ( atom_getsymbolarg(j,argc,argv) == gensym("connectedTo") )
+ {
+ if (argv[j+1].a_type == A_SYMBOL)
+ {
+ if (!( (x->link[i].mass1->Id == atom_getsymbolarg(j+1,argc,argv)) || (x->link[i].mass2->Id == atom_getsymbolarg(j+1,argc,argv)) ))
+ { return(0); }
+ j+=2;
+ }
+ else if (argv[j+1].a_type == A_FLOAT)
+ {
+ if (!( (x->link[i].mass1->num == atom_getfloatarg(j+1,argc,argv)) || (x->link[i].mass2->num == atom_getfloatarg(j+1,argc,argv)) ))
+ { return(0); }
+ j+=2;
+ }
+ else
+ {
+ post("bad argument for connectedTo");
+ j+=1;
+ }
+ }
+ else
+ {
+ post("Option \"%s\" not reconized, stoping test",atom_getsymbolarg(j,argc,argv)->s_name);
+ return(-1);
+ }
+ }
+ }
+ return(1);
+}
+
+//----------------------------------------------------------------------
+
+void pmpd_testLink(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_int i, tmp;
+ t_atom std_out[2];
+
+ SETSYMBOL(&(std_out[0]),atom_getsymbolarg(0,argc,argv));
+
+ for (i=0; i < x->nb_link; i++)
+ {
+ tmp=test_1d_link(i,x,argc,argv);
+ if (tmp == -1)
+ {
+ break;
+ }
+ else if (tmp)
+ {
+ SETFLOAT(&(std_out[1]),i);
+ outlet_anything(x->main_outlet, gensym("testLink"),2,std_out);
+ }
+ }
+}
+
+void pmpd_testMass(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ t_int i, tmp;
+ t_atom std_out[2];
+
+ SETSYMBOL(&(std_out[0]),atom_getsymbolarg(0,argc,argv));
+
+ for (i=0; i < x->nb_mass; i++)
+ {
+ tmp=test_1d_mass(i,x,argc,argv);
+ if (tmp == -1)
+ {
+ break;
+ }
+ else if (tmp)
+ {
+ SETFLOAT(&(std_out[1]),i);
+ outlet_anything(x->main_outlet, gensym("testMass"),2,std_out);
+ }
+ }
+}
+
+void pmpd_testLinkT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, vecsize, tmp;
+ t_garray *a;
+ t_word *vec;
+
+ if (argv[0].a_type == A_SYMBOL)
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_link;
+ taille_max = min(taille_max, vecsize);
+
+ for (i=0; i < taille_max; i++)
+ {
+ tmp = test_1d_link(i,x,argc,argv);
+ if (tmp == -1)
+ {
+ break;
+ }
+ vec[i].w_float = (t_float)tmp;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_testMassT(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, vecsize, tmp;
+ t_garray *a;
+ t_word *vec;
+
+ if (argv[0].a_type == A_SYMBOL)
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_mass;
+ taille_max = min(taille_max, vecsize);
+
+ for (i=0; i < taille_max; i++)
+ {
+ tmp = test_1d_mass(i,x,argc,argv);
+ if (tmp == -1)
+ {
+ break;
+ }
+ vec[i].w_float = (t_float)tmp;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
+void pmpd_testLinkL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, tmp;
+ t_atom list[x->nb_link+1];
+
+ for (i=0; i < x->nb_link;)
+ {
+ tmp=test_1d_link(i,x,argc,argv);
+ if (tmp == -1)
+ {
+ break;
+ }
+ SETFLOAT(&(list[i+1]), (t_float)tmp);
+ i++;
+ }
+ SETSYMBOL(&(list[0]),atom_getsymbolarg(0,argc,argv));
+ outlet_anything(x->main_outlet, gensym("testLink"),i+1 , list);
+}
+
+void pmpd_testMassL(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, tmp;
+ t_atom list[x->nb_mass+1];
+
+ for (i=0; i < x->nb_mass;)
+ {
+ tmp=test_1d_mass(i,x,argc,argv);
+ if (tmp == -1)
+ {
+ break;
+ }
+ SETFLOAT(&(list[i+1]), (t_float)tmp);
+ i++;
+ }
+ SETSYMBOL(&(list[0]),atom_getsymbolarg(0,argc,argv));
+ outlet_anything(x->main_outlet, gensym("testMass"),i+1 , list);
+}
+