move normalize_angle to utils
This commit is contained in:
parent
187a42f006
commit
87cc1347c7
4 changed files with 91 additions and 19 deletions
35
include/mapnik/util/math.hpp
Normal file
35
include/mapnik/util/math.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef MAPNIK_MATH_HPP
|
||||
#define MAPNIK_MATH_HPP
|
||||
|
||||
#include <mapnik/config.hpp>
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
MAPNIK_DECL double normalize_angle(double angle);
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
|
@ -238,6 +238,7 @@ source = Split(
|
|||
renderer_common.cpp
|
||||
renderer_common/render_pattern.cpp
|
||||
renderer_common/process_group_symbolizer.cpp
|
||||
math.cpp
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
48
src/math.cpp
Normal file
48
src/math.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* This file is part of Mapnik (c++ mapping toolkit)
|
||||
*
|
||||
* Copyright (C) 2015 Artem Pavlenko
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
// mapnik
|
||||
#include <mapnik/util/math.hpp>
|
||||
|
||||
// stl
|
||||
#include <cmath>
|
||||
|
||||
namespace mapnik {
|
||||
|
||||
namespace util {
|
||||
|
||||
double normalize_angle(double angle)
|
||||
{
|
||||
while (angle >= M_PI)
|
||||
{
|
||||
angle -= 2.0 * M_PI;
|
||||
}
|
||||
while (angle < -M_PI)
|
||||
{
|
||||
angle += 2.0 * M_PI;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
} // end namespace util
|
||||
|
||||
} // end namespace mapnik
|
|
@ -30,6 +30,7 @@
|
|||
#include <mapnik/text/text_properties.hpp>
|
||||
#include <mapnik/text/glyph_positions.hpp>
|
||||
#include <mapnik/vertex_cache.hpp>
|
||||
#include <mapnik/util/math.hpp>
|
||||
|
||||
// agg
|
||||
#include "agg_conv_clip_polyline.h"
|
||||
|
@ -95,11 +96,11 @@ text_upright_e placement_finder::simplify_upright(text_upright_e upright, double
|
|||
{
|
||||
if (upright == UPRIGHT_AUTO)
|
||||
{
|
||||
return (std::fabs(normalize_angle(angle)) > 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
|
||||
return (std::fabs(util::normalize_angle(angle)) > 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
|
||||
}
|
||||
if (upright == UPRIGHT_AUTO_DOWN)
|
||||
{
|
||||
return (std::fabs(normalize_angle(angle)) < 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
|
||||
return (std::fabs(util::normalize_angle(angle)) < 0.5*M_PI) ? UPRIGHT_LEFT : UPRIGHT_RIGHT;
|
||||
}
|
||||
if (upright == UPRIGHT_LEFT_ONLY)
|
||||
{
|
||||
|
@ -260,10 +261,12 @@ bool placement_finder::single_line_placement(vertex_cache &pp, text_upright_e or
|
|||
}
|
||||
current_cluster = glyph.char_index;
|
||||
// Only calculate new angle at the start of each cluster!
|
||||
angle = normalize_angle(off_pp.angle(sign * layout.cluster_width(current_cluster)));
|
||||
// Y axis is inverted.
|
||||
// See note about coordinate systems in placement_finder::find_point_placement().
|
||||
angle = -util::normalize_angle(off_pp.angle(sign * layout.cluster_width(current_cluster)));
|
||||
rot.init(angle);
|
||||
if ((text_props_->max_char_angle_delta > 0) && (last_cluster_angle != 999) &&
|
||||
std::fabs(normalize_angle(angle-last_cluster_angle)) > text_props_->max_char_angle_delta)
|
||||
std::fabs(util::normalize_angle(angle - last_cluster_angle)) > text_props_->max_char_angle_delta)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -328,21 +331,6 @@ void placement_finder::path_move_dx(vertex_cache & pp, double dx)
|
|||
if (!pp.move(dx)) pp.restore_state(state);
|
||||
}
|
||||
|
||||
double placement_finder::normalize_angle(double angle)
|
||||
{
|
||||
while (angle >= M_PI)
|
||||
{
|
||||
angle -= 2.0 * M_PI;
|
||||
}
|
||||
while (angle < -M_PI)
|
||||
{
|
||||
angle += 2.0 * M_PI;
|
||||
}
|
||||
// y axis is inverted.
|
||||
// See note about coordinate systems in placement_finder::find_point_placement().
|
||||
return -angle;
|
||||
}
|
||||
|
||||
double placement_finder::get_spacing(double path_length, double layout_width) const
|
||||
{
|
||||
int num_labels = 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue