@@ -308,47 +308,54 @@ class Bbox: public Py::PythonExtension<Bbox> {
308308// double. Also can serve as a lazy value evaluator
309309class Func : public Py ::PythonExtension<Func> {
310310public:
311-
311+ Func ( unsigned int type=IDENTITY ) : _type(type) {};
312312 static void init_type (void );
313313
314+ Py::Object str () { return Py::String (as_string ());}
315+ Py::Object repr () { return Py::String (as_string ());}
316+ std::string as_string () {
317+ if (_type==IDENTITY) return " Identity" ;
318+ else if (_type==LOG10) return " Log10" ;
319+ else throw Py::ValueError (" Unrecognized function type" );
320+ }
321+
322+ Py::Object set_type (const Py::Tuple &args) {
323+ args.verify_length (1 );
324+ _type = Py::Int (args[0 ]);
325+ return Py::Object ();
326+ }
327+
328+ Py::Object get_type (const Py::Tuple &args) {
329+ return Py::Int ((int )_type);
330+ }
314331
315332 // the python forward and inverse functions
316333 Py::Object map (const Py::Tuple &args);
317334 Py::Object inverse (const Py::Tuple &args);
318335
319336 // the api forward and inverse functions
320- virtual double operator ()(const double & )=0;
321- virtual double inverse_api (const double & )=0;
322-
323- };
324-
325- class Identity : public Func {
326- public:
327-
328- static void init_type (void );
329-
330- // the api forward and inverse functions
331- double operator ()(const double & x) {return x;}
332- double inverse_api (const double & x) {return x;}
333- };
334-
335- class Log : public Func {
336- public:
337-
338- static void init_type (void );
339-
340- double operator ()(const double & x) {
341- if (x<=0 ) {
342- throw Py::ValueError (" Cannot take log of nonpositive value" );
343-
337+ double operator ()(const double & x) {
338+ if (_type==IDENTITY) return x;
339+ else if (_type==LOG10) {
340+ if (x<=0 ) {
341+ throw Py::ValueError (" Cannot take log of nonpositive value" );
342+
343+ }
344+ return log10 (x);
344345 }
345- return log10 (x);
346- };
346+ else
347+ throw Py::ValueError (" Unrecognized function type" );
348+ }
349+ double inverse_api (const double & x) {
350+ if (_type==IDENTITY) return x;
351+ else if (_type==LOG10) return pow (10.0 , x);
352+ else throw Py::ValueError (" Unrecognized function type" );
347353
348- // the inverse mapping
349- double inverse_api (const double & x) {
350- return pow (10.0 , x);
351- };
354+ }
355+
356+ enum {IDENTITY, LOG10};
357+ private:
358+ unsigned int _type;
352359};
353360
354361class FuncXY : public Py ::PythonExtension<FuncXY> {
@@ -570,8 +577,6 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
570577
571578
572579 Func::init_type ();
573- Identity::init_type ();
574- Log::init_type ();
575580
576581 FuncXY::init_type ();
577582 PolarXY::init_type ();
@@ -589,11 +594,8 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
589594 " Bbox(ll, ur)" );
590595 add_varargs_method (" Interval" , &_transforms_module::new_interval,
591596 " Interval(val1, val2)" );
592-
593- add_varargs_method (" Identity" , &_transforms_module::new_identity,
594- " Identity())" );
595- add_varargs_method (" Log" , &_transforms_module::new_log,
596- " Log())" );
597+ add_varargs_method (" Func" , &_transforms_module::new_func,
598+ " Func(typecode)" );
597599
598600 add_varargs_method (" FuncXY" , &_transforms_module::new_funcxy,
599601 " FuncXY(funcx, funcy)" );
@@ -619,8 +621,8 @@ class _transforms_module : public Py::ExtensionModule<_transforms_module>
619621 Py::Object new_interval (const Py::Tuple &args);
620622 Py::Object new_affine (const Py::Tuple &args);
621623
622- Py::Object new_identity (const Py::Tuple &args);
623- Py::Object new_log ( const Py::Tuple &args);
624+ Py::Object new_func (const Py::Tuple &args);
625+
624626
625627 Py::Object new_funcxy (const Py::Tuple &args);
626628 Py::Object new_polarxy (const Py::Tuple &args);
0 commit comments