~ubuntu-branches/ubuntu/trusty/mapnik/trusty

« back to all changes in this revision

Viewing changes to include/mapnik/placement_finder.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2009-05-20 15:39:58 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090520153958-cf6z1ql9zva4y4dq
Tags: 0.6.0-1ubuntu1
* Merge from debian unstable (LP: #378819), remaining changes:
  - debian/control:
    + Change bdeps from python2.5-dev to python-all-dev (>= 2.5)
    + Change XS-Python-Version from 2.5 to >= 2.5
  - debian/rules:
    + Various changes to enable python2.5 and python2.6 builds
* debian/patches/libtool2_2.diff Dropped. Included upsteam.
* Removed quilt support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
   
42
42
   struct placement : boost::noncopyable
43
43
   { 
44
 
         placement(string_info & info_, 
45
 
                   //path_type & shape_path_,
46
 
                   shield_symbolizer const& sym);
 
44
         placement(string_info & info_, shield_symbolizer const& sym, bool has_dimensions_= false);
47
45
         
48
 
         placement(string_info & info_, 
49
 
                   //path_type & shape_path_,
50
 
                   text_symbolizer const& sym);
 
46
         placement(string_info & info_, text_symbolizer const& sym);
51
47
         
52
48
         ~placement();
53
 
        
54
 
         //helpers
55
 
         //std::pair<double, double> get_position_at_distance(double target_distance);
56
 
         //double get_total_distance();
57
 
 
 
49
  
58
50
         string_info & info;
59
 
         //path_type & shape_path;
60
 
         //double total_distance_; //cache for distance
61
51
    
62
52
         position displacement_;
63
53
         label_placement_e label_placement;
78
68
         double minimum_distance;
79
69
         bool avoid_edges;
80
70
         bool has_dimensions;
 
71
         bool allow_overlap;
81
72
         std::pair<double, double> dimensions;
82
73
   };
83
 
   
 
74
 
 
75
  
 
76
    
84
77
   template <typename DetectorT>
85
78
   class placement_finder : boost::noncopyable
86
79
   {
87
 
      public:
88
 
         placement_finder(DetectorT & detector);
89
 
         
90
 
         //Try place a single label at the given point
91
 
         void find_point_placement(placement & p, double, double);
92
 
         
93
 
         //Iterate over the given path, placing point labels with respect to label_spacing
94
 
         template <typename T>
95
 
         void find_point_placements(placement & p, T & path);
96
 
         
97
 
         //Iterate over the given path, placing line-following labels with respect to label_spacing
98
 
         template <typename T>
99
 
         void find_line_placements(placement & p, T & path);
100
 
         
101
 
         void clear();
102
 
         
103
 
      private:
104
 
         ///Helpers for find_line_placement
105
 
         
106
 
         ///Returns a possible placement on the given line, does not test for collisions
107
 
         //index: index of the node the current line ends on
108
 
         //distance: distance along the given index that the placement should start at, this includes the offset,
109
 
         //          as such it may be > or < the length of the current line, so this must be checked for
110
 
         //orientation: if set to != 0 the placement will be attempted with the given orientation
111
 
         //             otherwise it will autodetect the orientation.
112
 
         //             If >= 50% of the characters end up upside down, it will be retried the other way.
113
 
         //             RETURN: 1/-1 depending which way up the string ends up being.
114
 
         std::auto_ptr<placement_element> get_placement_offset(placement & p, const std::vector<vertex2d> & path_positions, const std::vector<double> & path_distances, int & orientation, unsigned index, double distance);
115
 
         
116
 
         ///Tests wether the given placement_element be placed without a collision
117
 
         // Returns true if it can
118
 
         // NOTE: This edits p.envelopes so it can be used afterwards (you must clear it otherwise)
119
 
         bool test_placement(placement & p, const std::auto_ptr<placement_element> & current_placement, const int & orientation);
120
 
         
121
 
         ///Does a line-circle intersect calculation
122
 
         // NOTE: Follow the strict pre conditions
123
 
         // Pre Conditions: x1,y1 is within radius distance of cx,cy. x2,y2 is outside radius distance of cx,cy
124
 
         //                 This means there is exactly one intersect point
125
 
         // Result is returned in ix, iy
126
 
         void find_line_circle_intersection(
127
 
            const double &cx, const double &cy, const double &radius, 
128
 
            const double &x1, const double &y1, const double &x2, const double &y2, 
129
 
            double &ix, double &iy);
130
 
         
131
 
         ///General Internals
132
 
         
133
 
         void update_detector(placement & p);
134
 
         
135
 
         DetectorT & detector_;
136
 
         Envelope<double> const& dimensions_;
 
80
   public:
 
81
      placement_finder(DetectorT & detector);
 
82
         
 
83
      //Try place a single label at the given point
 
84
      void find_point_placement(placement & p, double pos_x, double pos_y, vertical_alignment_e = MIDDLE);
 
85
         
 
86
      //Iterate over the given path, placing point labels with respect to label_spacing
 
87
      template <typename T>
 
88
      void find_point_placements(placement & p, T & path);
 
89
      
 
90
      //Iterate over the given path, placing line-following labels with respect to label_spacing
 
91
      template <typename T>
 
92
      void find_line_placements(placement & p, T & path);
 
93
      
 
94
      void update_detector(placement & p);
 
95
      
 
96
      void clear();
 
97
      
 
98
   private:
 
99
      ///Helpers for find_line_placement
 
100
      
 
101
      ///Returns a possible placement on the given line, does not test for collisions
 
102
      //index: index of the node the current line ends on
 
103
      //distance: distance along the given index that the placement should start at, this includes the offset,
 
104
      //          as such it may be > or < the length of the current line, so this must be checked for
 
105
      //orientation: if set to != 0 the placement will be attempted with the given orientation
 
106
      //             otherwise it will autodetect the orientation.
 
107
      //             If >= 50% of the characters end up upside down, it will be retried the other way.
 
108
      //             RETURN: 1/-1 depending which way up the string ends up being.
 
109
      std::auto_ptr<placement_element> get_placement_offset(placement & p, 
 
110
                                                            const std::vector<vertex2d> & path_positions, 
 
111
                                                            const std::vector<double> & path_distances, 
 
112
                                                            int & orientation, unsigned index, double distance);
 
113
      
 
114
      ///Tests wether the given placement_element be placed without a collision
 
115
      // Returns true if it can
 
116
      // NOTE: This edits p.envelopes so it can be used afterwards (you must clear it otherwise)
 
117
      bool test_placement(placement & p, const std::auto_ptr<placement_element> & current_placement, const int & orientation);
 
118
      
 
119
      ///Does a line-circle intersect calculation
 
120
      // NOTE: Follow the strict pre conditions
 
121
      // Pre Conditions: x1,y1 is within radius distance of cx,cy. x2,y2 is outside radius distance of cx,cy
 
122
      //                 This means there is exactly one intersect point
 
123
      // Result is returned in ix, iy
 
124
      void find_line_circle_intersection(
 
125
         const double &cx, const double &cy, const double &radius, 
 
126
         const double &x1, const double &y1, const double &x2, const double &y2, 
 
127
         double &ix, double &iy);
 
128
      
 
129
      ///General Internals
 
130
      
 
131
      
 
132
         
 
133
      DetectorT & detector_;
 
134
      Envelope<double> const& dimensions_;
137
135
   };  
138
136
}
139
137