vspline 1.1.0
Generic C++11 Code for Uniform B-Splines
use_map.cc
Go to the documentation of this file.
1/************************************************************************/
2/* */
3/* vspline - a set of generic tools for creation and evaluation */
4/* of uniform b-splines */
5/* */
6/* Copyright 2015 - 2023 by Kay F. Jahnke */
7/* */
8/* The git repository for this software is at */
9/* */
10/* https://bitbucket.org/kfj/vspline */
11/* */
12/* Please direct questions, bug reports, and contributions to */
13/* */
14/* kfjahnke+vspline@gmail.com */
15/* */
16/* Permission is hereby granted, free of charge, to any person */
17/* obtaining a copy of this software and associated documentation */
18/* files (the "Software"), to deal in the Software without */
19/* restriction, including without limitation the rights to use, */
20/* copy, modify, merge, publish, distribute, sublicense, and/or */
21/* sell copies of the Software, and to permit persons to whom the */
22/* Software is furnished to do so, subject to the following */
23/* conditions: */
24/* */
25/* The above copyright notice and this permission notice shall be */
26/* included in all copies or substantial portions of the */
27/* Software. */
28/* */
29/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
30/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
31/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
32/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
33/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
34/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
35/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
36/* OTHER DEALINGS IN THE SOFTWARE. */
37/* */
38/************************************************************************/
39
40/*! \file use_map.cc
41
42 \brief test program for code in map.h
43
44 The program creates one gate type each of the types provided in map.h
45 over the interval [0,1]. Then it queries a value and uses the gates on
46 this value in turn, printing out the result.
47*/
48
49#include <iostream>
50#include <iomanip>
51#include <assert.h>
52#include <vspline/map.h>
53
55
56template < class gate_type >
57void test ( gate_type gx , double x , const char * mode )
58{
59 std::cout << mode << std::endl ;
60
61 auto tester = vspline::mapper < typename gate_type::in_type > ( gx ) ;
62
63 typedef double crd_type ;
64
65 const crd_type crd { x } ;
66 crd_type res ;
67
68 tester.eval ( crd , res ) ;
69
70 std::cout << "single-value operation:" << std::endl ;
71
72 std::cout << crd << " -> " << res << std::endl ;
73
74 if ( VSIZE > 1 )
75 {
77
78 crd_v inv ( crd ) ;
79 crd_v resv ;
80
81 tester.eval ( inv , resv ) ;
82 std::cout << "vectorized operation:" << std::endl
83 << inv << " -> " << resv << std::endl ;
84 }
85}
86
87int main ( int argc , char * argv[] )
88{
89 double x ;
90
91 std::cout << std::fixed << std::showpos << std::showpoint
92 << std::setprecision(5);
93
94 while ( std::cin.good() )
95 {
96 std::cout << "enter coordinate to map to [ 0.0 : 1.0 ]" << std::endl ;
97 std::cin >> x ;
98
99 if ( std::cin.eof() )
100 {
101 std::cout << std::endl ;
102 break ;
103 }
104
105 try
106 {
107 test ( vspline::reject ( 0.0 , 1.0 ) ,
108 x , "REJECT:" ) ;
109 }
110 catch ( vspline::out_of_bounds )
111 {
112 std::cout << "exception out_of_bounds" << std::endl ;
113 }
114 test ( vspline::clamp ( 0.0 , 1.0 , 0.0 , 1.0 ) ,
115 x , "CLAMP:" ) ;
116
117 test ( vspline::mirror ( 0.0 , 1.0 ) ,
118 x , "MIRROR:" ) ;
119
120 test ( vspline::periodic ( 0.0 , 1.0 ) ,
121 x , "PERIODIC:" ) ;
122 }
123}
vspline::vector_traits< coordinate_type >::type crd_v
Definition: mandelbrot.cc:66
code to handle out-of-bounds coordinates.
vspline::reject_gate< rc_type, _vsize > reject(rc_type lower, rc_type upper)
factory function to create a reject_gate type functor given a lower and upper limit for the allowed r...
Definition: map.h:164
vspline::periodic_gate< rc_type, _vsize > periodic(rc_type lower, rc_type upper)
factory function to create a periodic_gate type functor given a lower and upper limit for the allowed...
Definition: map.h:449
vspline::clamp_gate< rc_type, _vsize > clamp(rc_type lower, rc_type upper, rc_type lfix, rc_type rfix)
factory function to create a clamp_gate type functor given a lower and upper limit for the allowed ra...
Definition: map.h:241
vspline::mirror_gate< rc_type, _vsize > mirror(rc_type lower, rc_type upper)
factory function to create a mirror_gate type functor given a lower and upper limit for the allowed r...
Definition: map.h:362
mirror gate 'folds' coordinates into the range. From the infinite number of mirror images resulting f...
Definition: map.h:295
out_of_bounds is thrown by mapping mode REJECT for out-of-bounds coordinates this exception is left w...
Definition: common.h:317
with the definition of 'simd_traits', we can proceed to implement 'vector_traits': struct vector_trai...
Definition: vector.h:344
void test(gate_type gx, double x, const char *mode)
Definition: use_map.cc:57
int main(int argc, char *argv[])
Definition: use_map.cc:87
const int VSIZE
Definition: use_map.cc:54