1. removed dependency on boost_serialization ( we don't really need it) at this time.

2. coord and envelope operator<< to use 16 digit precision.
3. added 'inside polygon' method impl.
This commit is contained in:
Artem Pavlenko 2006-08-20 18:49:22 +00:00
parent 0bb121a747
commit 72fae1daa1
11 changed files with 516 additions and 595 deletions

View file

@ -76,11 +76,6 @@ C_LIBSHEADERS = [
BOOST_LIBSHEADERS = [ BOOST_LIBSHEADERS = [
['thread', 'boost/thread/mutex.hpp', True], ['thread', 'boost/thread/mutex.hpp', True],
['filesystem', 'boost/filesystem/operations.hpp', True], ['filesystem', 'boost/filesystem/operations.hpp', True],
['serialization', ['boost/archive/text_oarchive.hpp',
'boost/archive/text_iarchive.hpp',
'boost/archive/xml_oarchive.hpp',
'boost/archive/xml_iarchive.hpp'], True
],
['regex', 'boost/regex.hpp', True], ['regex', 'boost/regex.hpp', True],
['program_options', 'boost/program_options.hpp', False] ['program_options', 'boost/program_options.hpp', False]
] ]

View file

@ -26,6 +26,7 @@
#define COORD_HPP #define COORD_HPP
#include <iostream> #include <iostream>
#include <iomanip>
#include <sstream> #include <sstream>
namespace mapnik namespace mapnik
@ -113,7 +114,8 @@ namespace mapnik
std::basic_ostringstream<charT,traits> s; std::basic_ostringstream<charT,traits> s;
s.copyfmt(out); s.copyfmt(out);
s.width(0); s.width(0);
s<<"coord2("<<c.x<<","<<c.y<<")"; s << "coord2(" << std::setprecision(16)
<< c.x << "," << c.y<< ")";
out << s.str(); out << s.str();
return out; return out;
} }
@ -126,7 +128,8 @@ namespace mapnik
std::basic_ostringstream<charT,traits> s; std::basic_ostringstream<charT,traits> s;
s.copyfmt(out); s.copyfmt(out);
s.width(0); s.width(0);
s<<"coord3("<<c.x<<","<<c.y<<","<<c.z<<")"; s << "coord3(" << std::setprecision(16)
<< c.x << "," << c.y<< "," << c.z<<")";
out << s.str(); out << s.str();
return out; return out;
} }

View file

@ -26,6 +26,7 @@
#define ENVELOPE_HPP #define ENVELOPE_HPP
#include "config.hpp" #include "config.hpp"
#include <iomanip>
#include "coord.hpp" #include "coord.hpp"
namespace mapnik namespace mapnik
@ -77,7 +78,9 @@ namespace mapnik
std::basic_ostringstream<charT,traits> s; std::basic_ostringstream<charT,traits> s;
s.copyfmt(out); s.copyfmt(out);
s.width(0); s.width(0);
s<<"Envelope("<<e.minx()<<","<<e.miny()<<","<<e.maxx()<<","<<e.maxy()<<")"; s <<"Envelope(" << std::setprecision(16)
<< e.minx() << "," << e.miny() <<","
<< e.maxx() << "," << e.maxy() <<")";
out << s.str(); out << s.str();
return out; return out;
} }

View file

