Update procedures
[shapes.git] / source / constructorrepresentation.cc
blob23a740629b6aaaba19779b847d64663f7571d9c7
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #include "constructorrepresentation.h"
21 #include <sstream>
22 #include <cstdio>
24 using namespace Shapes;
27 std::string
28 Helpers::shapesFormat( double scalar )
30 std::ostringstream oss;
32 if( scalar < 0 )
34 oss << "~" ;
36 static char buf[25];
37 std::sprintf( buf, "%.5f", fabs( scalar ) );
38 oss << buf ;
39 return oss.str( );
42 std::string
43 Helpers::shapesFormat( Concrete::Length length )
45 std::ostringstream oss;
47 double val = Concrete::Length::offtype( length );
49 if( val < 0 )
51 oss << "~" ;
53 static char buf[25];
54 sprintf( buf, "%.5fbp", fabs( val ) );
55 oss << buf ;
56 return oss.str( );
59 std::string
60 Helpers::shapesFormat( Concrete::Coords2D coords )
62 std::ostringstream oss;
64 oss << "(" << Helpers::shapesFormat( coords.x_ ) << "," << Helpers::shapesFormat( coords.y_ ) << ")" ;
66 return oss.str( );
69 std::string
70 Helpers::shapesFormat( Concrete::Coords3D coords )
72 std::ostringstream oss;
74 oss << "(" << Helpers::shapesFormat( coords.x_ ) << "," << Helpers::shapesFormat( coords.y_ ) << "," << Helpers::shapesFormat( coords.z_ ) << ")" ;
76 return oss.str( );
79 std::string
80 Helpers::shapesFormat( Concrete::UnitFloatPair coords )
82 std::ostringstream oss;
84 oss << "(" << Helpers::shapesFormat( coords.x_ ) << "," << Helpers::shapesFormat( coords.y_ ) << ")" ;
86 return oss.str( );
89 std::string
90 Helpers::shapesFormat( Concrete::UnitFloatTriple coords )
92 std::ostringstream oss;
94 oss << "(" << Helpers::shapesFormat( coords.x_ ) << "," << Helpers::shapesFormat( coords.y_ ) << "," << Helpers::shapesFormat( coords.z_ ) << ")" ;
96 return oss.str( );