Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
coord.cpp
Go to the documentation of this file.
1/*
4 * Authors:
5 * Krzysztof KosiƄski <tweenk.pl@gmail.com>
6 *
7 * Copyright 2014 Authors
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it either under the terms of the GNU Lesser General Public
11 * License version 2.1 as published by the Free Software Foundation
12 * (the "LGPL") or, at your option, under the terms of the Mozilla
13 * Public License Version 1.1 (the "MPL"). If you do not alter this
14 * notice, a recipient may use your version of this file under either
15 * the MPL or the LGPL.
16 *
17 * You should have received a copy of the LGPL along with this library
18 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * You should have received a copy of the MPL along with this library
21 * in the file COPYING-MPL-1.1
22 *
23 * The contents of this file are subject to the Mozilla Public License
24 * Version 1.1 (the "License"); you may not use this file except in
25 * compliance with the License. You may obtain a copy of the License at
26 * http://www.mozilla.org/MPL/
27 *
28 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
29 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
30 * the specific language governing rights and limitations.
31 */
32
33// Most of the code in this file is derived from:
34// https://code.google.com/p/double-conversion/
35// The copyright notice for that code is attached below.
36//
37// Copyright 2010 the V8 project authors. All rights reserved.
38// Redistribution and use in source and binary forms, with or without
39// modification, are permitted provided that the following conditions are
40// met:
41//
42// * Redistributions of source code must retain the above copyright
43// notice, this list of conditions and the following disclaimer.
44// * Redistributions in binary form must reproduce the above
45// copyright notice, this list of conditions and the following
46// disclaimer in the documentation and/or other materials provided
47// with the distribution.
48// * Neither the name of Google Inc. nor the names of its
49// contributors may be used to endorse or promote products derived
50// from this software without specific prior written permission.
51//
52// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
64#include <2geom/coord.h>
65#include <cstdint>
66#include <cstdlib>
67#include <cassert>
68#include <cstring>
69#include <climits>
70#include <cstdarg>
71#include <cmath>
72
73#include <double-conversion/double-conversion.h>
74
75namespace Geom {
76
78{
79 static const double_conversion::DoubleToStringConverter conv(
80 double_conversion::DoubleToStringConverter::UNIQUE_ZERO,
81 "inf", "NaN", 'e', -3, 6, 0, 0);
82 std::string ret(' ', 32);
83 double_conversion::StringBuilder builder(&ret[0], 32);
84 conv.ToShortest(x, &builder);
85 ret.resize(builder.position());
86 return ret;
87}
88
90{
91 static const double_conversion::DoubleToStringConverter conv(
92 double_conversion::DoubleToStringConverter::UNIQUE_ZERO,
93 "inf", "NaN", 'e', -6, 21, 0, 0);
94 std::string ret(' ', 32);
95 double_conversion::StringBuilder builder(&ret[0], 32);
96 conv.ToShortest(x, &builder);
97 ret.resize(builder.position());
98 return ret;
99}
100
101Coord parse_coord(std::string const &s)
102{
103 static const double_conversion::StringToDoubleConverter conv(
104 double_conversion::StringToDoubleConverter::ALLOW_LEADING_SPACES |
105 double_conversion::StringToDoubleConverter::ALLOW_TRAILING_SPACES |
106 double_conversion::StringToDoubleConverter::ALLOW_SPACES_AFTER_SIGN,
107 0.0, nan(""), "inf", "NaN");
108 int dummy;
109 return conv.StringToDouble(s.c_str(), s.length(), &dummy);
110}
111
112} // namespace Geom
113
114/*
115 Local Variables:
116 mode:c++
117 c-file-style:"stroustrup"
118 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119 indent-tabs-mode:nil
120 fill-column:99
121 End:
122*/
123// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Integral and real coordinate types and some basic utilities.
double Coord
Floating point type used to store coordinates.
Definition coord.h:76
Various utility functions.
Definition affine.h:22
Coord parse_coord(std::string const &s)
Definition coord.cpp:101
std::string format_coord_nice(Coord x)
Definition coord.cpp:89
std::string format_coord_shortest(Coord x)
Definition coord.cpp:77
Glib::RefPtr< Gtk::Builder > builder