@ -87,19 +87,21 @@ namespace mapnik
inline bool point_inside_path(double x,double y,Iter start,Iter end) inline bool point_inside_path(double x,double y,Iter start,Iter end)
{ {
bool inside=false; bool inside=false;
double x0=start->x; double x0=boost::get<0>(*start);
double y0=start->y; double y0=boost::get<1>(*start);
double x1,y1; double x1,y1;
while (++start!=end) while (++start!=end)
{ {
if (start->cmd == SEG_MOVETO) if ( boost::get<2>(*start) == SEG_MOVETO)
{ {
x0=start->x; x0 = boost::get<0>(*start);
y0=start->y; y0 = boost::get<1>(*start);
continue; continue;
} }
x1=start->x; x1=boost::get<0>(*start);
y1=start->y; y1=boost::get<1>(*start);
if ((((y1 <= y) && (y < y0)) || if ((((y1 <= y) && (y < y0)) ||
((y0 <= y) && (y < y1))) && ((y0 <= y) && (y < y1))) &&
( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1)) ( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))

View file

@ -149,7 +149,7 @@ namespace mapnik
virtual ~point() {} virtual ~point() {}
}; };
template <typename T, template <typename> class Container=vertex_vector> template <typename T, template <typename> class Container=vertex_vector2>
class polygon : public geometry<T> class polygon : public geometry<T>
{ {
typedef geometry<T> geometry_base; typedef geometry<T> geometry_base;
@ -246,8 +246,9 @@ namespace mapnik
bool hit_test(value_type x,value_type y) const bool hit_test(value_type x,value_type y) const
{ {
return false; return point_inside_path(x,y,cont_.begin(),cont_.end());
} }
void set_capacity(size_t size) void set_capacity(size_t size)
{ {
cont_.set_capacity(size); cont_.set_capacity(size);

View file

@ -15,7 +15,8 @@
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * #include <boost/serialization/serialization.hpp>
License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* *
*****************************************************************************/ *****************************************************************************/
@ -28,27 +29,11 @@
#include "feature.hpp" #include "feature.hpp"
#include "datasource.hpp" #include "datasource.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/serialization/serialization.hpp>
namespace mapnik namespace mapnik
{ {
class MAPNIK_DECL Layer class MAPNIK_DECL Layer
{ {
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive & ar, const unsigned int /*version*/)
{
ar & boost::serialization::make_nvp("name",name_)
& boost::serialization::make_nvp("title",title_)
& boost::serialization::make_nvp("abstract",abstract_)
& boost::serialization::make_nvp("params",params_)
& boost::serialization::make_nvp("min_zoom",minZoom_)
& boost::serialization::make_nvp("max_zoom",maxZoom_)
& boost::serialization::make_nvp("active",active_)
& boost::serialization::make_nvp("selectable",selectable_)
& boost::serialization::make_nvp("styles",styles_)
;
}
parameters params_; parameters params_;
std::string name_; std::string name_;
std::string title_; std::string title_;
@ -102,10 +87,4 @@ namespace mapnik
}; };
} }
BOOST_CLASS_IMPLEMENTATION(std::vector<std::string>, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(std::vector<std::string>, boost::serialization::track_never)
BOOST_CLASS_IMPLEMENTATION(mapnik::Layer, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::Layer, boost::serialization::track_never)
#endif //LAYER_HPP #endif //LAYER_HPP

View file

@ -24,8 +24,6 @@
#ifndef MAP_HPP #ifndef MAP_HPP
#define MAP_HPP #define MAP_HPP
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/vector.hpp>
#include "feature_type_style.hpp" #include "feature_type_style.hpp"
namespace mapnik namespace mapnik
@ -34,16 +32,6 @@ namespace mapnik
class MAPNIK_DECL Map class MAPNIK_DECL Map
{ {
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive & ar, const unsigned int /*version*/)
{
ar & boost::serialization::make_nvp("width",width_)
& boost::serialization::make_nvp("height",height_)
& boost::serialization::make_nvp("srid",srid_)
& boost::serialization::make_nvp("layers",layers_);
}
static const unsigned MIN_MAPSIZE=16; static const unsigned MIN_MAPSIZE=16;
static const unsigned MAX_MAPSIZE=2048; static const unsigned MAX_MAPSIZE=2048;
unsigned width_; unsigned width_;
@ -94,10 +82,4 @@ namespace mapnik
}; };
} }
BOOST_CLASS_IMPLEMENTATION(std::vector<mapnik::Layer>, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(std::vector<mapnik::Layer>, boost::serialization::track_never)
BOOST_CLASS_IMPLEMENTATION(mapnik::Map, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::Map, boost::serialization::track_never)
#endif //MAP_HPP #endif //MAP_HPP

View file

@ -79,8 +79,6 @@
namespace mapnik namespace mapnik
{ {
void MAPNIK_DECL save_to_xml(Map const& map,const char* filename);
void MAPNIK_DECL load_from_xml(Map & map, const char * filename);
} }
#endif //MAPNIK_HPP #endif //MAPNIK_HPP

View file

@ -44,36 +44,6 @@ namespace mapnik
class parameters : public param_map class parameters : public param_map
{ {
friend class boost::serialization::access;
template <typename Archive>
void save(Archive & ar, const unsigned int /*version*/) const
{
const size_t size = param_map::size();
ar & boost::serialization::make_nvp("count",size);
param_map::const_iterator itr;
for (itr=param_map::begin();itr!=param_map::end();++itr)
{
ar & boost::serialization::make_nvp("name",itr->first);
ar & boost::serialization::make_nvp("value",itr->second);
}
}
template <typename Archive>
void load(Archive & ar, const unsigned int /*version*/)
{
size_t size;
ar & boost::serialization::make_nvp("size",size);
for (size_t i=0;i<size;++i)
{
std::string name;
std::string value;
ar & boost::serialization::make_nvp("name",name);
ar & boost::serialization::make_nvp("value",value);
param_map::insert(make_pair(name,value));
}
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
public: public:
parameters() {} parameters() {}
@ -89,10 +59,4 @@ namespace mapnik
}; };
} }
BOOST_CLASS_IMPLEMENTATION(mapnik::parameter, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::parameter, boost::serialization::track_never)
BOOST_CLASS_IMPLEMENTATION(mapnik::parameters, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::parameters, boost::serialization::track_never)
#endif //PARAMS_HPP #endif //PARAMS_HPP

View file

@ -150,6 +150,7 @@ namespace mapnik
{ {
typedef typename T::type value_type; typedef typename T::type value_type;
typedef boost::tuple<value_type,value_type,char> vertex_type; typedef boost::tuple<value_type,value_type,char> vertex_type;
typedef typename std::vector<vertex_type>::const_iterator const_iterator;
vertex_vector2() {} vertex_vector2() {}
unsigned size() const unsigned size() const
{ {
@ -169,6 +170,16 @@ namespace mapnik
return boost::get<2>(c); return boost::get<2>(c);
} }
const_iterator begin() const
{
return cont_.begin();
}
const_iterator end() const
{
return cont_.end();
}
void transform_at(unsigned pos,const CoordTransform& t) void transform_at(unsigned pos,const CoordTransform& t)
{ {
if (pos >= cont_.size()) return; if (pos >= cont_.size()) return;

View file

@ -23,27 +23,10 @@
//$Id$ //$Id$
#include <fstream> #include <fstream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include "mapnik.hpp" #include "mapnik.hpp"
namespace mapnik namespace mapnik
{ {
void save_to_xml(Map const& m,const char* filename)
{
std::ofstream ofs(filename);
assert(ofs.good());
boost::archive::xml_oarchive oa(ofs);
oa << boost::serialization::make_nvp("map",m);
}
void load_from_xml(Map & m,const char* filename)
{
std::ifstream ifs(filename);
assert(ifs.good());
boost::archive::xml_iarchive ia(ifs);
ia >> boost::serialization::make_nvp("map",m);
}
} }