Max 5 API Reference
00001 /* 00002 * jit.distance.chebychev.c 00003 * 00004 * Copyright 2001-2005 - Cycling '74 00005 * Derek Gerstmann - derek@cycling74.com 00006 * 00007 * Functor for calculating chebychev distance 00008 * 00009 * The Chebychev distance between two points is the maximum distance between 00010 * the points in any single dimension. Since the functor object expects 00011 * to recieve a delta for each dimension, distance is the max delta of all 00012 * dimensions. 00013 * 00014 */ 00015 00016 #include "jit.common.h" 00017 #include "jit.functor.h" 00018 00019 // -------------------------------------------------------------------------- 00020 00021 typedef struct _jit_functor_distance_chebychev 00022 { 00023 t_jit_object ob; 00024 00025 } t_jit_functor_distance_chebychev; 00026 00027 // -------------------------------------------------------------------------- 00028 00029 t_jit_object *jit_functor_distance_chebychev_new(void); 00030 t_jit_err jit_functor_distance_chebychev_free(t_jit_functor_distance_chebychev *x); 00031 t_jit_err jit_functor_distance_chebychev_recalc(t_jit_functor_distance_chebychev *x); 00032 00033 long jit_functor_distance_chebychev_eval_fixed(t_jit_functor_distance_chebychev *x, long dimcount, long *vals); 00034 float jit_functor_distance_chebychev_eval_float32(t_jit_functor_distance_chebychev *x, long dimcount, float *vals); 00035 double jit_functor_distance_chebychev_eval_float64(t_jit_functor_distance_chebychev *x, long dimcount, double *vals); 00036 00037 void jit_functor_distance_chebychev_fixlut_init(void); 00038 00039 t_class *_jit_functor_distance_chebychev_class; 00040 00041 // -------------------------------------------------------------------------- 00042 00043 t_jit_err jit_functor_distance_chebychev_init(void) 00044 { 00045 t_jit_object *attr; 00046 00047 // create class 00048 _jit_functor_distance_chebychev_class = jit_class_new("jit_functor_distance_chebychev", 00049 (method)jit_functor_distance_chebychev_new,(method)jit_functor_distance_chebychev_free, 00050 sizeof(t_jit_functor_distance_chebychev),0L); 00051 00052 // add evaluation methods 00053 jit_class_addmethod(_jit_functor_distance_chebychev_class, 00054 (method)jit_functor_distance_chebychev_eval_fixed, "evalfixed", A_CANT, 0L); 00055 jit_class_addmethod(_jit_functor_distance_chebychev_class, 00056 (method)jit_functor_distance_chebychev_eval_float32, "evalfloat32", A_CANT, 0L); 00057 jit_class_addmethod(_jit_functor_distance_chebychev_class, 00058 (method)jit_functor_distance_chebychev_eval_float64, "evalfloat64", A_CANT, 0L); 00059 00060 // add to functor registry 00061 jit_functor_setup_class(_jit_functor_distance_chebychev_class,"distance","chebychev"); 00062 jit_class_register(_jit_functor_distance_chebychev_class); 00063 00064 return JIT_ERR_NONE; 00065 } 00066 00067 // -------------------------------------------------------------------------- 00068 00069 t_jit_object *jit_functor_distance_chebychev_new(void) 00070 { 00071 t_jit_functor_distance_chebychev *x; 00072 00073 if (x = (t_jit_functor_distance_chebychev *)jit_object_alloc(_jit_functor_distance_chebychev_class)) { 00074 // initialization 00075 jit_functor_distance_chebychev_recalc(x); 00076 } 00077 00078 return (t_jit_object *)x; 00079 } 00080 00081 t_jit_err jit_functor_distance_chebychev_free(t_jit_functor_distance_chebychev *x) 00082 { 00083 return JIT_ERR_NONE; 00084 } 00085 00086 // -------------------------------------------------------------------------- 00087 00088 t_jit_err jit_functor_distance_chebychev_recalc( 00089 t_jit_functor_distance_chebychev *x) 00090 { 00091 // calculate intermediary values for efficiency 00092 return JIT_ERR_NONE; 00093 } 00094 00095 long jit_functor_distance_chebychev_eval_fixed( 00096 t_jit_functor_distance_chebychev *x, long dimcount, long *vals) 00097 { 00098 return jit_functor_eval_fixed_with_float32((t_jit_object *)x,dimcount,vals, 00099 (t_jit_functor_float32_sig)jit_functor_distance_chebychev_eval_float32); 00100 } 00101 00102 float jit_functor_distance_chebychev_eval_float32( 00103 t_jit_functor_distance_chebychev *x, long dimcount, float *vals) 00104 { 00105 long i; 00106 float rval = ABS(vals[0]); 00107 00108 for (i = 1; i < dimcount; i++) { 00109 rval = MAX(rval, ABS(vals[i])); 00110 } 00111 00112 return rval; 00113 } 00114 00115 double jit_functor_distance_chebychev_eval_float64( 00116 t_jit_functor_distance_chebychev *x, long dimcount, double *vals) 00117 { 00118 long i; 00119 double rval = ABS(vals[0]); 00120 00121 for (i = 1; i < dimcount; i++) { 00122 rval = MAX(rval, ABS(vals[i])); 00123 } 00124 00125 return rval; 00126 } 00127 00128 // --------------------------------------------------------------------------
Copyright © 2008, Cycling '74