scan_arbitrary.hpp 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857
  1. /*
  2. Copyright 2008 Intel Corporation
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. #ifndef BOOST_POLYGON_SCAN_ARBITRARY_HPP
  8. #define BOOST_POLYGON_SCAN_ARBITRARY_HPP
  9. #ifdef BOOST_POLYGON_DEBUG_FILE
  10. #include <fstream>
  11. #endif
  12. #include "polygon_sort_adaptor.hpp"
  13. namespace boost { namespace polygon{
  14. template <typename Unit>
  15. class line_intersection : public scanline_base<Unit> {
  16. private:
  17. typedef typename scanline_base<Unit>::Point Point;
  18. //the first point is the vertex and and second point establishes the slope of an edge eminating from the vertex
  19. //typedef std::pair<Point, Point> half_edge;
  20. typedef typename scanline_base<Unit>::half_edge half_edge;
  21. //scanline comparator functor
  22. typedef typename scanline_base<Unit>::less_half_edge less_half_edge;
  23. typedef typename scanline_base<Unit>::less_point less_point;
  24. //when parallel half edges are encounterd the set of segments is expanded
  25. //when a edge leaves the scanline it is removed from the set
  26. //when the set is empty the element is removed from the map
  27. typedef int segment_id;
  28. typedef std::pair<half_edge, std::set<segment_id> > scanline_element;
  29. typedef std::map<half_edge, std::set<segment_id>, less_half_edge> edge_scanline;
  30. typedef typename edge_scanline::iterator iterator;
  31. // std::map<Unit, std::set<segment_id> > vertical_data_;
  32. // edge_scanline edge_scanline_;
  33. // Unit x_;
  34. // int just_before_;
  35. // segment_id segment_id_;
  36. // std::vector<std::pair<half_edge, int> > event_edges_;
  37. // std::set<Point> intersection_queue_;
  38. public:
  39. // inline line_intersection() : vertical_data_(), edge_scanline_(), x_((std::numeric_limits<Unit>::max)()), just_before_(0), segment_id_(0), event_edges_(), intersection_queue_() {
  40. // less_half_edge lessElm(&x_, &just_before_);
  41. // edge_scanline_ = edge_scanline(lessElm);
  42. // }
  43. // inline line_intersection(const line_intersection& that) : vertical_data_(), edge_scanline_(), x_(), just_before_(), segment_id_(), event_edges_(), intersection_queue_() { (*this) = that; }
  44. // inline line_intersection& operator=(const line_intersection& that) {
  45. // x_ = that.x_;
  46. // just_before_ = that.just_before_;
  47. // segment_id_ = that.segment_id_;
  48. // //I cannot simply copy that.edge_scanline_ to this edge_scanline_ becuase the functor store pointers to other members!
  49. // less_half_edge lessElm(&x_, &just_before_);
  50. // edge_scanline_ = edge_scanline(lessElm);
  51. // edge_scanline_.insert(that.edge_scanline_.begin(), that.edge_scanline_.end());
  52. // return *this;
  53. // }
  54. // static inline void between(Point pt, Point pt1, Point pt2) {
  55. // less_point lp;
  56. // if(lp(pt1, pt2))
  57. // return lp(pt, pt2) && lp(pt1, pt);
  58. // return lp(pt, pt1) && lp(pt2, pt);
  59. // }
  60. template <typename iT>
  61. static inline void compute_histogram_in_y(iT begin, iT end, std::size_t size, std::vector<std::pair<Unit, std::pair<std::size_t, std::size_t> > >& histogram) {
  62. std::vector<std::pair<Unit, int> > ends;
  63. ends.reserve(size * 2);
  64. for(iT itr = begin ; itr != end; ++itr) {
  65. int count = (*itr).first.first.y() < (*itr).first.second.y() ? 1 : -1;
  66. ends.push_back(std::make_pair((*itr).first.first.y(), count));
  67. ends.push_back(std::make_pair((*itr).first.second.y(), -count));
  68. }
  69. polygon_sort(ends.begin(), ends.end());
  70. histogram.reserve(ends.size());
  71. histogram.push_back(std::make_pair(ends.front().first, std::make_pair(0, 0)));
  72. for(typename std::vector<std::pair<Unit, int> >::iterator itr = ends.begin(); itr != ends.end(); ++itr) {
  73. if((*itr).first != histogram.back().first) {
  74. histogram.push_back(std::make_pair((*itr).first, histogram.back().second));
  75. }
  76. if((*itr).second < 0)
  77. histogram.back().second.second -= (*itr).second;
  78. histogram.back().second.first += (*itr).second;
  79. }
  80. }
  81. template <typename iT>
  82. static inline void compute_y_cuts(std::vector<Unit>& y_cuts, iT begin, iT end, std::size_t size) {
  83. if(begin == end) return;
  84. if(size < 30) return; //30 is empirically chosen, but the algorithm is not sensitive to this constant
  85. std::size_t min_cut = size;
  86. iT cut = begin;
  87. std::size_t position = 0;
  88. std::size_t cut_size = 0;
  89. std::size_t histogram_size = std::distance(begin, end);
  90. for(iT itr = begin; itr != end; ++itr, ++position) {
  91. if(position < histogram_size / 3)
  92. continue;
  93. if(histogram_size - position < histogram_size / 3) break;
  94. if((*itr).second.first < min_cut) {
  95. cut = itr;
  96. min_cut = (*cut).second.first;
  97. cut_size = position;
  98. }
  99. }
  100. if(cut_size == 0 || (*cut).second.first > size / 9) //nine is empirically chosen
  101. return;
  102. compute_y_cuts(y_cuts, begin, cut, (*cut).second.first + (*cut).second.second);
  103. y_cuts.push_back((*cut).first);
  104. compute_y_cuts(y_cuts, cut, end, size - (*cut).second.second);
  105. }
  106. template <typename iT>
  107. static inline void validate_scan_divide_and_conquer(std::vector<std::set<Point> >& intersection_points,
  108. iT begin, iT end) {
  109. std::vector<std::pair<Unit, std::pair<std::size_t, std::size_t> > > histogram;
  110. compute_histogram_in_y(begin, end, std::distance(begin, end), histogram);
  111. std::vector<Unit> y_cuts;
  112. compute_y_cuts(y_cuts, histogram.begin(), histogram.end(), std::distance(begin, end));
  113. std::map<Unit, std::vector<std::pair<half_edge, segment_id> > > bins;
  114. bins[histogram.front().first] = std::vector<std::pair<half_edge, segment_id> >();
  115. for(typename std::vector<Unit>::iterator itr = y_cuts.begin(); itr != y_cuts.end(); ++itr) {
  116. bins[*itr] = std::vector<std::pair<half_edge, segment_id> >();
  117. }
  118. for(iT itr = begin; itr != end; ++itr) {
  119. typename std::map<Unit, std::vector<std::pair<half_edge, segment_id> > >::iterator lb =
  120. bins.lower_bound((std::min)((*itr).first.first.y(), (*itr).first.second.y()));
  121. if(lb != bins.begin())
  122. --lb;
  123. typename std::map<Unit, std::vector<std::pair<half_edge, segment_id> > >::iterator ub =
  124. bins.upper_bound((std::max)((*itr).first.first.y(), (*itr).first.second.y()));
  125. for( ; lb != ub; ++lb) {
  126. (*lb).second.push_back(*itr);
  127. }
  128. }
  129. validate_scan(intersection_points, bins[histogram.front().first].begin(), bins[histogram.front().first].end());
  130. for(typename std::vector<Unit>::iterator itr = y_cuts.begin(); itr != y_cuts.end(); ++itr) {
  131. validate_scan(intersection_points, bins[*itr].begin(), bins[*itr].end(), *itr);
  132. }
  133. }
  134. template <typename iT>
  135. static inline void validate_scan(std::vector<std::set<Point> >& intersection_points,
  136. iT begin, iT end) {
  137. validate_scan(intersection_points, begin, end, (std::numeric_limits<Unit>::min)());
  138. }
  139. //quadratic algorithm to do same work as optimal scan for cross checking
  140. template <typename iT>
  141. static inline void validate_scan(std::vector<std::set<Point> >& intersection_points,
  142. iT begin, iT end, Unit min_y) {
  143. std::vector<Point> pts;
  144. std::vector<std::pair<half_edge, segment_id> > data(begin, end);
  145. for(std::size_t i = 0; i < data.size(); ++i) {
  146. if(data[i].first.second < data[i].first.first) {
  147. std::swap(data[i].first.first, data[i].first.second);
  148. }
  149. }
  150. typename scanline_base<Unit>::compute_intersection_pack pack_;
  151. polygon_sort(data.begin(), data.end());
  152. //find all intersection points
  153. for(typename std::vector<std::pair<half_edge, segment_id> >::iterator outer = data.begin();
  154. outer != data.end(); ++outer) {
  155. const half_edge& he1 = (*outer).first;
  156. //its own end points
  157. pts.push_back(he1.first);
  158. pts.push_back(he1.second);
  159. std::set<Point>& segmentpts = intersection_points[(*outer).second];
  160. for(typename std::set<Point>::iterator itr = segmentpts.begin(); itr != segmentpts.end(); ++itr) {
  161. if((*itr).y() > min_y - 1)
  162. pts.push_back(*itr);
  163. }
  164. bool have_first_y = he1.first.y() >= min_y && he1.second.y() >= min_y;
  165. for(typename std::vector<std::pair<half_edge, segment_id> >::iterator inner = outer;
  166. inner != data.end(); ++inner) {
  167. const half_edge& he2 = (*inner).first;
  168. if(have_first_y || (he2.first.y() >= min_y && he2.second.y() >= min_y)) {
  169. //at least one segment has a low y value within the range
  170. if(he1 == he2) continue;
  171. if((std::min)(he2. first.get(HORIZONTAL),
  172. he2.second.get(HORIZONTAL)) >=
  173. (std::max)(he1.second.get(HORIZONTAL),
  174. he1.first.get(HORIZONTAL)))
  175. break;
  176. if(he1.first == he2.first || he1.second == he2.second)
  177. continue;
  178. Point intersection;
  179. if(pack_.compute_intersection(intersection, he1, he2)) {
  180. //their intersection point
  181. pts.push_back(intersection);
  182. intersection_points[(*inner).second].insert(intersection);
  183. intersection_points[(*outer).second].insert(intersection);
  184. }
  185. }
  186. }
  187. }
  188. polygon_sort(pts.begin(), pts.end());
  189. typename std::vector<Point>::iterator newend = std::unique(pts.begin(), pts.end());
  190. typename std::vector<Point>::iterator lfinger = pts.begin();
  191. //find all segments that interact with intersection points
  192. for(typename std::vector<std::pair<half_edge, segment_id> >::iterator outer = data.begin();
  193. outer != data.end(); ++outer) {
  194. const half_edge& he1 = (*outer).first;
  195. segment_id id1 = (*outer).second;
  196. typedef rectangle_data<Unit> Rectangle;
  197. //Rectangle rect1;
  198. //set_points(rect1, he1.first, he1.second);
  199. //typename std::vector<Point>::iterator itr = lower_bound(pts.begin(), newend, (std::min)(he1.first, he1.second));
  200. //typename std::vector<Point>::iterator itr2 = upper_bound(pts.begin(), newend, (std::max)(he1.first, he1.second));
  201. Point startpt = (std::min)(he1.first, he1.second);
  202. Point stoppt = (std::max)(he1.first, he1.second);
  203. //while(itr != newend && itr != pts.begin() && (*itr).get(HORIZONTAL) >= (std::min)(he1.first.get(HORIZONTAL), he1.second.get(HORIZONTAL))) --itr;
  204. //while(itr2 != newend && (*itr2).get(HORIZONTAL) <= (std::max)(he1.first.get(HORIZONTAL), he1.second.get(HORIZONTAL))) ++itr2;
  205. //itr = pts.begin();
  206. //itr2 = pts.end();
  207. while(lfinger != newend && (*lfinger).x() < startpt.x()) ++lfinger;
  208. for(typename std::vector<Point>::iterator itr = lfinger ; itr != newend && (*itr).x() <= stoppt.x(); ++itr) {
  209. if(scanline_base<Unit>::intersects_grid(*itr, he1))
  210. intersection_points[id1].insert(*itr);
  211. }
  212. }
  213. }
  214. template <typename iT, typename property_type>
  215. static inline void validate_scan(std::vector<std::pair<half_edge, std::pair<property_type, int> > >& output_segments,
  216. iT begin, iT end) {
  217. std::vector<std::pair<property_type, int> > input_properties;
  218. std::vector<std::pair<half_edge, int> > input_segments, intermediate_segments;
  219. int index = 0;
  220. for( ; begin != end; ++begin) {
  221. input_properties.push_back((*begin).second);
  222. input_segments.push_back(std::make_pair((*begin).first, index++));
  223. }
  224. validate_scan(intermediate_segments, input_segments.begin(), input_segments.end());
  225. for(std::size_t i = 0; i < intermediate_segments.size(); ++i) {
  226. output_segments.push_back(std::make_pair(intermediate_segments[i].first,
  227. input_properties[intermediate_segments[i].second]));
  228. less_point lp;
  229. if(lp(output_segments.back().first.first, output_segments.back().first.second) !=
  230. lp(input_segments[intermediate_segments[i].second].first.first,
  231. input_segments[intermediate_segments[i].second].first.second)) {
  232. //edge changed orientation, invert count on edge
  233. output_segments.back().second.second *= -1;
  234. }
  235. if(!scanline_base<Unit>::is_vertical(input_segments[intermediate_segments[i].second].first) &&
  236. scanline_base<Unit>::is_vertical(output_segments.back().first)) {
  237. output_segments.back().second.second *= -1;
  238. }
  239. if(lp(output_segments.back().first.second, output_segments.back().first.first)) {
  240. std::swap(output_segments.back().first.first, output_segments.back().first.second);
  241. }
  242. }
  243. }
  244. template <typename iT>
  245. static inline void validate_scan(std::vector<std::pair<half_edge, int> >& output_segments,
  246. iT begin, iT end) {
  247. std::vector<std::set<Point> > intersection_points(std::distance(begin, end));
  248. validate_scan_divide_and_conquer(intersection_points, begin, end);
  249. //validate_scan(intersection_points, begin, end);
  250. segment_intersections(output_segments, intersection_points, begin, end);
  251. // std::pair<segment_id, segment_id> offenders;
  252. // if(!verify_scan(offenders, output_segments.begin(), output_segments.end())) {
  253. // std::cout << "break here!\n";
  254. // for(typename std::set<Point>::iterator itr = intersection_points[offenders.first].begin();
  255. // itr != intersection_points[offenders.first].end(); ++itr) {
  256. // std::cout << (*itr).x() << " " << (*itr).y() << " ";
  257. // } std::cout << "\n";
  258. // for(typename std::set<Point>::iterator itr = intersection_points[offenders.second].begin();
  259. // itr != intersection_points[offenders.second].end(); ++itr) {
  260. // std::cout << (*itr).x() << " " << (*itr).y() << " ";
  261. // } std::cout << "\n";
  262. // exit(1);
  263. // }
  264. }
  265. //quadratic algorithm to find intersections
  266. template <typename iT, typename segment_id>
  267. static inline bool verify_scan(std::pair<segment_id, segment_id>& offenders,
  268. iT begin, iT end) {
  269. std::vector<std::pair<half_edge, segment_id> > data(begin, end);
  270. for(std::size_t i = 0; i < data.size(); ++i) {
  271. if(data[i].first.second < data[i].first.first) {
  272. std::swap(data[i].first.first, data[i].first.second);
  273. }
  274. }
  275. polygon_sort(data.begin(), data.end());
  276. for(typename std::vector<std::pair<half_edge, segment_id> >::iterator outer = data.begin();
  277. outer != data.end(); ++outer) {
  278. const half_edge& he1 = (*outer).first;
  279. segment_id id1 = (*outer).second;
  280. for(typename std::vector<std::pair<half_edge, segment_id> >::iterator inner = outer;
  281. inner != data.end(); ++inner) {
  282. const half_edge& he2 = (*inner).first;
  283. if(he1 == he2) continue;
  284. if((std::min)(he2. first.get(HORIZONTAL),
  285. he2.second.get(HORIZONTAL)) >
  286. (std::max)(he1.second.get(HORIZONTAL),
  287. he1.first.get(HORIZONTAL)))
  288. break;
  289. segment_id id2 = (*inner).second;
  290. if(scanline_base<Unit>::intersects(he1, he2)) {
  291. offenders.first = id1;
  292. offenders.second = id2;
  293. //std::cout << he1.first.x() << " " << he1.first.y() << " " << he1.second.x() << " " << he1.second.y() << " " << he2.first.x() << " " << he2.first.y() << " " << he2.second.x() << " " << he2.second.y() << "\n";
  294. return false;
  295. }
  296. }
  297. }
  298. return true;
  299. }
  300. class less_point_down_slope : public std::binary_function<Point, Point, bool> {
  301. public:
  302. inline less_point_down_slope() {}
  303. inline bool operator () (const Point& pt1, const Point& pt2) const {
  304. if(pt1.get(HORIZONTAL) < pt2.get(HORIZONTAL)) return true;
  305. if(pt1.get(HORIZONTAL) == pt2.get(HORIZONTAL)) {
  306. if(pt1.get(VERTICAL) > pt2.get(VERTICAL)) return true;
  307. }
  308. return false;
  309. }
  310. };
  311. template <typename iT>
  312. static inline void segment_edge(std::vector<std::pair<half_edge, int> >& output_segments,
  313. const half_edge& , segment_id id, iT begin, iT end) {
  314. iT current = begin;
  315. iT next = begin;
  316. ++next;
  317. while(next != end) {
  318. output_segments.push_back(std::make_pair(half_edge(*current, *next), id));
  319. current = next;
  320. ++next;
  321. }
  322. }
  323. template <typename iT>
  324. static inline void segment_intersections(std::vector<std::pair<half_edge, int> >& output_segments,
  325. std::vector<std::set<Point> >& intersection_points,
  326. iT begin, iT end) {
  327. for(iT iter = begin; iter != end; ++iter) {
  328. //less_point lp;
  329. const half_edge& he = (*iter).first;
  330. //if(lp(he.first, he.second)) {
  331. // //it is the begin event
  332. segment_id id = (*iter).second;
  333. const std::set<Point>& pts = intersection_points[id];
  334. Point hpt(he.first.get(HORIZONTAL)+1, he.first.get(VERTICAL));
  335. if(!scanline_base<Unit>::is_vertical(he) && scanline_base<Unit>::less_slope(he.first.get(HORIZONTAL), he.first.get(VERTICAL),
  336. he.second, hpt)) {
  337. //slope is below horizontal
  338. std::vector<Point> tmpPts;
  339. tmpPts.reserve(pts.size());
  340. tmpPts.insert(tmpPts.end(), pts.begin(), pts.end());
  341. less_point_down_slope lpds;
  342. polygon_sort(tmpPts.begin(), tmpPts.end(), lpds);
  343. segment_edge(output_segments, he, id, tmpPts.begin(), tmpPts.end());
  344. } else {
  345. segment_edge(output_segments, he, id, pts.begin(), pts.end());
  346. }
  347. //}
  348. }
  349. }
  350. // //iT iterator over unsorted pair<Point> representing line segments of input
  351. // //output_segments is populated with fully intersected output line segment half
  352. // //edges and the index of the input segment that they are assoicated with
  353. // //duplicate output half edges with different ids will be generated in the case
  354. // //that parallel input segments intersection
  355. // //outputs are in sorted order and include both begin and end events for
  356. // //each segment
  357. // template <typename iT>
  358. // inline void scan(std::vector<std::pair<half_edge, int> >& output_segments,
  359. // iT begin, iT end) {
  360. // std::map<segment_id, std::set<Point> > intersection_points;
  361. // scan(intersection_points, begin, end);
  362. // segment_intersections(output_segments, intersection_points, begin, end);
  363. // }
  364. // //iT iterator over sorted sequence of half edge, segment id pairs representing segment begin and end points
  365. // //intersection points provides a mapping from input segment id (vector index) to the set
  366. // //of intersection points assocated with that input segment
  367. // template <typename iT>
  368. // inline void scan(std::map<segment_id, std::set<Point> >& intersection_points,
  369. // iT begin, iT end) {
  370. // for(iT iter = begin; iter != end; ++iter) {
  371. // const std::pair<half_edge, int>& elem = *iter;
  372. // const half_edge& he = elem.first;
  373. // Unit current_x = he.first.get(HORIZONTAL);
  374. // if(current_x != x_) {
  375. // process_scan_event(intersection_points);
  376. // while(!intersection_queue_.empty() &&
  377. // (*(intersection_queue_.begin()).get(HORIZONTAL) < current_x)) {
  378. // x_ = *(intersection_queue_.begin()).get(HORIZONTAL);
  379. // process_intersections_at_scan_event(intersection_points);
  380. // }
  381. // x_ = current_x;
  382. // }
  383. // event_edges_.push_back(elem);
  384. // }
  385. // process_scan_event(intersection_points);
  386. // }
  387. // inline iterator lookup(const half_edge& he) {
  388. // return edge_scanline_.find(he);
  389. // }
  390. // inline void insert_into_scanline(const half_edge& he, int id) {
  391. // edge_scanline_[he].insert(id);
  392. // }
  393. // inline void lookup_and_remove(const half_edge& he, int id) {
  394. // iterator remove_iter = lookup(he);
  395. // if(remove_iter == edge_scanline_.end()) {
  396. // //std::cout << "failed to find removal segment in scanline\n";
  397. // return;
  398. // }
  399. // std::set<segment_id>& ids = (*remove_iter).second;
  400. // std::set<segment_id>::iterator id_iter = ids.find(id);
  401. // if(id_iter == ids.end()) {
  402. // //std::cout << "failed to find removal segment id in scanline set\n";
  403. // return;
  404. // }
  405. // ids.erase(id_iter);
  406. // if(ids.empty())
  407. // edge_scanline_.erase(remove_iter);
  408. // }
  409. // static inline void update_segments(std::map<segment_id, std::set<Point> >& intersection_points,
  410. // const std::set<segment_id>& segments, Point pt) {
  411. // for(std::set<segment_id>::const_iterator itr = segments.begin(); itr != segments.end(); ++itr) {
  412. // intersection_points[*itr].insert(pt);
  413. // }
  414. // }
  415. // inline void process_intersections_at_scan_event(std::map<segment_id, std::set<Point> >& intersection_points) {
  416. // //there may be additional intersection points at this x location that haven't been
  417. // //found yet if vertical or near vertical line segments intersect more than
  418. // //once before the next x location
  419. // just_before_ = true;
  420. // std::set<iterator> intersecting_elements;
  421. // std::set<Unit> intersection_locations;
  422. // typedef typename std::set<Point>::iterator intersection_iterator;
  423. // intersection_iterator iter;
  424. // //first find all secondary intersection locations and all scanline iterators
  425. // //that are intersecting
  426. // for(iter = intersection_queue_.begin();
  427. // iter != intersection_queue_.end() && (*iter).get(HORIZONTAL) == x_; ++iter) {
  428. // Point pt = *iter;
  429. // Unit y = pt.get(VERTICAL);
  430. // intersection_locations.insert(y);
  431. // //if x_ is max there can be only end events and no sloping edges
  432. // if(x_ != (std::numeric_limits<Unit>::max)()) {
  433. // //deal with edges that project to the right of scanline
  434. // //first find the edges in the scanline adjacent to primary intersectin points
  435. // //lookup segment in scanline at pt
  436. // iterator itr = edge_scanline_.lower_bound(half_edge(pt, Point(x_+1, y)));
  437. // //look above pt in scanline until reaching end or segment that doesn't intersect
  438. // //1x1 grid upper right of pt
  439. // //look below pt in scanline until reaching begin or segment that doesn't interset
  440. // //1x1 grid upper right of pt
  441. // //second find edges in scanline on the y interval of each edge found in the previous
  442. // //step for x_ to x_ + 1
  443. // //third find overlaps in the y intervals of all found edges to find all
  444. // //secondary intersection points
  445. // }
  446. // }
  447. // //erase the intersection points from the queue
  448. // intersection_queue_.erase(intersection_queue_.begin(), iter);
  449. // std::vector<scanline_element> insertion_edges;
  450. // insertion_edges.reserve(intersecting_elements.size());
  451. // std::vector<std::pair<Unit, iterator> > sloping_ends;
  452. // //do all the work of updating the output of all intersecting
  453. // for(typename std::set<iterator>::iterator inter_iter = intersecting_elements.begin();
  454. // inter_iter != intersecting_elements.end(); ++inter_iter) {
  455. // //if it is horizontal update it now and continue
  456. // if(is_horizontal((*inter_iter).first)) {
  457. // update_segments(intersection_points, (*inter_iter).second, Point(x_, (*inter_iter).first.get(VERTICAL)));
  458. // } else {
  459. // //if x_ is max there can be only end events and no sloping edges
  460. // if(x_ != (std::numeric_limits<Unit>::max)()) {
  461. // //insert its end points into the vector of sloping ends
  462. // const half_edge& he = (*inter_iter).first;
  463. // Unit y = evalAtXforY(x_, he.first, he.second);
  464. // Unit y2 = evalAtXforY(x_+1, he.first, he.second);
  465. // if(y2 >= y) y2 +=1; //we round up, in exact case we don't worry about overbite of one
  466. // else y += 1; //downward sloping round up
  467. // sloping_ends.push_back(std::make_pair(y, inter_iter));
  468. // sloping_ends.push_back(std::make_pair(y2, inter_iter));
  469. // }
  470. // }
  471. // }
  472. // //merge sloping element data
  473. // polygon_sort(sloping_ends.begin(), sloping_ends.end());
  474. // std::map<Unit, std::set<iterator> > sloping_elements;
  475. // std::set<iterator> merge_elements;
  476. // for(typename std::vector<std::pair<Unit, iterator> >::iterator slop_iter = sloping_ends.begin();
  477. // slop_iter == sloping_ends.end(); ++slop_iter) {
  478. // //merge into sloping elements
  479. // typename std::set<iterator>::iterator merge_iterator = merge_elements.find((*slop_iter).second);
  480. // if(merge_iterator == merge_elements.end()) {
  481. // merge_elements.insert((*slop_iter).second);
  482. // } else {
  483. // merge_elements.erase(merge_iterator);
  484. // }
  485. // sloping_elements[(*slop_iter).first] = merge_elements;
  486. // }
  487. // //scan intersection points
  488. // typename std::map<Unit, std::set<segment_id> >::iterator vertical_iter = vertical_data_.begin();
  489. // typename std::map<Unit, std::set<iterator> >::iterator sloping_iter = sloping_elements.begin();
  490. // for(typename std::set<Unit>::iterator position_iter = intersection_locations.begin();
  491. // position_iter == intersection_locations.end(); ++position_iter) {
  492. // //look for vertical segments that intersect this point and update them
  493. // Unit y = *position_iter;
  494. // Point pt(x_, y);
  495. // //handle vertical segments
  496. // if(vertical_iter != vertical_data_.end()) {
  497. // typename std::map<Unit, std::set<segment_id> >::iterator next_vertical = vertical_iter;
  498. // for(++next_vertical; next_vertical != vertical_data_.end() &&
  499. // (*next_vertical).first < y; ++next_vertical) {
  500. // vertical_iter = next_vertical;
  501. // }
  502. // if((*vertical_iter).first < y && !(*vertical_iter).second.empty()) {
  503. // update_segments(intersection_points, (*vertical_iter).second, pt);
  504. // ++vertical_iter;
  505. // if(vertical_iter != vertical_data_.end() && (*vertical_iter).first == y)
  506. // update_segments(intersection_points, (*vertical_iter).second, pt);
  507. // }
  508. // }
  509. // //handle sloping segments
  510. // if(sloping_iter != sloping_elements.end()) {
  511. // typename std::map<Unit, std::set<iterator> >::iterator next_sloping = sloping_iter;
  512. // for(++next_sloping; next_sloping != sloping_elements.end() &&
  513. // (*next_sloping).first < y; ++next_sloping) {
  514. // sloping_iter = next_sloping;
  515. // }
  516. // if((*sloping_iter).first < y && !(*sloping_iter).second.empty()) {
  517. // for(typename std::set<iterator>::iterator element_iter = (*sloping_iter).second.begin();
  518. // element_iter != (*sloping_iter).second.end(); ++element_iter) {
  519. // const half_edge& he = (*element_iter).first;
  520. // if(intersects_grid(pt, he)) {
  521. // update_segments(intersection_points, (*element_iter).second, pt);
  522. // }
  523. // }
  524. // ++sloping_iter;
  525. // if(sloping_iter != sloping_elements.end() && (*sloping_iter).first == y &&
  526. // !(*sloping_iter).second.empty()) {
  527. // for(typename std::set<iterator>::iterator element_iter = (*sloping_iter).second.begin();
  528. // element_iter != (*sloping_iter).second.end(); ++element_iter) {
  529. // const half_edge& he = (*element_iter).first;
  530. // if(intersects_grid(pt, he)) {
  531. // update_segments(intersection_points, (*element_iter).second, pt);
  532. // }
  533. // }
  534. // }
  535. // }
  536. // }
  537. // }
  538. // //erase and reinsert edges into scanline with check for future intersection
  539. // }
  540. // inline void process_scan_event(std::map<segment_id, std::set<Point> >& intersection_points) {
  541. // just_before_ = true;
  542. // //process end events by removing those segments from the scanline
  543. // //and insert vertices of all events into intersection queue
  544. // Point prev_point((std::numeric_limits<Unit>::min)(), (std::numeric_limits<Unit>::min)());
  545. // less_point lp;
  546. // std::set<segment_id> vertical_ids;
  547. // vertical_data_.clear();
  548. // for(std::size_t i = 0; i < event_edges_.size(); ++i) {
  549. // segment_id id = event_edges_[i].second;
  550. // const half_edge& he = event_edges_[i].first;
  551. // //vertical half edges are handled during intersection processing because
  552. // //they cannot be inserted into the scanline
  553. // if(!is_vertical(he)) {
  554. // if(lp(he.second, he.first)) {
  555. // //half edge is end event
  556. // lookup_and_remove(he, id);
  557. // } else {
  558. // //half edge is begin event
  559. // insert_into_scanline(he, id);
  560. // //note that they will be immediately removed and reinserted after
  561. // //handling their intersection (vertex)
  562. // //an optimization would allow them to be processed specially to avoid the redundant
  563. // //removal and reinsertion
  564. // }
  565. // } else {
  566. // //common case if you are lucky
  567. // //update the map of y to set of segment id
  568. // if(lp(he.second, he.first)) {
  569. // //half edge is end event
  570. // std::set<segment_id>::iterator itr = vertical_ids.find(id);
  571. // if(itr == vertical_ids.end()) {
  572. // //std::cout << "Failed to find end event id in vertical ids\n";
  573. // } else {
  574. // vertical_ids.erase(itr);
  575. // vertical_data_[he.first.get(HORIZONTAL)] = vertical_ids;
  576. // }
  577. // } else {
  578. // //half edge is a begin event
  579. // vertical_ids.insert(id);
  580. // vertical_data_[he.first.get(HORIZONTAL)] = vertical_ids;
  581. // }
  582. // }
  583. // //prevent repeated insertion of same vertex into intersection queue
  584. // if(prev_point != he.first)
  585. // intersection_queue_.insert(he.first);
  586. // else
  587. // prev_point = he.first;
  588. // // process intersections at scan event
  589. // process_intersections_at_scan_event(intersection_points);
  590. // }
  591. // event_edges_.clear();
  592. // }
  593. public:
  594. template <typename stream_type>
  595. static inline bool test_validate_scan(stream_type& stdcout) {
  596. std::vector<std::pair<half_edge, segment_id> > input, edges;
  597. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), 0));
  598. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 10)), 1));
  599. std::pair<segment_id, segment_id> result;
  600. validate_scan(edges, input.begin(), input.end());
  601. if(!verify_scan(result, edges.begin(), edges.end())) {
  602. stdcout << "s fail1 " << result.first << " " << result.second << "\n";
  603. return false;
  604. }
  605. input.push_back(std::make_pair(half_edge(Point(0, 5), Point(5, 5)), 2));
  606. edges.clear();
  607. validate_scan(edges, input.begin(), input.end());
  608. if(!verify_scan(result, edges.begin(), edges.end())) {
  609. stdcout << "s fail2 " << result.first << " " << result.second << "\n";
  610. return false;
  611. }
  612. input.pop_back();
  613. input.push_back(std::make_pair(half_edge(Point(1, 0), Point(11, 11)), input.size()));
  614. edges.clear();
  615. validate_scan(edges, input.begin(), input.end());
  616. if(!verify_scan(result, edges.begin(), edges.end())) {
  617. stdcout << "s fail3 " << result.first << " " << result.second << "\n";
  618. return false;
  619. }
  620. input.push_back(std::make_pair(half_edge(Point(1, 0), Point(10, 11)), input.size()));
  621. edges.clear();
  622. validate_scan(edges, input.begin(), input.end());
  623. if(!verify_scan(result, edges.begin(), edges.end())) {
  624. stdcout << "s fail4 " << result.first << " " << result.second << "\n";
  625. return false;
  626. }
  627. input.pop_back();
  628. input.push_back(std::make_pair(half_edge(Point(1, 2), Point(11, 11)), input.size()));
  629. edges.clear();
  630. validate_scan(edges, input.begin(), input.end());
  631. if(!verify_scan(result, edges.begin(), edges.end())) {
  632. stdcout << "s fail5 " << result.first << " " << result.second << "\n";
  633. return false;
  634. }
  635. input.push_back(std::make_pair(half_edge(Point(0, 5), Point(0, 11)), input.size()));
  636. edges.clear();
  637. validate_scan(edges, input.begin(), input.end());
  638. if(!verify_scan(result, edges.begin(), edges.end())) {
  639. stdcout << "s fail6 " << result.first << " " << result.second << "\n";
  640. return false;
  641. }
  642. input.pop_back();
  643. for(std::size_t i = 0; i < input.size(); ++i) {
  644. std::swap(input[i].first.first, input[i].first.second);
  645. }
  646. edges.clear();
  647. validate_scan(edges, input.begin(), input.end());
  648. if(!verify_scan(result, edges.begin(), edges.end())) {
  649. stdcout << "s fail5 2 " << result.first << " " << result.second << "\n";
  650. return false;
  651. }
  652. for(std::size_t i = 0; i < input.size(); ++i) {
  653. input[i].first.first = Point(input[i].first.first.get(HORIZONTAL) * -1,
  654. input[i].first.first.get(VERTICAL) * -1);
  655. input[i].first.second = Point(input[i].first.second.get(HORIZONTAL) * -1,
  656. input[i].first.second.get(VERTICAL) * -1);
  657. }
  658. edges.clear();
  659. validate_scan(edges, input.begin(), input.end());
  660. stdcout << edges.size() << "\n";
  661. if(!verify_scan(result, edges.begin(), edges.end())) {
  662. stdcout << "s fail5 3 " << result.first << " " << result.second << "\n";
  663. return false;
  664. }
  665. input.clear();
  666. edges.clear();
  667. input.push_back(std::make_pair(half_edge(Point(5, 7), Point(7, 6)), 0));
  668. input.push_back(std::make_pair(half_edge(Point(2, 4), Point(6, 7)), 1));
  669. validate_scan(edges, input.begin(), input.end());
  670. if(!verify_scan(result, edges.begin(), edges.end())) {
  671. stdcout << "s fail2 1 " << result.first << " " << result.second << "\n";
  672. print(input);
  673. print(edges);
  674. return false;
  675. }
  676. input.clear();
  677. edges.clear();
  678. input.push_back(std::make_pair(half_edge(Point(3, 2), Point(1, 7)), 0));
  679. input.push_back(std::make_pair(half_edge(Point(0, 6), Point(7, 4)), 1));
  680. validate_scan(edges, input.begin(), input.end());
  681. if(!verify_scan(result, edges.begin(), edges.end())) {
  682. stdcout << "s fail2 2 " << result.first << " " << result.second << "\n";
  683. print(input);
  684. print(edges);
  685. return false;
  686. }
  687. input.clear();
  688. edges.clear();
  689. input.push_back(std::make_pair(half_edge(Point(6, 6), Point(1, 0)), 0));
  690. input.push_back(std::make_pair(half_edge(Point(3, 6), Point(2, 3)), 1));
  691. validate_scan(edges, input.begin(), input.end());
  692. if(!verify_scan(result, edges.begin(), edges.end())) {
  693. stdcout << "s fail2 3 " << result.first << " " << result.second << "\n";
  694. print(input);
  695. print(edges);
  696. return false;
  697. }
  698. input.clear();
  699. edges.clear();
  700. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(7, 0)), 0));
  701. input.push_back(std::make_pair(half_edge(Point(6, 0), Point(2, 0)), 1));
  702. validate_scan(edges, input.begin(), input.end());
  703. if(!verify_scan(result, edges.begin(), edges.end())) {
  704. stdcout << "s fail2 4 " << result.first << " " << result.second << "\n";
  705. print(input);
  706. print(edges);
  707. return false;
  708. }
  709. input.clear();
  710. edges.clear();
  711. input.push_back(std::make_pair(half_edge(Point(-17333131 - -17208131, -10316869 - -10191869), Point(0, 0)), 0));
  712. input.push_back(std::make_pair(half_edge(Point(-17291260 - -17208131, -10200000 - -10191869), Point(-17075000 - -17208131, -10200000 - -10191869)), 1));
  713. validate_scan(edges, input.begin(), input.end());
  714. if(!verify_scan(result, edges.begin(), edges.end())) {
  715. stdcout << "s fail2 5 " << result.first << " " << result.second << "\n";
  716. print(input);
  717. print(edges);
  718. return false;
  719. }
  720. input.clear();
  721. edges.clear();
  722. input.push_back(std::make_pair(half_edge(Point(-17333131, -10316869), Point(-17208131, -10191869)), 0));
  723. input.push_back(std::make_pair(half_edge(Point(-17291260, -10200000), Point(-17075000, -10200000)), 1));
  724. validate_scan(edges, input.begin(), input.end());
  725. if(!verify_scan(result, edges.begin(), edges.end())) {
  726. stdcout << "s fail2 6 " << result.first << " " << result.second << "\n";
  727. print(input);
  728. print(edges);
  729. return false;
  730. }
  731. input.clear();
  732. edges.clear();
  733. input.push_back(std::make_pair(half_edge(Point(-9850009+9853379, -286971+290340), Point(-12777869+9853379, -3214831+290340)), 0));
  734. input.push_back(std::make_pair(half_edge(Point(-5223510+9853379, -290340+290340), Point(-9858140+9853379, -290340+290340)), 1));
  735. validate_scan(edges, input.begin(), input.end());
  736. print(edges);
  737. if(!verify_scan(result, edges.begin(), edges.end())) {
  738. stdcout << "s fail2 7 " << result.first << " " << result.second << "\n";
  739. print(input);
  740. print(edges);
  741. return false;
  742. }
  743. input.clear();
  744. edges.clear();
  745. input.push_back(std::make_pair(half_edge(Point(-9850009, -286971), Point(-12777869, -3214831)), 0));
  746. input.push_back(std::make_pair(half_edge(Point(-5223510, -290340), Point(-9858140, -290340)), 1));
  747. validate_scan(edges, input.begin(), input.end());
  748. if(!verify_scan(result, edges.begin(), edges.end())) {
  749. stdcout << "s fail2 8 " << result.first << " " << result.second << "\n";
  750. print(input);
  751. print(edges);
  752. return false;
  753. }
  754. //3 3 2 2: 0; 4 2 0 6: 1; 0 3 6 3: 2; 4 1 5 5: 3;
  755. input.clear();
  756. edges.clear();
  757. input.push_back(std::make_pair(half_edge(Point(3, 3), Point(2, 2)), 0));
  758. input.push_back(std::make_pair(half_edge(Point(4, 2), Point(0, 6)), 1));
  759. input.push_back(std::make_pair(half_edge(Point(0, 3), Point(6, 3)), 2));
  760. input.push_back(std::make_pair(half_edge(Point(4, 1), Point(5, 5)), 3));
  761. validate_scan(edges, input.begin(), input.end());
  762. if(!verify_scan(result, edges.begin(), edges.end())) {
  763. stdcout << "s fail4 1 " << result.first << " " << result.second << "\n";
  764. print(input);
  765. print(edges);
  766. return false;
  767. }
  768. //5 7 1 3: 0; 4 5 2 1: 1; 2 5 2 1: 2; 4 1 5 3: 3;
  769. input.clear();
  770. edges.clear();
  771. input.push_back(std::make_pair(half_edge(Point(5, 7), Point(1, 3)), 0));
  772. input.push_back(std::make_pair(half_edge(Point(4, 5), Point(2, 1)), 1));
  773. input.push_back(std::make_pair(half_edge(Point(2, 5), Point(2, 1)), 2));
  774. input.push_back(std::make_pair(half_edge(Point(4, 1), Point(5, 3)), 3));
  775. validate_scan(edges, input.begin(), input.end());
  776. if(!verify_scan(result, edges.begin(), edges.end())) {
  777. stdcout << "s fail4 2 " << result.first << " " << result.second << "\n";
  778. print(input);
  779. print(edges);
  780. return false;
  781. }
  782. //1 0 -4 -1: 0; 0 0 2 -1: 1;
  783. input.clear();
  784. edges.clear();
  785. input.push_back(std::make_pair(half_edge(Point(1, 0), Point(-4, -1)), 0));
  786. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(2, -1)), 1));
  787. validate_scan(edges, input.begin(), input.end());
  788. if(!verify_scan(result, edges.begin(), edges.end())) {
  789. stdcout << "s fail2 5 " << result.first << " " << result.second << "\n";
  790. print(input);
  791. print(edges);
  792. return false;
  793. }
  794. Unit min_c =0;
  795. Unit max_c =0;
  796. for(unsigned int outer = 0; outer < 1000; ++outer) {
  797. input.clear();
  798. for(unsigned int i = 0; i < 4; ++i) {
  799. Unit x1 = rand();
  800. Unit x2 = rand();
  801. Unit y1 = rand();
  802. Unit y2 = rand();
  803. int neg1 = rand() % 2;
  804. if(neg1) x1 *= -1;
  805. int neg2 = rand() % 2;
  806. if(neg2) x2 *= -1;
  807. int neg3 = rand() % 2;
  808. if(neg3) y1 *= -1;
  809. int neg4 = rand() % 2;
  810. if(neg4) y2 *= -1;
  811. if(x1 < min_c) min_c = x1;
  812. if(x2 < min_c) min_c = x2;
  813. if(y1 < min_c) min_c = y1;
  814. if(y2 < min_c) min_c = y2;
  815. if(x1 > max_c) max_c = x1;
  816. if(x2 > max_c) max_c = x2;
  817. if(y1 > max_c) max_c = y1;
  818. if(y2 > max_c) max_c = y2;
  819. Point pt1(x1, y1);
  820. Point pt2(x2, y2);
  821. if(pt1 != pt2)
  822. input.push_back(std::make_pair(half_edge(pt1, pt2), i));
  823. }
  824. edges.clear();
  825. validate_scan(edges, input.begin(), input.end());
  826. if(!verify_scan(result, edges.begin(), edges.end())) {
  827. stdcout << "s fail9 " << outer << ": " << result.first << " " << result.second << "\n";
  828. print(input);
  829. print(edges);
  830. return false;
  831. }
  832. }
  833. return true;
  834. }
  835. //static void print(const std::pair<half_edge, segment_id>& segment) {
  836. //std::cout << segment.first.first << " " << segment.first.second << ": " << segment.second << "; ";
  837. //}
  838. static void print(const std::vector<std::pair<half_edge, segment_id> >& vec) {
  839. for(std::size_t i = 0; i < vec.size(); ++ i) {
  840. // print(vec[i]);
  841. }
  842. //std::cout << "\n";
  843. }
  844. template <typename stream_type>
  845. static inline bool test_verify_scan(stream_type& stdcout) {
  846. std::vector<std::pair<half_edge, segment_id> > edges;
  847. edges.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), 0));
  848. edges.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 10)), 1));
  849. std::pair<segment_id, segment_id> result;
  850. if(!verify_scan(result, edges.begin(), edges.end())) {
  851. stdcout << "fail1\n";
  852. return false;
  853. }
  854. edges.push_back(std::make_pair(half_edge(Point(0, 5), Point(5, 5)), 2));
  855. if(verify_scan(result, edges.begin(), edges.end())) {
  856. stdcout << "fail2\n";
  857. return false;
  858. }
  859. edges.pop_back();
  860. edges.push_back(std::make_pair(half_edge(Point(1, 0), Point(11, 11)), (segment_id)edges.size()));
  861. if(!verify_scan(result, edges.begin(), edges.end())) {
  862. stdcout << "fail3\n";
  863. return false;
  864. }
  865. edges.push_back(std::make_pair(half_edge(Point(1, 0), Point(10, 11)), (segment_id)edges.size()));
  866. if(verify_scan(result, edges.begin(), edges.end())) {
  867. stdcout << "fail4\n";
  868. return false;
  869. }
  870. edges.pop_back();
  871. edges.push_back(std::make_pair(half_edge(Point(1, 2), Point(11, 11)), (segment_id)edges.size()));
  872. if(!verify_scan(result, edges.begin(), edges.end())) {
  873. stdcout << "fail5 " << result.first << " " << result.second << "\n";
  874. return false;
  875. }
  876. edges.push_back(std::make_pair(half_edge(Point(0, 5), Point(0, 11)), (segment_id)edges.size()));
  877. if(verify_scan(result, edges.begin(), edges.end())) {
  878. stdcout << "fail6 " << result.first << " " << result.second << "\n";
  879. return false;
  880. }
  881. edges.pop_back();
  882. for(std::size_t i = 0; i < edges.size(); ++i) {
  883. std::swap(edges[i].first.first, edges[i].first.second);
  884. }
  885. if(!verify_scan(result, edges.begin(), edges.end())) {
  886. stdcout << "fail5 2 " << result.first << " " << result.second << "\n";
  887. return false;
  888. }
  889. for(std::size_t i = 0; i < edges.size(); ++i) {
  890. edges[i].first.first = Point(edges[i].first.first.get(HORIZONTAL) * -1,
  891. edges[i].first.first.get(VERTICAL) * -1);
  892. edges[i].first.second = Point(edges[i].first.second.get(HORIZONTAL) * -1,
  893. edges[i].first.second.get(VERTICAL) * -1);
  894. }
  895. if(!verify_scan(result, edges.begin(), edges.end())) {
  896. stdcout << "fail5 3 " << result.first << " " << result.second << "\n";
  897. return false;
  898. }
  899. return true;
  900. }
  901. };
  902. //scanline consumes the "flattened" fully intersected line segments produced by
  903. //a pass of line_intersection along with property and count information and performs a
  904. //useful operation like booleans or property merge or connectivity extraction
  905. template <typename Unit, typename property_type, typename keytype = std::set<property_type> >
  906. class scanline : public scanline_base<Unit> {
  907. public:
  908. //definitions
  909. typedef typename scanline_base<Unit>::Point Point;
  910. //the first point is the vertex and and second point establishes the slope of an edge eminating from the vertex
  911. //typedef std::pair<Point, Point> half_edge;
  912. typedef typename scanline_base<Unit>::half_edge half_edge;
  913. //scanline comparator functor
  914. typedef typename scanline_base<Unit>::less_half_edge less_half_edge;
  915. typedef typename scanline_base<Unit>::less_point less_point;
  916. typedef keytype property_set;
  917. //this is the data type used internally to store the combination of property counts at a given location
  918. typedef std::vector<std::pair<property_type, int> > property_map;
  919. //this data structure assocates a property and count to a half edge
  920. typedef std::pair<half_edge, std::pair<property_type, int> > vertex_property;
  921. //this data type is used internally to store the combined property data for a given half edge
  922. typedef std::pair<half_edge, property_map> vertex_data;
  923. //this data type stores the combination of many half edges
  924. typedef std::vector<vertex_property> property_merge_data;
  925. //this data structure stores end points of edges in the scanline
  926. typedef std::set<Point, less_point> end_point_queue;
  927. //this is the output data type that is created by the scanline before it is post processed based on content of property sets
  928. typedef std::pair<half_edge, std::pair<property_set, property_set> > half_edge_property;
  929. //this is the scanline data structure
  930. typedef std::map<half_edge, property_map, less_half_edge> scanline_type;
  931. typedef std::pair<half_edge, property_map> scanline_element;
  932. typedef typename scanline_type::iterator iterator;
  933. typedef typename scanline_type::const_iterator const_iterator;
  934. //data
  935. scanline_type scan_data_;
  936. std::vector<iterator> removal_set_; //edges to be removed at the current scanline stop
  937. std::vector<scanline_element> insertion_set_; //edge to be inserted after current scanline stop
  938. end_point_queue end_point_queue_;
  939. Unit x_;
  940. Unit y_;
  941. int just_before_;
  942. typename scanline_base<Unit>::evalAtXforYPack evalAtXforYPack_;
  943. public:
  944. inline scanline() : scan_data_(), removal_set_(), insertion_set_(), end_point_queue_(),
  945. x_((std::numeric_limits<Unit>::max)()), y_((std::numeric_limits<Unit>::max)()), just_before_(false), evalAtXforYPack_() {
  946. less_half_edge lessElm(&x_, &just_before_, &evalAtXforYPack_);
  947. scan_data_ = scanline_type(lessElm);
  948. }
  949. inline scanline(const scanline& that) : scan_data_(), removal_set_(), insertion_set_(), end_point_queue_(),
  950. x_((std::numeric_limits<Unit>::max)()), y_((std::numeric_limits<Unit>::max)()), just_before_(false), evalAtXforYPack_() {
  951. (*this) = that; }
  952. inline scanline& operator=(const scanline& that) {
  953. x_ = that.x_;
  954. y_ = that.y_;
  955. just_before_ = that.just_before_;
  956. end_point_queue_ = that.end_point_queue_;
  957. //I cannot simply copy that.scanline_type to this scanline_type becuase the functor store pointers to other members!
  958. less_half_edge lessElm(&x_, &just_before_);
  959. scan_data_ = scanline_type(lessElm);
  960. scan_data_.insert(that.scan_data_.begin(), that.scan_data_.end());
  961. return *this;
  962. }
  963. template <typename result_type, typename result_functor>
  964. void write_out(result_type& result, result_functor rf, const half_edge& he,
  965. const property_map& pm_left, const property_map& pm_right) {
  966. //std::cout << "write out ";
  967. //std::cout << he.first << ", " << he.second << "\n";
  968. property_set ps_left, ps_right;
  969. set_unique_property(ps_left, pm_left);
  970. set_unique_property(ps_right, pm_right);
  971. if(ps_left != ps_right) {
  972. //std::cout << "!equivalent\n";
  973. rf(result, he, ps_left, ps_right);
  974. }
  975. }
  976. template <typename result_type, typename result_functor, typename iT>
  977. iT handle_input_events(result_type& result, result_functor rf, iT begin, iT end) {
  978. typedef typename high_precision_type<Unit>::type high_precision;
  979. //for each event
  980. property_map vertical_properties_above;
  981. property_map vertical_properties_below;
  982. half_edge vertical_edge_above;
  983. half_edge vertical_edge_below;
  984. std::vector<scanline_element> insertion_elements;
  985. //current_iter should increase monotonically toward end as we process scanline stop
  986. iterator current_iter = scan_data_.begin();
  987. just_before_ = true;
  988. Unit y = (std::numeric_limits<Unit>::min)();
  989. bool first_iteration = true;
  990. //we want to return from inside the loop when we hit end or new x
  991. #ifdef BOOST_POLYGON_MSVC
  992. #pragma warning (push)
  993. #pragma warning (disable: 4127)
  994. #endif
  995. while(true) {
  996. if(begin == end || (!first_iteration && ((*begin).first.first.get(VERTICAL) != y ||
  997. (*begin).first.first.get(HORIZONTAL) != x_))) {
  998. //lookup iterator range in scanline for elements coming in from the left
  999. //that end at this y
  1000. Point pt(x_, y);
  1001. //grab the properties coming in from below
  1002. property_map properties_below;
  1003. if(current_iter != scan_data_.end()) {
  1004. //make sure we are looking at element in scanline just below y
  1005. //if(evalAtXforY(x_, (*current_iter).first.first, (*current_iter).first.second) != y) {
  1006. if(scanline_base<Unit>::on_above_or_below(Point(x_, y), (*current_iter).first) != 0) {
  1007. Point e2(pt);
  1008. if(e2.get(VERTICAL) != (std::numeric_limits<Unit>::max)())
  1009. e2.set(VERTICAL, e2.get(VERTICAL) + 1);
  1010. else
  1011. e2.set(VERTICAL, e2.get(VERTICAL) - 1);
  1012. half_edge vhe(pt, e2);
  1013. current_iter = scan_data_.lower_bound(vhe);
  1014. }
  1015. if(current_iter != scan_data_.end()) {
  1016. //get the bottom iterator for elements at this point
  1017. //while(evalAtXforY(x_, (*current_iter).first.first, (*current_iter).first.second) >= (high_precision)y &&
  1018. while(scanline_base<Unit>::on_above_or_below(Point(x_, y), (*current_iter).first) != 1 &&
  1019. current_iter != scan_data_.begin()) {
  1020. --current_iter;
  1021. }
  1022. //if(evalAtXforY(x_, (*current_iter).first.first, (*current_iter).first.second) >= (high_precision)y) {
  1023. if(scanline_base<Unit>::on_above_or_below(Point(x_, y), (*current_iter).first) != 1) {
  1024. properties_below.clear();
  1025. } else {
  1026. properties_below = (*current_iter).second;
  1027. //move back up to y or one past y
  1028. ++current_iter;
  1029. }
  1030. }
  1031. }
  1032. std::vector<iterator> edges_from_left;
  1033. while(current_iter != scan_data_.end() &&
  1034. //can only be true if y is integer
  1035. //evalAtXforY(x_, (*current_iter).first.first, (*current_iter).first.second) == y) {
  1036. scanline_base<Unit>::on_above_or_below(Point(x_, y), (*current_iter).first) == 0) {
  1037. //removal_set_.push_back(current_iter);
  1038. ++current_iter;
  1039. }
  1040. //merge vertical count with count from below
  1041. if(!vertical_properties_below.empty()) {
  1042. merge_property_maps(vertical_properties_below, properties_below);
  1043. //write out vertical edge
  1044. write_out(result, rf, vertical_edge_below, properties_below, vertical_properties_below);
  1045. } else {
  1046. merge_property_maps(vertical_properties_below, properties_below);
  1047. }
  1048. //iteratively add intertion element counts to count from below
  1049. //and write them to insertion set
  1050. for(std::size_t i = 0; i < insertion_elements.size(); ++i) {
  1051. if(i == 0) {
  1052. merge_property_maps(insertion_elements[i].second, vertical_properties_below);
  1053. write_out(result, rf, insertion_elements[i].first, insertion_elements[i].second, vertical_properties_below);
  1054. } else {
  1055. merge_property_maps(insertion_elements[i].second, insertion_elements[i-1].second);
  1056. write_out(result, rf, insertion_elements[i].first, insertion_elements[i].second, insertion_elements[i-1].second);
  1057. }
  1058. insertion_set_.push_back(insertion_elements[i]);
  1059. }
  1060. if((begin == end || (*begin).first.first.get(HORIZONTAL) != x_)) {
  1061. if(vertical_properties_above.empty()) {
  1062. return begin;
  1063. } else {
  1064. y = vertical_edge_above.second.get(VERTICAL);
  1065. vertical_properties_below.clear();
  1066. vertical_properties_above.swap(vertical_properties_below);
  1067. vertical_edge_below = vertical_edge_above;
  1068. insertion_elements.clear();
  1069. continue;
  1070. }
  1071. }
  1072. vertical_properties_below.clear();
  1073. vertical_properties_above.swap(vertical_properties_below);
  1074. vertical_edge_below = vertical_edge_above;
  1075. insertion_elements.clear();
  1076. }
  1077. if(begin != end) {
  1078. const vertex_property& vp = *begin;
  1079. const half_edge& he = vp.first;
  1080. y = he.first.get(VERTICAL);
  1081. first_iteration = false;
  1082. if(! vertical_properties_below.empty() &&
  1083. vertical_edge_below.second.get(VERTICAL) < y) {
  1084. y = vertical_edge_below.second.get(VERTICAL);
  1085. continue;
  1086. }
  1087. if(scanline_base<Unit>::is_vertical(he)) {
  1088. update_property_map(vertical_properties_above, vp.second);
  1089. vertical_edge_above = he;
  1090. } else {
  1091. if(insertion_elements.empty() ||
  1092. insertion_elements.back().first != he) {
  1093. insertion_elements.push_back(scanline_element(he, property_map()));
  1094. }
  1095. update_property_map(insertion_elements.back().second, vp.second);
  1096. }
  1097. ++begin;
  1098. }
  1099. }
  1100. #ifdef BOOST_POLYGON_MSVC
  1101. #pragma warning (pop)
  1102. #endif
  1103. }
  1104. inline void erase_end_events(typename end_point_queue::iterator epqi) {
  1105. end_point_queue_.erase(end_point_queue_.begin(), epqi);
  1106. for(typename std::vector<iterator>::iterator retire_itr = removal_set_.begin();
  1107. retire_itr != removal_set_.end(); ++retire_itr) {
  1108. scan_data_.erase(*retire_itr);
  1109. }
  1110. removal_set_.clear();
  1111. }
  1112. inline void remove_retired_edges_from_scanline() {
  1113. just_before_ = true;
  1114. typename end_point_queue::iterator epqi = end_point_queue_.begin();
  1115. Unit current_x = x_;
  1116. Unit previous_x = x_;
  1117. while(epqi != end_point_queue_.end() &&
  1118. (*epqi).get(HORIZONTAL) <= current_x) {
  1119. x_ = (*epqi).get(HORIZONTAL);
  1120. if(x_ != previous_x) erase_end_events(epqi);
  1121. previous_x = x_;
  1122. //lookup elements
  1123. Point e2(*epqi);
  1124. if(e2.get(VERTICAL) != (std::numeric_limits<Unit>::max)())
  1125. e2.set(VERTICAL, e2.get(VERTICAL) + 1);
  1126. else
  1127. e2.set(VERTICAL, e2.get(VERTICAL) - 1);
  1128. half_edge vhe_e(*epqi, e2);
  1129. iterator current_iter = scan_data_.lower_bound(vhe_e);
  1130. while(current_iter != scan_data_.end() && (*current_iter).first.second == (*epqi)) {
  1131. //evalAtXforY(x_, (*current_iter).first.first, (*current_iter).first.second) == (*epqi).get(VERTICAL)) {
  1132. removal_set_.push_back(current_iter);
  1133. ++current_iter;
  1134. }
  1135. ++epqi;
  1136. }
  1137. x_ = current_x;
  1138. erase_end_events(epqi);
  1139. }
  1140. inline void insert_new_edges_into_scanline() {
  1141. just_before_ = false;
  1142. for(typename std::vector<scanline_element>::iterator insert_itr = insertion_set_.begin();
  1143. insert_itr != insertion_set_.end(); ++insert_itr) {
  1144. scan_data_.insert(*insert_itr);
  1145. end_point_queue_.insert((*insert_itr).first.second);
  1146. }
  1147. insertion_set_.clear();
  1148. }
  1149. //iterator over range of vertex property elements and call result functor
  1150. //passing edge to be output, the merged data on both sides and the result
  1151. template <typename result_type, typename result_functor, typename iT>
  1152. void scan(result_type& result, result_functor rf, iT begin, iT end) {
  1153. while(begin != end) {
  1154. x_ = (*begin).first.first.get(HORIZONTAL); //update scanline stop location
  1155. //print_scanline();
  1156. --x_;
  1157. remove_retired_edges_from_scanline();
  1158. ++x_;
  1159. begin = handle_input_events(result, rf, begin, end);
  1160. remove_retired_edges_from_scanline();
  1161. //print_scanline();
  1162. insert_new_edges_into_scanline();
  1163. }
  1164. //print_scanline();
  1165. x_ = (std::numeric_limits<Unit>::max)();
  1166. remove_retired_edges_from_scanline();
  1167. }
  1168. //inline void print_scanline() {
  1169. // std::cout << "scanline at " << x_ << ": ";
  1170. // for(iterator itr = scan_data_.begin(); itr != scan_data_.end(); ++itr) {
  1171. // const scanline_element& se = *itr;
  1172. // const half_edge& he = se.first;
  1173. // const property_map& mp = se.second;
  1174. // std::cout << he.first << ", " << he.second << " ( ";
  1175. // for(std::size_t i = 0; i < mp.size(); ++i) {
  1176. // std::cout << mp[i].first << ":" << mp[i].second << " ";
  1177. // } std::cout << ") ";
  1178. // } std::cout << "\n";
  1179. //}
  1180. static inline void merge_property_maps(property_map& mp, const property_map& mp2) {
  1181. property_map newmp;
  1182. newmp.reserve(mp.size() + mp2.size());
  1183. unsigned int i = 0;
  1184. unsigned int j = 0;
  1185. while(i != mp.size() && j != mp2.size()) {
  1186. if(mp[i].first < mp2[j].first) {
  1187. newmp.push_back(mp[i]);
  1188. ++i;
  1189. } else if(mp[i].first > mp2[j].first) {
  1190. newmp.push_back(mp2[j]);
  1191. ++j;
  1192. } else {
  1193. int count = mp[i].second;
  1194. count += mp2[j].second;
  1195. if(count) {
  1196. newmp.push_back(mp[i]);
  1197. newmp.back().second = count;
  1198. }
  1199. ++i;
  1200. ++j;
  1201. }
  1202. }
  1203. while(i != mp.size()) {
  1204. newmp.push_back(mp[i]);
  1205. ++i;
  1206. }
  1207. while(j != mp2.size()) {
  1208. newmp.push_back(mp2[j]);
  1209. ++j;
  1210. }
  1211. mp.swap(newmp);
  1212. }
  1213. static inline void update_property_map(property_map& mp, const std::pair<property_type, int>& prop_data) {
  1214. property_map newmp;
  1215. newmp.reserve(mp.size() +1);
  1216. bool consumed = false;
  1217. for(std::size_t i = 0; i < mp.size(); ++i) {
  1218. if(!consumed && prop_data.first == mp[i].first) {
  1219. consumed = true;
  1220. int count = prop_data.second + mp[i].second;
  1221. if(count)
  1222. newmp.push_back(std::make_pair(prop_data.first, count));
  1223. } else if(!consumed && prop_data.first < mp[i].first) {
  1224. consumed = true;
  1225. newmp.push_back(prop_data);
  1226. newmp.push_back(mp[i]);
  1227. } else {
  1228. newmp.push_back(mp[i]);
  1229. }
  1230. }
  1231. if(!consumed) newmp.push_back(prop_data);
  1232. mp.swap(newmp);
  1233. }
  1234. static inline void set_unique_property(property_set& unqiue_property, const property_map& property) {
  1235. unqiue_property.clear();
  1236. for(typename property_map::const_iterator itr = property.begin(); itr != property.end(); ++itr) {
  1237. if((*itr).second > 0)
  1238. unqiue_property.insert(unqiue_property.end(), (*itr).first);
  1239. }
  1240. }
  1241. static inline bool common_vertex(const half_edge& he1, const half_edge& he2) {
  1242. return he1.first == he2.first ||
  1243. he1.first == he2.second ||
  1244. he1.second == he2.first ||
  1245. he1.second == he2.second;
  1246. }
  1247. typedef typename scanline_base<Unit>::vertex_half_edge vertex_half_edge;
  1248. template <typename iT>
  1249. static inline void convert_segments_to_vertex_half_edges(std::vector<vertex_half_edge>& output, iT begin, iT end) {
  1250. for( ; begin != end; ++begin) {
  1251. const half_edge& he = (*begin).first;
  1252. int count = (*begin).second;
  1253. output.push_back(vertex_half_edge(he.first, he.second, count));
  1254. output.push_back(vertex_half_edge(he.second, he.first, -count));
  1255. }
  1256. polygon_sort(output.begin(), output.end());
  1257. }
  1258. class test_functor {
  1259. public:
  1260. inline test_functor() {}
  1261. inline void operator()(std::vector<std::pair<half_edge, std::pair<property_set, property_set> > >& result,
  1262. const half_edge& he, const property_set& ps_left, const property_set& ps_right) {
  1263. result.push_back(std::make_pair(he, std::make_pair(ps_left, ps_right)));
  1264. }
  1265. };
  1266. template <typename stream_type>
  1267. static inline bool test_scanline(stream_type& stdcout) {
  1268. std::vector<std::pair<half_edge, std::pair<property_set, property_set> > > result;
  1269. std::vector<std::pair<half_edge, std::pair<property_type, int> > > input;
  1270. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), std::make_pair(0, 1)));
  1271. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 0)), std::make_pair(0, 1)));
  1272. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(10, 10)), std::make_pair(0, -1)));
  1273. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(10, 10)), std::make_pair(0, -1)));
  1274. scanline sl;
  1275. test_functor tf;
  1276. sl.scan(result, tf, input.begin(), input.end());
  1277. stdcout << "scanned\n";
  1278. for(std::size_t i = 0; i < result.size(); ++i) {
  1279. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1280. } stdcout << "\n";
  1281. input.clear();
  1282. result.clear();
  1283. input.push_back(std::make_pair(half_edge(Point(-1, -1), Point(10, 0)), std::make_pair(0, 1)));
  1284. input.push_back(std::make_pair(half_edge(Point(-1, -1), Point(0, 10)), std::make_pair(0, -1)));
  1285. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(11, 11)), std::make_pair(0, -1)));
  1286. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(11, 11)), std::make_pair(0, 1)));
  1287. scanline sl2;
  1288. sl2.scan(result, tf, input.begin(), input.end());
  1289. stdcout << "scanned\n";
  1290. for(std::size_t i = 0; i < result.size(); ++i) {
  1291. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1292. } stdcout << "\n";
  1293. input.clear();
  1294. result.clear();
  1295. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), std::make_pair(0, 1)));
  1296. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 0)), std::make_pair(0, 1)));
  1297. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(10, 10)), std::make_pair(0, -1)));
  1298. input.push_back(std::make_pair(half_edge(Point(1, 1), Point(8, 2)), std::make_pair(1, 1)));
  1299. input.push_back(std::make_pair(half_edge(Point(1, 1), Point(2, 8)), std::make_pair(1, -1)));
  1300. input.push_back(std::make_pair(half_edge(Point(2, 8), Point(9, 9)), std::make_pair(1, -1)));
  1301. input.push_back(std::make_pair(half_edge(Point(8, 2), Point(9, 9)), std::make_pair(1, 1)));
  1302. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(10, 10)), std::make_pair(0, -1)));
  1303. scanline sl3;
  1304. sl3.scan(result, tf, input.begin(), input.end());
  1305. stdcout << "scanned\n";
  1306. for(std::size_t i = 0; i < result.size(); ++i) {
  1307. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1308. } stdcout << "\n";
  1309. input.clear();
  1310. result.clear();
  1311. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), std::make_pair(0, 1)));
  1312. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 0)), std::make_pair(0, 1)));
  1313. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(10, 10)), std::make_pair(0, -1)));
  1314. input.push_back(std::make_pair(half_edge(Point(1, 1), Point(8, 2)), std::make_pair(0, 1)));
  1315. input.push_back(std::make_pair(half_edge(Point(1, 1), Point(2, 8)), std::make_pair(0, -1)));
  1316. input.push_back(std::make_pair(half_edge(Point(2, 8), Point(9, 9)), std::make_pair(0, -1)));
  1317. input.push_back(std::make_pair(half_edge(Point(8, 2), Point(9, 9)), std::make_pair(0, 1)));
  1318. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(10, 10)), std::make_pair(0, -1)));
  1319. scanline sl4;
  1320. sl4.scan(result, tf, input.begin(), input.end());
  1321. stdcout << "scanned\n";
  1322. for(std::size_t i = 0; i < result.size(); ++i) {
  1323. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1324. } stdcout << "\n";
  1325. input.clear();
  1326. result.clear();
  1327. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 0)), std::make_pair(0, 1)));
  1328. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(9, 1)), std::make_pair(0, 1)));
  1329. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(1, 9)), std::make_pair(0, -1)));
  1330. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), std::make_pair(0, 1)));
  1331. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(10, 10)), std::make_pair(0, -1)));
  1332. input.push_back(std::make_pair(half_edge(Point(1, 9), Point(10, 10)), std::make_pair(0, -1)));
  1333. input.push_back(std::make_pair(half_edge(Point(9, 1), Point(10, 10)), std::make_pair(0, 1)));
  1334. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(10, 10)), std::make_pair(0, -1)));
  1335. scanline sl5;
  1336. sl5.scan(result, tf, input.begin(), input.end());
  1337. stdcout << "scanned\n";
  1338. for(std::size_t i = 0; i < result.size(); ++i) {
  1339. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1340. } stdcout << "\n";
  1341. input.clear();
  1342. result.clear();
  1343. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 0)), std::make_pair(0, 1)));
  1344. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(9, 1)), std::make_pair(1, 1)));
  1345. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(1, 9)), std::make_pair(1, -1)));
  1346. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), std::make_pair(0, 1)));
  1347. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(10, 10)), std::make_pair(0, -1)));
  1348. input.push_back(std::make_pair(half_edge(Point(1, 9), Point(10, 10)), std::make_pair(1, -1)));
  1349. input.push_back(std::make_pair(half_edge(Point(9, 1), Point(10, 10)), std::make_pair(1, 1)));
  1350. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(10, 10)), std::make_pair(0, -1)));
  1351. scanline sl6;
  1352. sl6.scan(result, tf, input.begin(), input.end());
  1353. stdcout << "scanned\n";
  1354. for(std::size_t i = 0; i < result.size(); ++i) {
  1355. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1356. } stdcout << "\n";
  1357. input.clear();
  1358. result.clear();
  1359. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(10, 0)), std::make_pair(0, 1)));
  1360. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(9, 1)), std::make_pair(1, 1)));
  1361. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(1, 9)), std::make_pair(1, -1)));
  1362. input.push_back(std::make_pair(half_edge(Point(0, 0), Point(0, 10)), std::make_pair(0, 1)));
  1363. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(10, 10)), std::make_pair(0, -1)));
  1364. input.push_back(std::make_pair(half_edge(Point(0, 20), Point(10, 20)), std::make_pair(0, 1)));
  1365. input.push_back(std::make_pair(half_edge(Point(0, 20), Point(9, 21)), std::make_pair(1, 1)));
  1366. input.push_back(std::make_pair(half_edge(Point(0, 20), Point(1, 29)), std::make_pair(1, -1)));
  1367. input.push_back(std::make_pair(half_edge(Point(0, 20), Point(0, 30)), std::make_pair(0, 1)));
  1368. input.push_back(std::make_pair(half_edge(Point(0, 30), Point(10, 30)), std::make_pair(0, -1)));
  1369. input.push_back(std::make_pair(half_edge(Point(1, 9), Point(10, 10)), std::make_pair(1, -1)));
  1370. input.push_back(std::make_pair(half_edge(Point(1, 29), Point(10, 30)), std::make_pair(1, -1)));
  1371. input.push_back(std::make_pair(half_edge(Point(9, 1), Point(10, 10)), std::make_pair(1, 1)));
  1372. input.push_back(std::make_pair(half_edge(Point(9, 21), Point(10, 30)), std::make_pair(1, 1)));
  1373. input.push_back(std::make_pair(half_edge(Point(10, 20), Point(10, 30)), std::make_pair(0, -1)));
  1374. input.push_back(std::make_pair(half_edge(Point(10, 20), Point(10, 30)), std::make_pair(0, -1)));
  1375. scanline sl7;
  1376. sl7.scan(result, tf, input.begin(), input.end());
  1377. stdcout << "scanned\n";
  1378. for(std::size_t i = 0; i < result.size(); ++i) {
  1379. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1380. } stdcout << "\n";
  1381. input.clear();
  1382. result.clear();
  1383. input.push_back(std::make_pair(half_edge(Point(-1, -1), Point(10, 0)), std::make_pair(0, 1))); //a
  1384. input.push_back(std::make_pair(half_edge(Point(-1, -1), Point(0, 10)), std::make_pair(0, -1))); //a
  1385. input.push_back(std::make_pair(half_edge(Point(0, 10), Point(11, 11)), std::make_pair(0, -1))); //a
  1386. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(20, 0)), std::make_pair(0, 1))); //b
  1387. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(11, 11)), std::make_pair(0, -1))); //b
  1388. input.push_back(std::make_pair(half_edge(Point(10, 0), Point(11, 11)), std::make_pair(0, 1))); //a
  1389. input.push_back(std::make_pair(half_edge(Point(11, 11), Point(20, 10)), std::make_pair(0, -1))); //b
  1390. input.push_back(std::make_pair(half_edge(Point(20, 0), Point(30, 0)), std::make_pair(0, 1))); //c
  1391. input.push_back(std::make_pair(half_edge(Point(20, 0), Point(20, 10)), std::make_pair(0, -1))); //b
  1392. input.push_back(std::make_pair(half_edge(Point(20, 0), Point(20, 10)), std::make_pair(0, 1))); //c
  1393. input.push_back(std::make_pair(half_edge(Point(20, 10), Point(30, 10)), std::make_pair(0, -1))); //c
  1394. input.push_back(std::make_pair(half_edge(Point(30, 0), Point(30, 10)), std::make_pair(0, -1))); //c
  1395. scanline sl8;
  1396. sl8.scan(result, tf, input.begin(), input.end());
  1397. stdcout << "scanned\n";
  1398. for(std::size_t i = 0; i < result.size(); ++i) {
  1399. stdcout << result[i].first.first << ", " << result[i].first.second << "; ";
  1400. } stdcout << "\n";
  1401. return true;
  1402. }
  1403. };
  1404. template <typename Unit>
  1405. class merge_output_functor {
  1406. public:
  1407. typedef typename scanline_base<Unit>::half_edge half_edge;
  1408. merge_output_functor() {}
  1409. template <typename result_type, typename key_type>
  1410. void operator()(result_type& result, const half_edge& edge, const key_type& left, const key_type& right) {
  1411. typename std::pair<half_edge, int> elem;
  1412. elem.first = edge;
  1413. elem.second = 1;
  1414. if(edge.second < edge.first) elem.second *= -1;
  1415. if(scanline_base<Unit>::is_vertical(edge)) elem.second *= -1;
  1416. if(!left.empty())
  1417. result[left].insert_clean(elem);
  1418. elem.second *= -1;
  1419. if(!right.empty())
  1420. result[right].insert_clean(elem);
  1421. }
  1422. };
  1423. template <typename Unit, typename property_type, typename key_type = std::set<property_type>,
  1424. typename output_functor_type = merge_output_functor<Unit> >
  1425. class property_merge : public scanline_base<Unit> {
  1426. protected:
  1427. typedef typename scanline_base<Unit>::Point Point;
  1428. //the first point is the vertex and and second point establishes the slope of an edge eminating from the vertex
  1429. //typedef std::pair<Point, Point> half_edge;
  1430. typedef typename scanline_base<Unit>::half_edge half_edge;
  1431. //scanline comparator functor
  1432. typedef typename scanline_base<Unit>::less_half_edge less_half_edge;
  1433. typedef typename scanline_base<Unit>::less_point less_point;
  1434. //this data structure assocates a property and count to a half edge
  1435. typedef std::pair<half_edge, std::pair<property_type, int> > vertex_property;
  1436. //this data type stores the combination of many half edges
  1437. typedef std::vector<vertex_property> property_merge_data;
  1438. //this is the data type used internally to store the combination of property counts at a given location
  1439. typedef std::vector<std::pair<property_type, int> > property_map;
  1440. //this data type is used internally to store the combined property data for a given half edge
  1441. typedef std::pair<half_edge, property_map> vertex_data;
  1442. property_merge_data pmd;
  1443. typename scanline_base<Unit>::evalAtXforYPack evalAtXforYPack_;
  1444. template<typename vertex_data_type>
  1445. class less_vertex_data {
  1446. typename scanline_base<Unit>::evalAtXforYPack* pack_;
  1447. public:
  1448. less_vertex_data() : pack_() {}
  1449. less_vertex_data(typename scanline_base<Unit>::evalAtXforYPack* pack) : pack_(pack) {}
  1450. bool operator() (const vertex_data_type& lvalue, const vertex_data_type& rvalue) const {
  1451. less_point lp;
  1452. if(lp(lvalue.first.first, rvalue.first.first)) return true;
  1453. if(lp(rvalue.first.first, lvalue.first.first)) return false;
  1454. Unit x = lvalue.first.first.get(HORIZONTAL);
  1455. int just_before_ = 0;
  1456. less_half_edge lhe(&x, &just_before_, pack_);
  1457. return lhe(lvalue.first, rvalue.first);
  1458. }
  1459. };
  1460. inline void sort_property_merge_data() {
  1461. less_vertex_data<vertex_property> lvd(&evalAtXforYPack_);
  1462. polygon_sort(pmd.begin(), pmd.end(), lvd);
  1463. }
  1464. public:
  1465. inline property_merge_data& get_property_merge_data() { return pmd; }
  1466. inline property_merge() : pmd(), evalAtXforYPack_() {}
  1467. inline property_merge(const property_merge& pm) : pmd(pm.pmd), evalAtXforYPack_(pm.evalAtXforYPack_) {}
  1468. inline property_merge& operator=(const property_merge& pm) { pmd = pm.pmd; return *this; }
  1469. template <typename polygon_type>
  1470. void insert(const polygon_type& polygon_object, const property_type& property_value, bool is_hole = false) {
  1471. insert(polygon_object, property_value, is_hole, typename geometry_concept<polygon_type>::type());
  1472. }
  1473. //result type should be std::map<std::set<property_type>, polygon_set_type>
  1474. //or std::map<std::vector<property_type>, polygon_set_type>
  1475. template <typename result_type>
  1476. void merge(result_type& result) {
  1477. if(pmd.empty()) return;
  1478. //intersect data
  1479. property_merge_data tmp_pmd;
  1480. line_intersection<Unit>::validate_scan(tmp_pmd, pmd.begin(), pmd.end());
  1481. pmd.swap(tmp_pmd);
  1482. sort_property_merge_data();
  1483. scanline<Unit, property_type, key_type> sl;
  1484. output_functor_type mof;
  1485. sl.scan(result, mof, pmd.begin(), pmd.end());
  1486. }
  1487. inline bool verify1() {
  1488. std::pair<int, int> offenders;
  1489. std::vector<std::pair<half_edge, int> > lines;
  1490. int count = 0;
  1491. for(std::size_t i = 0; i < pmd.size(); ++i) {
  1492. lines.push_back(std::make_pair(pmd[i].first, count++));
  1493. }
  1494. if(!line_intersection<Unit>::verify_scan(offenders, lines.begin(), lines.end())) {
  1495. //stdcout << "Intersection failed!\n";
  1496. //stdcout << offenders.first << " " << offenders.second << "\n";
  1497. return false;
  1498. }
  1499. std::vector<Point> pts;
  1500. for(std::size_t i = 0; i < lines.size(); ++i) {
  1501. pts.push_back(lines[i].first.first);
  1502. pts.push_back(lines[i].first.second);
  1503. }
  1504. polygon_sort(pts.begin(), pts.end());
  1505. for(std::size_t i = 0; i < pts.size(); i+=2) {
  1506. if(pts[i] != pts[i+1]) {
  1507. //stdcout << "Non-closed figures after line intersection!\n";
  1508. return false;
  1509. }
  1510. }
  1511. return true;
  1512. }
  1513. void clear() {*this = property_merge();}
  1514. protected:
  1515. template <typename polygon_type>
  1516. void insert(const polygon_type& polygon_object, const property_type& property_value, bool is_hole,
  1517. polygon_concept ) {
  1518. bool first_iteration = true;
  1519. bool second_iteration = true;
  1520. Point first_point;
  1521. Point second_point;
  1522. Point previous_previous_point;
  1523. Point previous_point;
  1524. Point current_point;
  1525. direction_1d winding_dir = winding(polygon_object);
  1526. for(typename polygon_traits<polygon_type>::iterator_type itr = begin_points(polygon_object);
  1527. itr != end_points(polygon_object); ++itr) {
  1528. assign(current_point, *itr);
  1529. if(first_iteration) {
  1530. first_iteration = false;
  1531. first_point = previous_point = current_point;
  1532. } else if(second_iteration) {
  1533. if(previous_point != current_point) {
  1534. second_iteration = false;
  1535. previous_previous_point = previous_point;
  1536. second_point = previous_point = current_point;
  1537. }
  1538. } else {
  1539. if(previous_point != current_point) {
  1540. create_vertex(pmd, previous_point, current_point, winding_dir,
  1541. is_hole, property_value);
  1542. previous_previous_point = previous_point;
  1543. previous_point = current_point;
  1544. }
  1545. }
  1546. }
  1547. current_point = first_point;
  1548. if(!first_iteration && !second_iteration) {
  1549. if(previous_point != current_point) {
  1550. create_vertex(pmd, previous_point, current_point, winding_dir,
  1551. is_hole, property_value);
  1552. previous_previous_point = previous_point;
  1553. previous_point = current_point;
  1554. }
  1555. current_point = second_point;
  1556. create_vertex(pmd, previous_point, current_point, winding_dir,
  1557. is_hole, property_value);
  1558. previous_previous_point = previous_point;
  1559. previous_point = current_point;
  1560. }
  1561. }
  1562. template <typename polygon_with_holes_type>
  1563. void insert(const polygon_with_holes_type& polygon_with_holes_object, const property_type& property_value, bool is_hole,
  1564. polygon_with_holes_concept tag) {
  1565. insert(polygon_with_holes_object, property_value, is_hole, polygon_concept());
  1566. for(typename polygon_with_holes_traits<polygon_with_holes_type>::iterator_holes_type itr =
  1567. begin_holes(polygon_with_holes_object);
  1568. itr != end_holes(polygon_with_holes_object); ++itr) {
  1569. insert(*itr, property_value, !is_hole, polygon_concept());
  1570. }
  1571. }
  1572. template <typename rectangle_type>
  1573. void insert(const rectangle_type& rectangle_object, const property_type& property_value, bool is_hole,
  1574. rectangle_concept ) {
  1575. polygon_90_data<Unit> poly;
  1576. assign(poly, rectangle_object);
  1577. insert(poly, property_value, is_hole, polygon_concept());
  1578. }
  1579. public: //change to private when done testing
  1580. static inline void create_vertex(property_merge_data& pmd,
  1581. const Point& current_point,
  1582. const Point& next_point,
  1583. direction_1d winding,
  1584. bool is_hole, const property_type& property) {
  1585. if(current_point == next_point) return;
  1586. vertex_property current_vertex;
  1587. current_vertex.first.first = current_point;
  1588. current_vertex.first.second = next_point;
  1589. current_vertex.second.first = property;
  1590. int multiplier = 1;
  1591. if(winding == CLOCKWISE)
  1592. multiplier = -1;
  1593. if(is_hole)
  1594. multiplier *= -1;
  1595. if(current_point < next_point) {
  1596. multiplier *= -1;
  1597. std::swap(current_vertex.first.first, current_vertex.first.second);
  1598. }
  1599. current_vertex.second.second = multiplier * (euclidean_distance(next_point, current_point, HORIZONTAL) == 0 ? -1: 1);
  1600. pmd.push_back(current_vertex);
  1601. //current_vertex.first.second = previous_point;
  1602. //current_vertex.second.second *= -1;
  1603. //pmd.push_back(current_vertex);
  1604. }
  1605. static inline void sort_vertex_half_edges(vertex_data& vertex) {
  1606. less_half_edge_pair lessF(vertex.first);
  1607. polygon_sort(vertex.second.begin(), vertex.second.end(), lessF);
  1608. }
  1609. class less_half_edge_pair {
  1610. private:
  1611. Point pt_;
  1612. public:
  1613. less_half_edge_pair(const Point& pt) : pt_(pt) {}
  1614. bool operator()(const half_edge& e1, const half_edge& e2) {
  1615. const Point& pt1 = e1.first;
  1616. const Point& pt2 = e2.first;
  1617. if(get(pt1, HORIZONTAL) ==
  1618. get(pt_, HORIZONTAL)) {
  1619. //vertical edge is always largest
  1620. return false;
  1621. }
  1622. if(get(pt2, HORIZONTAL) ==
  1623. get(pt_, HORIZONTAL)) {
  1624. //if half edge 1 is not vertical its slope is less than that of half edge 2
  1625. return get(pt1, HORIZONTAL) != get(pt2, HORIZONTAL);
  1626. }
  1627. return scanline_base<Unit>::less_slope(get(pt_, HORIZONTAL),
  1628. get(pt_, VERTICAL), pt1, pt2);
  1629. }
  1630. };
  1631. public:
  1632. //test functions
  1633. template <typename stream_type>
  1634. static stream_type& print (stream_type& o, const property_map& c)
  1635. {
  1636. o << "count: {";
  1637. for(typename property_map::const_iterator itr = c.begin(); itr != c.end(); ++itr) {
  1638. o << ((*itr).first) << ":" << ((*itr).second) << " ";
  1639. }
  1640. return o << "} ";
  1641. }
  1642. template <typename stream_type>
  1643. static stream_type& print (stream_type& o, const half_edge& he)
  1644. {
  1645. o << "half edge: (";
  1646. o << (he.first);
  1647. return o << ", " << (he.second) << ") ";
  1648. }
  1649. template <typename stream_type>
  1650. static stream_type& print (stream_type& o, const vertex_property& c)
  1651. {
  1652. o << "vertex property: {";
  1653. print(o, c.first);
  1654. o << ", " << c.second.first << ":" << c.second.second << " ";
  1655. return o;
  1656. }
  1657. template <typename stream_type>
  1658. static stream_type& print (stream_type& o, const std::vector<vertex_property>& hev)
  1659. {
  1660. o << "vertex properties: {";
  1661. for(std::size_t i = 0; i < hev.size(); ++i) {
  1662. print(o, (hev[i])) << " ";
  1663. }
  1664. return o << "} ";
  1665. }
  1666. template <typename stream_type>
  1667. static stream_type& print (stream_type& o, const std::vector<half_edge>& hev)
  1668. {
  1669. o << "half edges: {";
  1670. for(std::size_t i = 0; i < hev.size(); ++i) {
  1671. print(o, (hev[i])) << " ";
  1672. }
  1673. return o << "} ";
  1674. }
  1675. template <typename stream_type>
  1676. static stream_type& print (stream_type& o, const vertex_data& v)
  1677. {
  1678. return print(o << "vertex: <" << (v.first) << ", ", (v.second)) << "> ";
  1679. }
  1680. template <typename stream_type>
  1681. static stream_type& print (stream_type& o, const std::vector<vertex_data>& vv)
  1682. {
  1683. o << "vertices: {";
  1684. for(std::size_t i = 0; i < vv.size(); ++i) {
  1685. print(o, (vv[i])) << " ";
  1686. }
  1687. return o << "} ";
  1688. }
  1689. template <typename stream_type>
  1690. static inline bool test_insertion(stream_type& stdcout) {
  1691. property_merge si;
  1692. rectangle_data<Unit> rect;
  1693. xl(rect, 0);
  1694. yl(rect, 1);
  1695. xh(rect, 10);
  1696. yh(rect, 11);
  1697. si.insert(rect, 333);
  1698. print(stdcout, si.pmd) << "\n";
  1699. Point pts[4] = {Point(0, 0), Point(10,-3), Point(13, 8), Point(0, 0) };
  1700. polygon_data<Unit> poly;
  1701. property_merge si2;
  1702. poly.set(pts, pts+3);
  1703. si2.insert(poly, 444);
  1704. si2.sort_property_merge_data();
  1705. print(stdcout, si2.pmd) << "\n";
  1706. property_merge si3;
  1707. poly.set(pts, pts+4);
  1708. si3.insert(poly, 444);
  1709. si3.sort_property_merge_data();
  1710. stdcout << (si2.pmd == si3.pmd) << "\n";
  1711. std::reverse(pts, pts+4);
  1712. property_merge si4;
  1713. poly.set(pts, pts+4);
  1714. si4.insert(poly, 444);
  1715. si4.sort_property_merge_data();
  1716. print(stdcout, si4.pmd) << "\n";
  1717. stdcout << (si2.pmd == si4.pmd) << "\n";
  1718. std::reverse(pts, pts+3);
  1719. property_merge si5;
  1720. poly.set(pts, pts+4);
  1721. si5.insert(poly, 444);
  1722. si5.sort_property_merge_data();
  1723. stdcout << (si2.pmd == si5.pmd) << "\n";
  1724. return true;
  1725. }
  1726. template <typename stream_type>
  1727. static inline bool test_merge(stream_type& stdcout) {
  1728. property_merge si;
  1729. rectangle_data<Unit> rect;
  1730. xl(rect, 0);
  1731. yl(rect, 1);
  1732. xh(rect, 10);
  1733. yh(rect, 11);
  1734. si.insert(rect, 333);
  1735. std::map<std::set<property_type>, polygon_set_data<Unit> > result;
  1736. si.merge(result);
  1737. print(stdcout, si.pmd) << "\n";
  1738. polygon_set_data<Unit> psd = (*(result.begin())).second;
  1739. std::vector<polygon_data<Unit> > polys;
  1740. psd.get(polys);
  1741. if(polys.size() != 1) {
  1742. stdcout << "fail merge 1\n";
  1743. return false;
  1744. }
  1745. stdcout << (polys[0]) << "\n";
  1746. si.clear();
  1747. std::vector<Point> pts;
  1748. pts.push_back(Point(0, 0));
  1749. pts.push_back(Point(10, -10));
  1750. pts.push_back(Point(10, 10));
  1751. polygon_data<Unit> poly;
  1752. poly.set(pts.begin(), pts.end());
  1753. si.insert(poly, 444);
  1754. pts.clear();
  1755. pts.push_back(Point(5, 0));
  1756. pts.push_back(Point(-5, -10));
  1757. pts.push_back(Point(-5, 10));
  1758. poly.set(pts.begin(), pts.end());
  1759. si.insert(poly, 444);
  1760. result.clear();
  1761. si.merge(result);
  1762. print(stdcout, si.pmd) << "\n";
  1763. psd = (*(result.begin())).second;
  1764. stdcout << psd << "\n";
  1765. polys.clear();
  1766. psd.get(polys);
  1767. if(polys.size() != 1) {
  1768. stdcout << "fail merge 2\n";
  1769. return false;
  1770. }
  1771. //Polygon { -4 -1, 3 3, -2 3 }
  1772. //Polygon { 0 -4, -4 -2, -2 1 }
  1773. si.clear();
  1774. pts.clear();
  1775. pts.push_back(Point(-4, -1));
  1776. pts.push_back(Point(3, 3));
  1777. pts.push_back(Point(-2, 3));
  1778. poly.set(pts.begin(), pts.end());
  1779. si.insert(poly, 444);
  1780. pts.clear();
  1781. pts.push_back(Point(0, -4));
  1782. pts.push_back(Point(-4, -2));
  1783. pts.push_back(Point(-2, 1));
  1784. poly.set(pts.begin(), pts.end());
  1785. si.insert(poly, 444);
  1786. result.clear();
  1787. si.merge(result);
  1788. print(stdcout, si.pmd) << "\n";
  1789. psd = (*(result.begin())).second;
  1790. stdcout << psd << "\n";
  1791. polys.clear();
  1792. psd.get(polys);
  1793. if(polys.size() != 1) {
  1794. stdcout << "fail merge 3\n";
  1795. return false;
  1796. }
  1797. stdcout << "Polygon { -2 2, -2 2, 1 4 } \n";
  1798. stdcout << "Polygon { 2 4, 2 -4, -3 1 } \n";
  1799. si.clear();
  1800. pts.clear();
  1801. pts.push_back(Point(-2, 2));
  1802. pts.push_back(Point(-2, 2));
  1803. pts.push_back(Point(1, 4));
  1804. poly.set(pts.begin(), pts.end());
  1805. si.insert(poly, 444);
  1806. pts.clear();
  1807. pts.push_back(Point(2, 4));
  1808. pts.push_back(Point(2, -4));
  1809. pts.push_back(Point(-3, 1));
  1810. poly.set(pts.begin(), pts.end());
  1811. si.insert(poly, 444);
  1812. result.clear();
  1813. si.merge(result);
  1814. print(stdcout, si.pmd) << "\n";
  1815. psd = (*(result.begin())).second;
  1816. stdcout << psd << "\n";
  1817. polys.clear();
  1818. psd.get(polys);
  1819. if(polys.size() != 1) {
  1820. stdcout << "fail merge 4\n";
  1821. return false;
  1822. }
  1823. stdcout << (polys[0]) << "\n";
  1824. stdcout << "Polygon { -4 0, -2 -3, 3 -4 } \n";
  1825. stdcout << "Polygon { -1 1, 1 -2, -4 -3 } \n";
  1826. si.clear();
  1827. pts.clear();
  1828. pts.push_back(Point(-4, 0));
  1829. pts.push_back(Point(-2, -3));
  1830. pts.push_back(Point(3, -4));
  1831. poly.set(pts.begin(), pts.end());
  1832. si.insert(poly, 444);
  1833. pts.clear();
  1834. pts.push_back(Point(-1, 1));
  1835. pts.push_back(Point(1, -2));
  1836. pts.push_back(Point(-4, -3));
  1837. poly.set(pts.begin(), pts.end());
  1838. si.insert(poly, 444);
  1839. result.clear();
  1840. si.merge(result);
  1841. print(stdcout, si.pmd) << "\n";
  1842. psd = (*(result.begin())).second;
  1843. stdcout << psd << "\n";
  1844. polys.clear();
  1845. psd.get(polys);
  1846. if(polys.size() != 1) {
  1847. stdcout << "fail merge 5\n";
  1848. return false;
  1849. }
  1850. stdcout << "Polygon { 2 2, -2 0, 0 1 } \n";
  1851. stdcout << "Polygon { 4 -2, 3 -1, 2 3 } \n";
  1852. si.clear();
  1853. pts.clear();
  1854. pts.push_back(Point(2, 2));
  1855. pts.push_back(Point(-2, 0));
  1856. pts.push_back(Point(0, 1));
  1857. poly.set(pts.begin(), pts.end());
  1858. si.insert(poly, 444);
  1859. pts.clear();
  1860. pts.push_back(Point(4, -2));
  1861. pts.push_back(Point(3, -1));
  1862. pts.push_back(Point(2, 3));
  1863. poly.set(pts.begin(), pts.end());
  1864. si.insert(poly, 444);
  1865. result.clear();
  1866. si.merge(result);
  1867. print(stdcout, si.pmd) << "\n";
  1868. if(!result.empty()) {
  1869. psd = (*(result.begin())).second;
  1870. stdcout << psd << "\n";
  1871. polys.clear();
  1872. psd.get(polys);
  1873. if(polys.size() != 1) {
  1874. stdcout << "fail merge 6\n";
  1875. return false;
  1876. }
  1877. stdcout << (polys[0]) << "\n";
  1878. }
  1879. stdcout << "Polygon { 0 2, 3 -1, 4 1 } \n";
  1880. stdcout << "Polygon { -4 3, 3 3, 4 2 } \n";
  1881. si.clear();
  1882. pts.clear();
  1883. pts.push_back(Point(0, 2));
  1884. pts.push_back(Point(3, -1));
  1885. pts.push_back(Point(4, 1));
  1886. poly.set(pts.begin(), pts.end());
  1887. si.insert(poly, 444);
  1888. pts.clear();
  1889. pts.push_back(Point(-4, 3));
  1890. pts.push_back(Point(3, 3));
  1891. pts.push_back(Point(4, 2));
  1892. poly.set(pts.begin(), pts.end());
  1893. si.insert(poly, 444);
  1894. result.clear();
  1895. si.merge(result);
  1896. print(stdcout, si.pmd) << "\n";
  1897. if(!result.empty()) {
  1898. psd = (*(result.begin())).second;
  1899. stdcout << psd << "\n";
  1900. polys.clear();
  1901. psd.get(polys);
  1902. if(polys.size() == 0) {
  1903. stdcout << "fail merge 7\n";
  1904. return false;
  1905. }
  1906. stdcout << (polys[0]) << "\n";
  1907. }
  1908. stdcout << "Polygon { 1 -2, -1 4, 3 -2 } \n";
  1909. stdcout << "Polygon { 0 -3, 3 1, -3 -4 } \n";
  1910. si.clear();
  1911. pts.clear();
  1912. pts.push_back(Point(1, -2));
  1913. pts.push_back(Point(-1, 4));
  1914. pts.push_back(Point(3, -2));
  1915. poly.set(pts.begin(), pts.end());
  1916. si.insert(poly, 444);
  1917. pts.clear();
  1918. pts.push_back(Point(0, -3));
  1919. pts.push_back(Point(3, 1));
  1920. pts.push_back(Point(-3, -4));
  1921. poly.set(pts.begin(), pts.end());
  1922. si.insert(poly, 444);
  1923. result.clear();
  1924. si.merge(result);
  1925. print(stdcout, si.pmd) << "\n";
  1926. if(!result.empty()) {
  1927. psd = (*(result.begin())).second;
  1928. stdcout << psd << "\n";
  1929. polys.clear();
  1930. psd.get(polys);
  1931. if(polys.size() == 0) {
  1932. stdcout << "fail merge 8\n";
  1933. return false;
  1934. }
  1935. stdcout << (polys[0]) << "\n";
  1936. }
  1937. stdcout << "Polygon { 2 2, 3 0, -3 4 } \n";
  1938. stdcout << "Polygon { -2 -2, 0 0, -1 -1 } \n";
  1939. si.clear();
  1940. pts.clear();
  1941. pts.push_back(Point(2, 2));
  1942. pts.push_back(Point(3, 0));
  1943. pts.push_back(Point(-3, 4));
  1944. poly.set(pts.begin(), pts.end());
  1945. si.insert(poly, 444);
  1946. pts.clear();
  1947. pts.push_back(Point(-2, -2));
  1948. pts.push_back(Point(0, 0));
  1949. pts.push_back(Point(-1, -1));
  1950. poly.set(pts.begin(), pts.end());
  1951. si.insert(poly, 444);
  1952. result.clear();
  1953. si.merge(result);
  1954. print(stdcout, si.pmd) << "\n";
  1955. if(!result.empty()) {
  1956. psd = (*(result.begin())).second;
  1957. stdcout << psd << "\n";
  1958. polys.clear();
  1959. psd.get(polys);
  1960. if(polys.size() == 0) {
  1961. stdcout << "fail merge 9\n";
  1962. return false;
  1963. }
  1964. stdcout << (polys[0]) << "\n";
  1965. }
  1966. si.clear();
  1967. pts.clear();
  1968. //5624841,17616200,75000,9125000
  1969. //pts.push_back(Point(5624841,75000));
  1970. //pts.push_back(Point(5624841,9125000));
  1971. //pts.push_back(Point(17616200,9125000));
  1972. //pts.push_back(Point(17616200,75000));
  1973. pts.push_back(Point(12262940, 6652520 )); pts.push_back(Point(12125750, 6652520 )); pts.push_back(Point(12121272, 6652961 )); pts.push_back(Point(12112981, 6656396 )); pts.push_back(Point(12106636, 6662741 )); pts.push_back(Point(12103201, 6671032 )); pts.push_back(Point(12103201, 6680007 )); pts.push_back(Point(12106636, 6688298 ));
  1974. pts.push_back(Point(12109500, 6691780 )); pts.push_back(Point(12748600, 7330890 )); pts.push_back(Point(15762600, 7330890 )); pts.push_back(Point(15904620, 7472900 )); pts.push_back(Point(15909200, 7473030 )); pts.push_back(Point(15935830, 7476006 )); pts.push_back(Point(15992796, 7499602 )); pts.push_back(Point(16036397, 7543203 ));
  1975. pts.push_back(Point(16059993, 7600169 )); pts.push_back(Point(16059993, 7661830 )); pts.push_back(Point(16036397, 7718796 )); pts.push_back(Point(15992796, 7762397 )); pts.push_back(Point(15935830, 7785993 )); pts.push_back(Point(15874169, 7785993 )); pts.push_back(Point(15817203, 7762397 )); pts.push_back(Point(15773602, 7718796 ));
  1976. pts.push_back(Point(15750006, 7661830 )); pts.push_back(Point(15747030, 7635200 )); pts.push_back(Point(15746900, 7630620 )); pts.push_back(Point(15670220, 7553930 )); pts.push_back(Point(14872950, 7553930 )); pts.push_back(Point(14872950, 7626170 ));
  1977. pts.push_back(Point(14869973, 7661280 )); pts.push_back(Point(14846377, 7718246 )); pts.push_back(Point(14802776, 7761847 )); pts.push_back(Point(14745810, 7785443 )); pts.push_back(Point(14684149, 7785443 )); pts.push_back(Point(14627183, 7761847 )); pts.push_back(Point(14583582, 7718246 ));
  1978. pts.push_back(Point(14559986, 7661280 )); pts.push_back(Point(14557070, 7636660 )); pts.push_back(Point(14556670, 7625570 )); pts.push_back(Point(13703330, 7625570 )); pts.push_back(Point(13702930, 7636660 )); pts.push_back(Point(13699993, 7661830 )); pts.push_back(Point(13676397, 7718796 ));
  1979. pts.push_back(Point(13632796, 7762397 )); pts.push_back(Point(13575830, 7785993 )); pts.push_back(Point(13514169, 7785993 )); pts.push_back(Point(13457203, 7762397 )); pts.push_back(Point(13436270, 7745670 )); pts.push_back(Point(13432940, 7742520 )); pts.push_back(Point(12963760, 7742520 ));
  1980. pts.push_back(Point(12959272, 7742961 )); pts.push_back(Point(12950981, 7746396 )); pts.push_back(Point(12944636, 7752741 )); pts.push_back(Point(12941201, 7761032 )); pts.push_back(Point(12941201, 7770007 )); pts.push_back(Point(12944636, 7778298 )); pts.push_back(Point(12947490, 7781780 ));
  1981. pts.push_back(Point(13425330, 8259620 )); pts.push_back(Point(15601330, 8259620 )); pts.push_back(Point(15904620, 8562900 )); pts.push_back(Point(15909200, 8563030 )); pts.push_back(Point(15935830, 8566006 )); pts.push_back(Point(15992796, 8589602 )); pts.push_back(Point(16036397, 8633203 ));
  1982. pts.push_back(Point(16059993, 8690169 )); pts.push_back(Point(16059993, 8751830 )); pts.push_back(Point(16036397, 8808796 )); pts.push_back(Point(15992796, 8852397 )); pts.push_back(Point(15935830, 8875993 )); pts.push_back(Point(15874169, 8875993 )); pts.push_back(Point(15817203, 8852397 )); pts.push_back(Point(15773602, 8808796 ));
  1983. pts.push_back(Point(15750006, 8751830 )); pts.push_back(Point(15747030, 8725200 )); pts.push_back(Point(15746900, 8720620 )); pts.push_back(Point(15508950, 8482660 )); pts.push_back(Point(14689890, 8482660 )); pts.push_back(Point(14685412, 8483101 )); pts.push_back(Point(14677121, 8486536 ));
  1984. pts.push_back(Point(14670776, 8492881 )); pts.push_back(Point(14667341, 8501172 )); pts.push_back(Point(14667341, 8510147 )); pts.push_back(Point(14670776, 8518438 )); pts.push_back(Point(14673630, 8521920 )); pts.push_back(Point(14714620, 8562900 )); pts.push_back(Point(14719200, 8563030 )); pts.push_back(Point(14745830, 8566006 ));
  1985. pts.push_back(Point(14802796, 8589602 )); pts.push_back(Point(14846397, 8633203 )); pts.push_back(Point(14869993, 8690169 )); pts.push_back(Point(14869993, 8751830 )); pts.push_back(Point(14846397, 8808796 )); pts.push_back(Point(14802796, 8852397 )); pts.push_back(Point(14745830, 8875993 )); pts.push_back(Point(14684169, 8875993 ));
  1986. pts.push_back(Point(14627203, 8852397 )); pts.push_back(Point(14583602, 8808796 )); pts.push_back(Point(14560006, 8751830 )); pts.push_back(Point(14557030, 8725200 )); pts.push_back(Point(14556900, 8720620 )); pts.push_back(Point(14408270, 8571980 )); pts.push_back(Point(13696320, 8571980 )); pts.push_back(Point(13696320, 8675520 ));
  1987. pts.push_back(Point(13699963, 8690161 )); pts.push_back(Point(13699963, 8751818 )); pts.push_back(Point(13676368, 8808781 )); pts.push_back(Point(13632771, 8852378 )); pts.push_back(Point(13575808, 8875973 )); pts.push_back(Point(13514151, 8875973 )); pts.push_back(Point(13457188, 8852378 )); pts.push_back(Point(13436270, 8835670 )); pts.push_back(Point(13432940, 8832520 ));
  1988. pts.push_back(Point(13281760, 8832520 )); pts.push_back(Point(13277272, 8832961 )); pts.push_back(Point(13268981, 8836396 )); pts.push_back(Point(13262636, 8842741 )); pts.push_back(Point(13259201, 8851032 )); pts.push_back(Point(13259201, 8860007 )); pts.push_back(Point(13262636, 8868298 )); pts.push_back(Point(13265500, 8871780 ));
  1989. pts.push_back(Point(13518710, 9125000 )); pts.push_back(Point(16270720, 9125000 )); pts.push_back(Point(16270720, 8939590 )); pts.push_back(Point(17120780, 8939590 )); pts.push_back(Point(17120780, 9125000 )); pts.push_back(Point(17616200, 9125000 )); pts.push_back(Point(17616200, 75000 )); pts.push_back(Point(16024790, 75000 ));
  1990. pts.push_back(Point(16021460, 80700 )); pts.push_back(Point(16016397, 88796 )); pts.push_back(Point(15972796, 132397 )); pts.push_back(Point(15915830, 155993 )); pts.push_back(Point(15908730, 157240 )); pts.push_back(Point(15905000, 157800 )); pts.push_back(Point(15516800, 546000 )); pts.push_back(Point(15905000, 934200 ));
  1991. pts.push_back(Point(15908730, 934760 )); pts.push_back(Point(15915830, 936006 )); pts.push_back(Point(15972796, 959602 )); pts.push_back(Point(16016397, 1003203 )); pts.push_back(Point(16039993, 1060169 )); pts.push_back(Point(16039993, 1121830 )); pts.push_back(Point(16016397, 1178796 )); pts.push_back(Point(15972796, 1222397 ));
  1992. pts.push_back(Point(15915830, 1245993 )); pts.push_back(Point(15854169, 1245993 )); pts.push_back(Point(15797203, 1222397 )); pts.push_back(Point(15753602, 1178796 )); pts.push_back(Point(15730006, 1121830 )); pts.push_back(Point(15728760, 1114730 )); pts.push_back(Point(15728200, 1111000 )); pts.push_back(Point(15363500, 746300 ));
  1993. pts.push_back(Point(14602620, 746300 )); pts.push_back(Point(14598142, 746741 )); pts.push_back(Point(14589851, 750176 )); pts.push_back(Point(14583506, 756521 )); pts.push_back(Point(14580071, 764812 )); pts.push_back(Point(14580071, 773787 )); pts.push_back(Point(14583506, 782078 )); pts.push_back(Point(14586360, 785560 ));
  1994. pts.push_back(Point(14586370, 785560 )); pts.push_back(Point(14735000, 934200 )); pts.push_back(Point(14738730, 934760 )); pts.push_back(Point(14745830, 936006 )); pts.push_back(Point(14802796, 959602 )); pts.push_back(Point(14846397, 1003203 )); pts.push_back(Point(14869993, 1060169 ));
  1995. pts.push_back(Point(14870450, 1062550 )); pts.push_back(Point(14872170, 1071980 )); pts.push_back(Point(14972780, 1071980 )); pts.push_back(Point(15925000, 2024200 )); pts.push_back(Point(15928730, 2024760 )); pts.push_back(Point(15935830, 2026006 )); pts.push_back(Point(15992796, 2049602 ));
  1996. pts.push_back(Point(16036397, 2093203 )); pts.push_back(Point(16059993, 2150169 )); pts.push_back(Point(16059993, 2211830 )); pts.push_back(Point(16036397, 2268796 )); pts.push_back(Point(15992796, 2312397 )); pts.push_back(Point(15935830, 2335993 )); pts.push_back(Point(15874169, 2335993 ));
  1997. pts.push_back(Point(15817203, 2312397 )); pts.push_back(Point(15773602, 2268796 )); pts.push_back(Point(15750006, 2211830 )); pts.push_back(Point(15748760, 2204730 )); pts.push_back(Point(15748200, 2201000 )); pts.push_back(Point(14869220, 1322020 )); pts.push_back(Point(14088350, 1322020 ));
  1998. pts.push_back(Point(14083862, 1322461 )); pts.push_back(Point(14075571, 1325896 )); pts.push_back(Point(14069226, 1332241 )); pts.push_back(Point(14065791, 1340532 )); pts.push_back(Point(14065791, 1349507 )); pts.push_back(Point(14069226, 1357798 )); pts.push_back(Point(14072080, 1361280 ));
  1999. pts.push_back(Point(14072090, 1361280 )); pts.push_back(Point(14735000, 2024200 )); pts.push_back(Point(14738730, 2024760 )); pts.push_back(Point(14745830, 2026006 )); pts.push_back(Point(14802796, 2049602 )); pts.push_back(Point(14846397, 2093203 )); pts.push_back(Point(14869993, 2150169 ));
  2000. pts.push_back(Point(14869993, 2211830 )); pts.push_back(Point(14846397, 2268796 )); pts.push_back(Point(14802796, 2312397 )); pts.push_back(Point(14745830, 2335993 )); pts.push_back(Point(14684169, 2335993 )); pts.push_back(Point(14627203, 2312397 )); pts.push_back(Point(14583602, 2268796 )); pts.push_back(Point(14560006, 2211830 ));
  2001. pts.push_back(Point(14558760, 2204730 )); pts.push_back(Point(14558200, 2201000 )); pts.push_back(Point(13752220, 1395020 )); pts.push_back(Point(12991340, 1395020 )); pts.push_back(Point(12986862, 1395461 )); pts.push_back(Point(12978571, 1398896 )); pts.push_back(Point(12972226, 1405241 ));
  2002. pts.push_back(Point(12968791, 1413532 )); pts.push_back(Point(12968791, 1422507 )); pts.push_back(Point(12972226, 1430798 )); pts.push_back(Point(12975080, 1434280 )); pts.push_back(Point(12975090, 1434280 )); pts.push_back(Point(13565000, 2024200 )); pts.push_back(Point(13568730, 2024760 )); pts.push_back(Point(13575830, 2026006 ));
  2003. pts.push_back(Point(13632796, 2049602 )); pts.push_back(Point(13676397, 2093203 )); pts.push_back(Point(13699993, 2150169 )); pts.push_back(Point(13699993, 2211830 )); pts.push_back(Point(13676397, 2268796 )); pts.push_back(Point(13632796, 2312397 )); pts.push_back(Point(13575830, 2335993 ));
  2004. pts.push_back(Point(13514169, 2335993 )); pts.push_back(Point(13457203, 2312397 )); pts.push_back(Point(13413602, 2268796 )); pts.push_back(Point(13390006, 2211830 )); pts.push_back(Point(13388760, 2204730 )); pts.push_back(Point(13388200, 2201000 )); pts.push_back(Point(12655220, 1468020 ));
  2005. pts.push_back(Point(11894340, 1468020 )); pts.push_back(Point(11889862, 1468461 )); pts.push_back(Point(11881571, 1471896 )); pts.push_back(Point(11875226, 1478241 )); pts.push_back(Point(11871791, 1486532 )); pts.push_back(Point(11871791, 1495507 ));
  2006. pts.push_back(Point(11875226, 1503798 )); pts.push_back(Point(11878090, 1507280 )); pts.push_back(Point(12395000, 2024200 )); pts.push_back(Point(12398730, 2024760 )); pts.push_back(Point(12405830, 2026006 )); pts.push_back(Point(12462796, 2049602 )); pts.push_back(Point(12506397, 2093203 ));
  2007. pts.push_back(Point(12529993, 2150169 )); pts.push_back(Point(12529993, 2211830 )); pts.push_back(Point(12506397, 2268796 )); pts.push_back(Point(12462796, 2312397 )); pts.push_back(Point(12405830, 2335993 )); pts.push_back(Point(12344169, 2335993 ));
  2008. pts.push_back(Point(12287203, 2312397 )); pts.push_back(Point(12243602, 2268796 )); pts.push_back(Point(12220006, 2211830 )); pts.push_back(Point(12218760, 2204730 )); pts.push_back(Point(12218200, 2201000 )); pts.push_back(Point(11558220, 1541020 ));
  2009. pts.push_back(Point(10797340, 1541020 )); pts.push_back(Point(10792862, 1541461 )); pts.push_back(Point(10784571, 1544896 )); pts.push_back(Point(10778226, 1551241 )); pts.push_back(Point(10774791, 1559532 )); pts.push_back(Point(10774791, 1568507 )); pts.push_back(Point(10778226, 1576798 )); pts.push_back(Point(10781080, 1580280 ));
  2010. pts.push_back(Point(10781090, 1580280 )); pts.push_back(Point(11225000, 2024200 )); pts.push_back(Point(11228730, 2024760 )); pts.push_back(Point(11235830, 2026006 )); pts.push_back(Point(11292796, 2049602 )); pts.push_back(Point(11336397, 2093203 )); pts.push_back(Point(11359993, 2150169 ));
  2011. pts.push_back(Point(11359993, 2211830 )); pts.push_back(Point(11336397, 2268796 )); pts.push_back(Point(11292796, 2312397 )); pts.push_back(Point(11235830, 2335993 )); pts.push_back(Point(11174169, 2335993 )); pts.push_back(Point(11117203, 2312397 )); pts.push_back(Point(11073602, 2268796 )); pts.push_back(Point(11050006, 2211830 ));
  2012. pts.push_back(Point(11048760, 2204730 )); pts.push_back(Point(11048200, 2201000 )); pts.push_back(Point(10461220, 1614020 )); pts.push_back(Point( 5647400, 1614020 )); pts.push_back(Point( 5642912, 1614461 ));
  2013. pts.push_back(Point( 5634621, 1617896 )); pts.push_back(Point( 5628276, 1624241 )); pts.push_back(Point( 5624841, 1632532 )); pts.push_back(Point( 5624841, 1641507 )); pts.push_back(Point( 5628276, 1649798 )); pts.push_back(Point( 5631130, 1653280 ));
  2014. pts.push_back(Point( 5688490, 1710640 )); pts.push_back(Point( 9722350, 1710640 )); pts.push_back(Point(10034620, 2022900 )); pts.push_back(Point(10039200, 2023030 )); pts.push_back(Point(10065830, 2026006 )); pts.push_back(Point(10122796, 2049602 ));
  2015. pts.push_back(Point(10166397, 2093203 )); pts.push_back(Point(10189993, 2150169 )); pts.push_back(Point(10189993, 2211830 )); pts.push_back(Point(10166397, 2268796 )); pts.push_back(Point(10158620, 2279450 )); pts.push_back(Point(10158620, 2404900 )); pts.push_back(Point(10548950, 2795240 ));
  2016. pts.push_back(Point(15586950, 2795240 )); pts.push_back(Point(15904620, 3112900 )); pts.push_back(Point(15909200, 3113030 )); pts.push_back(Point(15935830, 3116006 )); pts.push_back(Point(15992796, 3139602 )); pts.push_back(Point(16036397, 3183203 )); pts.push_back(Point(16059993, 3240169 )); pts.push_back(Point(16059993, 3301830 ));
  2017. pts.push_back(Point(16036397, 3358796 )); pts.push_back(Point(15992796, 3402397 )); pts.push_back(Point(15935830, 3425993 )); pts.push_back(Point(15874169, 3425993 )); pts.push_back(Point(15817203, 3402397 )); pts.push_back(Point(15773602, 3358796 )); pts.push_back(Point(15750006, 3301830 )); pts.push_back(Point(15747030, 3275200 ));
  2018. pts.push_back(Point(15746900, 3270620 )); pts.push_back(Point(15494570, 3018280 )); pts.push_back(Point(14675510, 3018280 )); pts.push_back(Point(14671032, 3018721 )); pts.push_back(Point(14662741, 3022156 )); pts.push_back(Point(14656396, 3028501 )); pts.push_back(Point(14652961, 3036792 ));
  2019. pts.push_back(Point(14652961, 3045767 )); pts.push_back(Point(14656396, 3054058 )); pts.push_back(Point(14659260, 3057540 )); pts.push_back(Point(14714620, 3112900 )); pts.push_back(Point(14719200, 3113030 )); pts.push_back(Point(14745830, 3116006 )); pts.push_back(Point(14802796, 3139602 ));
  2020. pts.push_back(Point(14846397, 3183203 )); pts.push_back(Point(14869993, 3240169 )); pts.push_back(Point(14869993, 3301830 )); pts.push_back(Point(14846397, 3358796 )); pts.push_back(Point(14802796, 3402397 )); pts.push_back(Point(14745830, 3425993 )); pts.push_back(Point(14684169, 3425993 )); pts.push_back(Point(14627203, 3402397 ));
  2021. pts.push_back(Point(14583602, 3358796 )); pts.push_back(Point(14560006, 3301830 )); pts.push_back(Point(14557030, 3275200 )); pts.push_back(Point(14556900, 3270620 )); pts.push_back(Point(14370700, 3084410 )); pts.push_back(Point(13702830, 3084410 )); pts.push_back(Point(13702830, 3263160 ));
  2022. pts.push_back(Point(13700003, 3302210 )); pts.push_back(Point(13676407, 3359176 )); pts.push_back(Point(13632806, 3402777 )); pts.push_back(Point(13575840, 3426373 )); pts.push_back(Point(13514179, 3426373 )); pts.push_back(Point(13457213, 3402777 )); pts.push_back(Point(13413612, 3359176 ));
  2023. pts.push_back(Point(13390016, 3302210 )); pts.push_back(Point(13387030, 3275200 )); pts.push_back(Point(13386900, 3270620 )); pts.push_back(Point(13266840, 3150550 )); pts.push_back(Point(12532920, 3150550 )); pts.push_back(Point(12532920, 3264990 )); pts.push_back(Point(12529993, 3301820 ));
  2024. pts.push_back(Point(12506397, 3358786 )); pts.push_back(Point(12462796, 3402387 )); pts.push_back(Point(12405830, 3425983 )); pts.push_back(Point(12344169, 3425983 )); pts.push_back(Point(12287203, 3402387 )); pts.push_back(Point(12243602, 3358786 )); pts.push_back(Point(12220006, 3301820 )); pts.push_back(Point(12217030, 3275200 ));
  2025. pts.push_back(Point(12216900, 3270620 )); pts.push_back(Point(12157460, 3211170 )); pts.push_back(Point(11362030, 3211170 )); pts.push_back(Point(11360250, 3220520 )); pts.push_back(Point(11359993, 3221830 )); pts.push_back(Point(11336397, 3278796 ));
  2026. pts.push_back(Point(11292796, 3322397 )); pts.push_back(Point(11235830, 3345993 )); pts.push_back(Point(11174169, 3345993 )); pts.push_back(Point(11117203, 3322397 )); pts.push_back(Point(11096270, 3305670 )); pts.push_back(Point(11092940, 3302520 )); pts.push_back(Point(10680760, 3302520 ));
  2027. pts.push_back(Point(10676272, 3302961 )); pts.push_back(Point(10667981, 3306396 )); pts.push_back(Point(10661636, 3312741 )); pts.push_back(Point(10658201, 3321032 )); pts.push_back(Point(10658201, 3330007 )); pts.push_back(Point(10661636, 3338298 )); pts.push_back(Point(10664500, 3341780 ));
  2028. pts.push_back(Point(11264260, 3941550 )); pts.push_back(Point(15643260, 3941550 )); pts.push_back(Point(15904620, 4202900 )); pts.push_back(Point(15909200, 4203030 )); pts.push_back(Point(15935830, 4206006 )); pts.push_back(Point(15992796, 4229602 ));
  2029. pts.push_back(Point(16036397, 4273203 )); pts.push_back(Point(16059993, 4330169 )); pts.push_back(Point(16059993, 4391830 )); pts.push_back(Point(16036397, 4448796 )); pts.push_back(Point(15992796, 4492397 ));
  2030. pts.push_back(Point(15935830, 4515993 )); pts.push_back(Point(15874169, 4515993 )); pts.push_back(Point(15817203, 4492397 )); pts.push_back(Point(15773602, 4448796 )); pts.push_back(Point(15750006, 4391830 )); pts.push_back(Point(15747030, 4365200 )); pts.push_back(Point(15746900, 4360620 ));
  2031. pts.push_back(Point(15550880, 4164590 )); pts.push_back(Point(14825070, 4164590 )); pts.push_back(Point(14825070, 4247610 )); pts.push_back(Point(14846397, 4273213 )); pts.push_back(Point(14869993, 4330179 )); pts.push_back(Point(14869993, 4391840 )); pts.push_back(Point(14846397, 4448806 ));
  2032. pts.push_back(Point(14802796, 4492407 )); pts.push_back(Point(14745830, 4516003 )); pts.push_back(Point(14684169, 4516003 )); pts.push_back(Point(14627203, 4492407 )); pts.push_back(Point(14583602, 4448806 )); pts.push_back(Point(14560006, 4391840 )); pts.push_back(Point(14557030, 4365200 ));
  2033. pts.push_back(Point(14556900, 4360620 )); pts.push_back(Point(14432520, 4236230 )); pts.push_back(Point(13702830, 4236230 )); pts.push_back(Point(13702830, 4352930 )); pts.push_back(Point(13699993, 4391750 )); pts.push_back(Point(13676397, 4448716 ));
  2034. pts.push_back(Point(13632796, 4492317 )); pts.push_back(Point(13575830, 4515913 )); pts.push_back(Point(13514169, 4515913 )); pts.push_back(Point(13457203, 4492317 )); pts.push_back(Point(13413602, 4448716 )); pts.push_back(Point(13390006, 4391750 )); pts.push_back(Point(13387030, 4365200 ));
  2035. pts.push_back(Point(13386900, 4360620 )); pts.push_back(Point(13334170, 4307880 )); pts.push_back(Point(12532990, 4307880 )); pts.push_back(Point(12532990, 4357550 )); pts.push_back(Point(12529993, 4391760 )); pts.push_back(Point(12506397, 4448726 )); pts.push_back(Point(12462796, 4492327 ));
  2036. pts.push_back(Point(12405830, 4515923 )); pts.push_back(Point(12344169, 4515923 )); pts.push_back(Point(12287203, 4492327 )); pts.push_back(Point(12243602, 4448726 )); pts.push_back(Point(12220006, 4391760 )); pts.push_back(Point(12217970, 4378710 )); pts.push_back(Point(12216810, 4368500 ));
  2037. pts.push_back(Point(11363190, 4368500 )); pts.push_back(Point(11362030, 4378710 )); pts.push_back(Point(11359983, 4391828 )); pts.push_back(Point(11336388, 4448791 )); pts.push_back(Point(11292791, 4492388 )); pts.push_back(Point(11235828, 4515983 )); pts.push_back(Point(11174171, 4515983 )); pts.push_back(Point(11117208, 4492388 ));
  2038. pts.push_back(Point(11096270, 4475670 )); pts.push_back(Point(11092940, 4472520 )); pts.push_back(Point(11057750, 4472520 )); pts.push_back(Point(11053272, 4472961 )); pts.push_back(Point(11044981, 4476396 )); pts.push_back(Point(11038636, 4482741 )); pts.push_back(Point(11035201, 4491032 ));
  2039. pts.push_back(Point(11035201, 4500007 )); pts.push_back(Point(11038636, 4508298 )); pts.push_back(Point(11041490, 4511780 )); pts.push_back(Point(11573490, 5043780 )); pts.push_back(Point(15655490, 5043780 )); pts.push_back(Point(15904620, 5292900 ));
  2040. pts.push_back(Point(15909200, 5293030 )); pts.push_back(Point(15935830, 5296006 )); pts.push_back(Point(15992796, 5319602 )); pts.push_back(Point(16036397, 5363203 )); pts.push_back(Point(16059993, 5420169 )); pts.push_back(Point(16059993, 5481830 )); pts.push_back(Point(16036397, 5538796 ));
  2041. pts.push_back(Point(15992796, 5582397 )); pts.push_back(Point(15935830, 5605993 )); pts.push_back(Point(15874169, 5605993 )); pts.push_back(Point(15817203, 5582397 )); pts.push_back(Point(15773602, 5538796 )); pts.push_back(Point(15750006, 5481830 )); pts.push_back(Point(15747030, 5455200 ));
  2042. pts.push_back(Point(15746900, 5450620 )); pts.push_back(Point(15563110, 5266820 )); pts.push_back(Point(14857380, 5266820 )); pts.push_back(Point(14857380, 5382430 )); pts.push_back(Point(14869993, 5420179 )); pts.push_back(Point(14869993, 5481840 )); pts.push_back(Point(14846397, 5538806 )); pts.push_back(Point(14802796, 5582407 ));
  2043. pts.push_back(Point(14745830, 5606003 )); pts.push_back(Point(14684169, 5606003 )); pts.push_back(Point(14627203, 5582407 )); pts.push_back(Point(14583602, 5538806 )); pts.push_back(Point(14560006, 5481840 )); pts.push_back(Point(14557030, 5455200 )); pts.push_back(Point(14556900, 5450620 )); pts.push_back(Point(14444750, 5338460 ));
  2044. pts.push_back(Point(13702890, 5338460 )); pts.push_back(Point(13702890, 5364400 )); pts.push_back(Point(13699993, 5401800 )); pts.push_back(Point(13676397, 5458766 )); pts.push_back(Point(13632796, 5502367 )); pts.push_back(Point(13575830, 5525963 )); pts.push_back(Point(13514169, 5525963 )); pts.push_back(Point(13457203, 5502367 ));
  2045. pts.push_back(Point(13413602, 5458766 )); pts.push_back(Point(13390006, 5401800 )); pts.push_back(Point(13389230, 5397620 )); pts.push_back(Point(13387590, 5388060 )); pts.push_back(Point(12532960, 5388060 )); pts.push_back(Point(12532960, 5446220 )); pts.push_back(Point(12529993, 5481820 ));
  2046. pts.push_back(Point(12506397, 5538786 )); pts.push_back(Point(12462796, 5582387 )); pts.push_back(Point(12405830, 5605983 )); pts.push_back(Point(12344169, 5605983 )); pts.push_back(Point(12287203, 5582387 )); pts.push_back(Point(12266270, 5565670 )); pts.push_back(Point(12262940, 5562520 )); pts.push_back(Point(11737750, 5562520 ));
  2047. pts.push_back(Point(11733272, 5562961 )); pts.push_back(Point(11724981, 5566396 )); pts.push_back(Point(11718636, 5572741 )); pts.push_back(Point(11715201, 5581032 )); pts.push_back(Point(11715201, 5590007 )); pts.push_back(Point(11718636, 5598298 )); pts.push_back(Point(11721500, 5601780 ));
  2048. pts.push_back(Point(12287760, 6168050 )); pts.push_back(Point(15689760, 6168050 )); pts.push_back(Point(15904620, 6382900 )); pts.push_back(Point(15909200, 6383030 )); pts.push_back(Point(15935830, 6386006 )); pts.push_back(Point(15992796, 6409602 ));
  2049. pts.push_back(Point(16036397, 6453203 )); pts.push_back(Point(16059993, 6510169 )); pts.push_back(Point(16059993, 6571830 )); pts.push_back(Point(16036397, 6628796 )); pts.push_back(Point(15992796, 6672397 )); pts.push_back(Point(15935830, 6695993 )); pts.push_back(Point(15874169, 6695993 ));
  2050. pts.push_back(Point(15817203, 6672397 )); pts.push_back(Point(15773602, 6628796 )); pts.push_back(Point(15750006, 6571830 )); pts.push_back(Point(15747030, 6545200 )); pts.push_back(Point(15746900, 6540620 )); pts.push_back(Point(15597380, 6391090 )); pts.push_back(Point(14858060, 6391090 ));
  2051. pts.push_back(Point(14858060, 6473860 )); pts.push_back(Point(14869993, 6510179 )); pts.push_back(Point(14869993, 6571840 )); pts.push_back(Point(14846397, 6628806 )); pts.push_back(Point(14802796, 6672407 )); pts.push_back(Point(14745830, 6696003 )); pts.push_back(Point(14684169, 6696003 ));
  2052. pts.push_back(Point(14627203, 6672407 )); pts.push_back(Point(14583602, 6628806 )); pts.push_back(Point(14560006, 6571840 )); pts.push_back(Point(14557030, 6545200 )); pts.push_back(Point(14556900, 6540620 )); pts.push_back(Point(14479020, 6462730 ));
  2053. pts.push_back(Point(13702990, 6462730 )); pts.push_back(Point(13702990, 6537170 )); pts.push_back(Point(13700003, 6571840 )); pts.push_back(Point(13676407, 6628806 )); pts.push_back(Point(13632806, 6672407 )); pts.push_back(Point(13575840, 6696003 ));
  2054. pts.push_back(Point(13514179, 6696003 )); pts.push_back(Point(13457213, 6672407 )); pts.push_back(Point(13413612, 6628806 )); pts.push_back(Point(13390016, 6571840 )); pts.push_back(Point(13387040, 6545550 )); pts.push_back(Point(13386710, 6534380 ));
  2055. pts.push_back(Point(12533290, 6534380 )); pts.push_back(Point(12532960, 6545550 )); pts.push_back(Point(12529983, 6571828 )); pts.push_back(Point(12506388, 6628791 )); pts.push_back(Point(12462791, 6672388 )); pts.push_back(Point(12405828, 6695983 ));
  2056. pts.push_back(Point(12344171, 6695983 )); pts.push_back(Point(12287208, 6672388 )); pts.push_back(Point(12266270, 6655670 ));
  2057. poly.set(pts.begin(), pts.end());
  2058. si.insert(poly, 444);
  2059. result.clear();
  2060. si.merge(result);
  2061. si.verify1();
  2062. print(stdcout, si.pmd) << "\n";
  2063. if(!result.empty()) {
  2064. psd = (*(result.begin())).second;
  2065. stdcout << psd << "\n";
  2066. std::vector<Point> outpts;
  2067. for(typename polygon_set_data<Unit>::iterator_type itr = psd.begin();
  2068. itr != psd.end(); ++itr) {
  2069. outpts.push_back((*itr).first.first);
  2070. outpts.push_back((*itr).first.second);
  2071. }
  2072. polygon_sort(outpts.begin(), outpts.end());
  2073. for(std::size_t i = 0; i < outpts.size(); i+=2) {
  2074. if(outpts[i] != outpts[i+1]) {
  2075. stdcout << "Polygon set not a closed figure\n";
  2076. stdcout << i << "\n";
  2077. stdcout << outpts[i] << " " << outpts[i+1] << "\n";
  2078. return 0;
  2079. }
  2080. }
  2081. polys.clear();
  2082. psd.get(polys);
  2083. if(polys.size() == 0) {
  2084. stdcout << "fail merge 10\n";
  2085. return false;
  2086. }
  2087. stdcout << (polys[0]) << "\n";
  2088. }
  2089. for(unsigned int i = 0; i < 10; ++i) {
  2090. stdcout << "random case # " << i << "\n";
  2091. si.clear();
  2092. pts.clear();
  2093. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2094. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2095. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2096. polygon_data<Unit> poly1;
  2097. poly1.set(pts.begin(), pts.end());
  2098. stdcout << poly1 << "\n";
  2099. si.insert(poly1, 444);
  2100. pts.clear();
  2101. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2102. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2103. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2104. polygon_data<Unit> poly2;
  2105. poly2.set(pts.begin(), pts.end());
  2106. stdcout << poly2 << "\n";
  2107. si.insert(poly2, 444);
  2108. result.clear();
  2109. si.merge(result);
  2110. print(stdcout, si.pmd) << "\n";
  2111. if(!result.empty()) {
  2112. psd = (*(result.begin())).second;
  2113. stdcout << psd << "\n";
  2114. polys.clear();
  2115. psd.get(polys);
  2116. if(polys.size() == 0) {
  2117. si.clear();
  2118. si.insert(poly1, 333);
  2119. result.clear();
  2120. si.merge(result);
  2121. psd = (*(result.begin())).second;
  2122. std::vector<polygon_data<Unit> > polys1;
  2123. psd.get(polys1);
  2124. si.clear();
  2125. si.insert(poly2, 333);
  2126. result.clear();
  2127. si.merge(result);
  2128. psd = (*(result.begin())).second;
  2129. std::vector<polygon_data<Unit> > polys2;
  2130. psd.get(polys2);
  2131. if(!polys1.empty() || !polys2.empty()) {
  2132. stdcout << "fail random merge " << i << "\n";
  2133. return false;
  2134. }
  2135. }
  2136. }
  2137. if(!polys.empty())
  2138. stdcout << polys.size() << ": " << (polys[0]) << "\n";
  2139. }
  2140. return true;
  2141. }
  2142. template <typename stream_type>
  2143. static inline bool check_rectangle_trio(rectangle_data<Unit> rect1, rectangle_data<Unit> rect2, rectangle_data<Unit> rect3, stream_type& stdcout) {
  2144. property_merge si;
  2145. std::map<std::set<property_type>, polygon_set_data<Unit> > result;
  2146. std::vector<polygon_data<Unit> > polys;
  2147. property_merge_90<property_type, Unit> si90;
  2148. std::map<std::set<property_type>, polygon_90_set_data<Unit> > result90;
  2149. std::vector<polygon_data<Unit> > polys90;
  2150. si.insert(rect1, 111);
  2151. si90.insert(rect1, 111);
  2152. stdcout << rect1 << "\n";
  2153. si.insert(rect2, 222);
  2154. si90.insert(rect2, 222);
  2155. stdcout << rect2 << "\n";
  2156. si.insert(rect3, 333);
  2157. si90.insert(rect3, 333);
  2158. stdcout << rect3 << "\n";
  2159. si.merge(result);
  2160. si90.merge(result90);
  2161. if(result.size() != result90.size()) {
  2162. stdcout << "merge failed with size mismatch\n";
  2163. return 0;
  2164. }
  2165. typename std::map<std::set<property_type>, polygon_90_set_data<Unit> >::iterator itr90 = result90.begin();
  2166. for(typename std::map<std::set<property_type>, polygon_set_data<Unit> >::iterator itr = result.begin();
  2167. itr != result.end(); ++itr) {
  2168. for(typename std::set<property_type>::const_iterator set_itr = (*itr).first.begin();
  2169. set_itr != (*itr).first.end(); ++set_itr) {
  2170. stdcout << (*set_itr) << " ";
  2171. } stdcout << ") \n";
  2172. polygon_set_data<Unit> psd = (*itr).second;
  2173. polygon_90_set_data<Unit> psd90 = (*itr90).second;
  2174. polys.clear();
  2175. polys90.clear();
  2176. psd.get(polys);
  2177. psd90.get(polys90);
  2178. if(polys.size() != polys90.size()) {
  2179. stdcout << "merge failed with polygon count mismatch\n";
  2180. stdcout << psd << "\n";
  2181. for(std::size_t j = 0; j < polys.size(); ++j) {
  2182. stdcout << polys[j] << "\n";
  2183. }
  2184. stdcout << "reference\n";
  2185. for(std::size_t j = 0; j < polys90.size(); ++j) {
  2186. stdcout << polys90[j] << "\n";
  2187. }
  2188. return 0;
  2189. }
  2190. bool failed = false;
  2191. for(std::size_t j = 0; j < polys.size(); ++j) {
  2192. stdcout << polys[j] << "\n";
  2193. stdcout << polys90[j] << "\n";
  2194. #ifdef BOOST_POLYGON_ICC
  2195. #pragma warning (push)
  2196. #pragma warning (disable:1572)
  2197. #endif
  2198. if(area(polys[j]) != area(polys90[j])) {
  2199. #ifdef BOOST_POLYGON_ICC
  2200. #pragma warning (pop)
  2201. #endif
  2202. stdcout << "merge failed with area mismatch\n";
  2203. failed = true;
  2204. }
  2205. }
  2206. if(failed) return 0;
  2207. ++itr90;
  2208. }
  2209. return true;
  2210. }
  2211. template <typename stream_type>
  2212. static inline bool test_manhattan_intersection(stream_type& stdcout) {
  2213. rectangle_data<Unit> rect1, rect2, rect3;
  2214. set_points(rect1, (Point(-1, 2)), (Point(1, 4)));
  2215. set_points(rect2, (Point(-1, 2)), (Point(2, 3)));
  2216. set_points(rect3, (Point(-3, 0)), (Point(4, 2)));
  2217. if(!check_rectangle_trio(rect1, rect2, rect3, stdcout)) {
  2218. return false;
  2219. }
  2220. for(unsigned int i = 0; i < 100; ++i) {
  2221. property_merge si;
  2222. std::map<std::set<property_type>, polygon_set_data<Unit> > result;
  2223. std::vector<polygon_data<Unit> > polys;
  2224. property_merge_90<property_type, Unit> si90;
  2225. std::map<std::set<property_type>, polygon_90_set_data<Unit> > result90;
  2226. std::vector<polygon_data<Unit> > polys90;
  2227. stdcout << "random case # " << i << "\n";
  2228. set_points(rect1, (Point(rand()%9-4, rand()%9-4)), (Point(rand()%9-4, rand()%9-4)));
  2229. set_points(rect2, (Point(rand()%9-4, rand()%9-4)), (Point(rand()%9-4, rand()%9-4)));
  2230. set_points(rect3, (Point(rand()%9-4, rand()%9-4)), (Point(rand()%9-4, rand()%9-4)));
  2231. if(!check_rectangle_trio(rect1, rect2, rect3, stdcout)) {
  2232. return false;
  2233. }
  2234. }
  2235. return true;
  2236. }
  2237. template <typename stream_type>
  2238. static inline bool test_intersection(stream_type& stdcout) {
  2239. property_merge si;
  2240. rectangle_data<Unit> rect;
  2241. xl(rect, 0);
  2242. yl(rect, 10);
  2243. xh(rect, 30);
  2244. yh(rect, 20);
  2245. si.insert(rect, 333);
  2246. xl(rect, 10);
  2247. yl(rect, 0);
  2248. xh(rect, 20);
  2249. yh(rect, 30);
  2250. si.insert(rect, 444);
  2251. xl(rect, 15);
  2252. yl(rect, 0);
  2253. xh(rect, 25);
  2254. yh(rect, 30);
  2255. si.insert(rect, 555);
  2256. std::map<std::set<property_type>, polygon_set_data<Unit> > result;
  2257. si.merge(result);
  2258. print(stdcout, si.pmd) << "\n";
  2259. for(typename std::map<std::set<property_type>, polygon_set_data<Unit> >::iterator itr = result.begin();
  2260. itr != result.end(); ++itr) {
  2261. stdcout << "( ";
  2262. for(typename std::set<property_type>::const_iterator set_itr = (*itr).first.begin();
  2263. set_itr != (*itr).first.end(); ++set_itr) {
  2264. stdcout << (*set_itr) << " ";
  2265. } stdcout << ") \n";
  2266. polygon_set_data<Unit> psd = (*itr).second;
  2267. stdcout << psd << "\n";
  2268. std::vector<polygon_data<Unit> > polys;
  2269. psd.get(polys);
  2270. for(std::size_t i = 0; i < polys.size(); ++i) {
  2271. stdcout << polys[i] << "\n";
  2272. }
  2273. }
  2274. std::vector<Point> pts;
  2275. std::vector<polygon_data<Unit> > polys;
  2276. for(unsigned int i = 0; i < 10; ++i) {
  2277. property_merge si2;
  2278. stdcout << "random case # " << i << "\n";
  2279. si.clear();
  2280. pts.clear();
  2281. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2282. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2283. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2284. polygon_data<Unit> poly1;
  2285. poly1.set(pts.begin(), pts.end());
  2286. stdcout << poly1 << "\n";
  2287. si.insert(poly1, 444);
  2288. si2.insert(poly1, 333);
  2289. pts.clear();
  2290. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2291. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2292. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2293. polygon_data<Unit> poly2;
  2294. poly2.set(pts.begin(), pts.end());
  2295. stdcout << poly2 << "\n";
  2296. si.insert(poly2, 444);
  2297. si2.insert(poly2, 444);
  2298. pts.clear();
  2299. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2300. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2301. pts.push_back(Point(rand()%9-4, rand()%9-4));
  2302. polygon_data<Unit> poly3;
  2303. poly3.set(pts.begin(), pts.end());
  2304. stdcout << poly3 << "\n";
  2305. si.insert(poly3, 444);
  2306. si2.insert(poly3, 555);
  2307. result.clear();
  2308. std::map<std::set<property_type>, polygon_set_data<Unit> > result2;
  2309. si.merge(result);
  2310. si2.merge(result2);
  2311. stdcout << "merged result\n";
  2312. for(typename std::map<std::set<property_type>, polygon_set_data<Unit> >::iterator itr = result.begin();
  2313. itr != result.end(); ++itr) {
  2314. stdcout << "( ";
  2315. for(typename std::set<property_type>::const_iterator set_itr = (*itr).first.begin();
  2316. set_itr != (*itr).first.end(); ++set_itr) {
  2317. stdcout << (*set_itr) << " ";
  2318. } stdcout << ") \n";
  2319. polygon_set_data<Unit> psd = (*itr).second;
  2320. stdcout << psd << "\n";
  2321. std::vector<polygon_data<Unit> > polys2;
  2322. psd.get(polys2);
  2323. for(std::size_t ii = 0; ii < polys2.size(); ++ii) {
  2324. stdcout << polys2[ii] << "\n";
  2325. }
  2326. }
  2327. stdcout << "intersected pmd\n";
  2328. print(stdcout, si2.pmd) << "\n";
  2329. stdcout << "intersected result\n";
  2330. for(typename std::map<std::set<property_type>, polygon_set_data<Unit> >::iterator itr = result2.begin();
  2331. itr != result2.end(); ++itr) {
  2332. stdcout << "( ";
  2333. for(typename std::set<property_type>::const_iterator set_itr = (*itr).first.begin();
  2334. set_itr != (*itr).first.end(); ++set_itr) {
  2335. stdcout << (*set_itr) << " ";
  2336. } stdcout << ") \n";
  2337. polygon_set_data<Unit> psd = (*itr).second;
  2338. stdcout << psd << "\n";
  2339. std::vector<polygon_data<Unit> > polys2;
  2340. psd.get(polys2);
  2341. for(std::size_t ii = 0; ii < polys2.size(); ++ii) {
  2342. stdcout << polys2[ii] << "\n";
  2343. }
  2344. }
  2345. si.clear();
  2346. for(typename std::map<std::set<property_type>, polygon_set_data<Unit> >::iterator itr = result2.begin();
  2347. itr != result2.end(); ++itr) {
  2348. polys.clear();
  2349. (*itr).second.get(polys);
  2350. for(std::size_t j = 0; j < polys.size(); ++j) {
  2351. si.insert(polys[j], 444);
  2352. }
  2353. }
  2354. result2.clear();
  2355. si.merge(result2);
  2356. stdcout << "remerged result\n";
  2357. for(typename std::map<std::set<property_type>, polygon_set_data<Unit> >::iterator itr = result2.begin();
  2358. itr != result2.end(); ++itr) {
  2359. stdcout << "( ";
  2360. for(typename std::set<property_type>::const_iterator set_itr = (*itr).first.begin();
  2361. set_itr != (*itr).first.end(); ++set_itr) {
  2362. stdcout << (*set_itr) << " ";
  2363. } stdcout << ") \n";
  2364. polygon_set_data<Unit> psd = (*itr).second;
  2365. stdcout << psd << "\n";
  2366. std::vector<polygon_data<Unit> > polys2;
  2367. psd.get(polys2);
  2368. for(std::size_t ii = 0; ii < polys2.size(); ++ii) {
  2369. stdcout << polys2[ii] << "\n";
  2370. }
  2371. }
  2372. std::vector<polygon_data<Unit> > polys2;
  2373. polys.clear();
  2374. (*(result.begin())).second.get(polys);
  2375. (*(result2.begin())).second.get(polys2);
  2376. if(!(polys == polys2)) {
  2377. stdcout << "failed intersection check # " << i << "\n";
  2378. return false;
  2379. }
  2380. }
  2381. return true;
  2382. }
  2383. };
  2384. template <typename Unit>
  2385. class arbitrary_boolean_op : public scanline_base<Unit> {
  2386. private:
  2387. typedef int property_type;
  2388. typedef typename scanline_base<Unit>::Point Point;
  2389. //the first point is the vertex and and second point establishes the slope of an edge eminating from the vertex
  2390. //typedef std::pair<Point, Point> half_edge;
  2391. typedef typename scanline_base<Unit>::half_edge half_edge;
  2392. //scanline comparator functor
  2393. typedef typename scanline_base<Unit>::less_half_edge less_half_edge;
  2394. typedef typename scanline_base<Unit>::less_point less_point;
  2395. //this data structure assocates a property and count to a half edge
  2396. typedef std::pair<half_edge, std::pair<property_type, int> > vertex_property;
  2397. //this data type stores the combination of many half edges
  2398. typedef std::vector<vertex_property> property_merge_data;
  2399. //this is the data type used internally to store the combination of property counts at a given location
  2400. typedef std::vector<std::pair<property_type, int> > property_map;
  2401. //this data type is used internally to store the combined property data for a given half edge
  2402. typedef std::pair<half_edge, property_map> vertex_data;
  2403. property_merge_data pmd;
  2404. typename scanline_base<Unit>::evalAtXforYPack evalAtXforYPack_;
  2405. template<typename vertex_data_type>
  2406. class less_vertex_data {
  2407. typename scanline_base<Unit>::evalAtXforYPack* pack_;
  2408. public:
  2409. less_vertex_data() : pack_() {}
  2410. less_vertex_data(typename scanline_base<Unit>::evalAtXforYPack* pack) : pack_(pack) {}
  2411. bool operator()(const vertex_data_type& lvalue, const vertex_data_type& rvalue) const {
  2412. less_point lp;
  2413. if(lp(lvalue.first.first, rvalue.first.first)) return true;
  2414. if(lp(rvalue.first.first, lvalue.first.first)) return false;
  2415. Unit x = lvalue.first.first.get(HORIZONTAL);
  2416. int just_before_ = 0;
  2417. less_half_edge lhe(&x, &just_before_, pack_);
  2418. return lhe(lvalue.first, rvalue.first);
  2419. }
  2420. };
  2421. template <typename result_type, typename key_type, int op_type>
  2422. class boolean_output_functor {
  2423. public:
  2424. boolean_output_functor() {}
  2425. void operator()(result_type& result, const half_edge& edge, const key_type& left, const key_type& right) {
  2426. typename std::pair<half_edge, int> elem;
  2427. elem.first = edge;
  2428. elem.second = 1;
  2429. if(edge.second < edge.first) elem.second *= -1;
  2430. if(scanline_base<Unit>::is_vertical(edge)) elem.second *= -1;
  2431. #ifdef BOOST_POLYGON_MSVC
  2432. #pragma warning (push)
  2433. #pragma warning (disable: 4127)
  2434. #endif
  2435. if(op_type == 0) { //OR
  2436. if(!left.empty() && right.empty()) {
  2437. result.insert_clean(elem);
  2438. } else if(!right.empty() && left.empty()) {
  2439. elem.second *= -1;
  2440. result.insert_clean(elem);
  2441. }
  2442. } else if(op_type == 1) { //AND
  2443. if(left.size() == 2 && right.size() != 2) {
  2444. result.insert_clean(elem);
  2445. } else if(right.size() == 2 && left.size() != 2) {
  2446. elem.second *= -1;
  2447. result.insert_clean(elem);
  2448. }
  2449. } else if(op_type == 2) { //XOR
  2450. if(left.size() == 1 && right.size() != 1) {
  2451. result.insert_clean(elem);
  2452. } else if(right.size() == 1 && left.size() != 1) {
  2453. elem.second *= -1;
  2454. result.insert_clean(elem);
  2455. }
  2456. } else { //SUBTRACT
  2457. if(left.size() == 1) {
  2458. if((*(left.begin())) == 0) {
  2459. result.insert_clean(elem);
  2460. }
  2461. }
  2462. #ifdef BOOST_POLYGON_MSVC
  2463. #pragma warning (pop)
  2464. #endif
  2465. if(right.size() == 1) {
  2466. if((*(right.begin())) == 0) {
  2467. elem.second *= -1;
  2468. result.insert_clean(elem);
  2469. }
  2470. }
  2471. }
  2472. }
  2473. };
  2474. inline void sort_property_merge_data() {
  2475. less_vertex_data<vertex_property> lvd(&evalAtXforYPack_);
  2476. polygon_sort(pmd.begin(), pmd.end(), lvd);
  2477. }
  2478. public:
  2479. inline arbitrary_boolean_op() : pmd(), evalAtXforYPack_() {}
  2480. inline arbitrary_boolean_op(const arbitrary_boolean_op& pm) : pmd(pm.pmd), evalAtXforYPack_(pm.evalAtXforYPack_) {}
  2481. inline arbitrary_boolean_op& operator=(const arbitrary_boolean_op& pm) { pmd = pm.pmd; return *this; }
  2482. enum BOOLEAN_OP_TYPE {
  2483. BOOLEAN_OR = 0,
  2484. BOOLEAN_AND = 1,
  2485. BOOLEAN_XOR = 2,
  2486. BOOLEAN_NOT = 3
  2487. };
  2488. template <typename result_type, typename iT1, typename iT2>
  2489. inline void execute(result_type& result, iT1 b1, iT1 e1, iT2 b2, iT2 e2, int op) {
  2490. //intersect data
  2491. insert(b1, e1, 0);
  2492. insert(b2, e2, 1);
  2493. property_merge_data tmp_pmd;
  2494. //#define BOOST_POLYGON_DEBUG_FILE
  2495. #ifdef BOOST_POLYGON_DEBUG_FILE
  2496. std::fstream debug_file;
  2497. debug_file.open("gtl_debug.txt", std::ios::out);
  2498. property_merge<Unit, property_type, std::vector<property_type> >::print(debug_file, pmd);
  2499. debug_file.close();
  2500. #endif
  2501. if(pmd.empty())
  2502. return;
  2503. line_intersection<Unit>::validate_scan(tmp_pmd, pmd.begin(), pmd.end());
  2504. pmd.swap(tmp_pmd);
  2505. sort_property_merge_data();
  2506. scanline<Unit, property_type, std::vector<property_type> > sl;
  2507. if(op == BOOLEAN_OR) {
  2508. boolean_output_functor<result_type, std::vector<property_type>, 0> bof;
  2509. sl.scan(result, bof, pmd.begin(), pmd.end());
  2510. } else if(op == BOOLEAN_AND) {
  2511. boolean_output_functor<result_type, std::vector<property_type>, 1> bof;
  2512. sl.scan(result, bof, pmd.begin(), pmd.end());
  2513. } else if(op == BOOLEAN_XOR) {
  2514. boolean_output_functor<result_type, std::vector<property_type>, 2> bof;
  2515. sl.scan(result, bof, pmd.begin(), pmd.end());
  2516. } else if(op == BOOLEAN_NOT) {
  2517. boolean_output_functor<result_type, std::vector<property_type>, 3> bof;
  2518. sl.scan(result, bof, pmd.begin(), pmd.end());
  2519. }
  2520. }
  2521. inline void clear() {*this = arbitrary_boolean_op();}
  2522. private:
  2523. template <typename iT>
  2524. void insert(iT b, iT e, int id) {
  2525. for(;
  2526. b != e; ++b) {
  2527. pmd.push_back(vertex_property(half_edge((*b).first.first, (*b).first.second),
  2528. std::pair<property_type, int>(id, (*b).second)));
  2529. }
  2530. }
  2531. };
  2532. template <typename Unit, typename stream_type>
  2533. bool test_arbitrary_boolean_op(stream_type& stdcout) {
  2534. polygon_set_data<Unit> psd;
  2535. rectangle_data<Unit> rect;
  2536. set_points(rect, point_data<Unit>(0, 0), point_data<Unit>(10, 10));
  2537. psd.insert(rect);
  2538. polygon_set_data<Unit> psd2;
  2539. set_points(rect, point_data<Unit>(5, 5), point_data<Unit>(15, 15));
  2540. psd2.insert(rect);
  2541. std::vector<polygon_data<Unit> > pv;
  2542. pv.clear();
  2543. arbitrary_boolean_op<Unit> abo;
  2544. polygon_set_data<Unit> psd3;
  2545. abo.execute(psd3, psd.begin(), psd.end(), psd2.begin(), psd2.end(), arbitrary_boolean_op<Unit>::BOOLEAN_OR);
  2546. psd3.get(pv);
  2547. for(std::size_t i = 0; i < pv.size(); ++i) {
  2548. stdcout << pv[i] << "\n";
  2549. }
  2550. pv.clear();
  2551. abo.clear();
  2552. psd3.clear();
  2553. abo.execute(psd3, psd.begin(), psd.end(), psd2.begin(), psd2.end(), arbitrary_boolean_op<Unit>::BOOLEAN_AND);
  2554. psd3.get(pv);
  2555. for(std::size_t i = 0; i < pv.size(); ++i) {
  2556. stdcout << pv[i] << "\n";
  2557. }
  2558. pv.clear();
  2559. abo.clear();
  2560. psd3.clear();
  2561. abo.execute(psd3, psd.begin(), psd.end(), psd2.begin(), psd2.end(), arbitrary_boolean_op<Unit>::BOOLEAN_XOR);
  2562. psd3.get(pv);
  2563. for(std::size_t i = 0; i < pv.size(); ++i) {
  2564. stdcout << pv[i] << "\n";
  2565. }
  2566. pv.clear();
  2567. abo.clear();
  2568. psd3.clear();
  2569. abo.execute(psd3, psd.begin(), psd.end(), psd2.begin(), psd2.end(), arbitrary_boolean_op<Unit>::BOOLEAN_NOT);
  2570. psd3.get(pv);
  2571. for(std::size_t i = 0; i < pv.size(); ++i) {
  2572. stdcout << pv[i] << "\n";
  2573. }
  2574. return true;
  2575. }
  2576. template <typename Unit, typename property_type>
  2577. class arbitrary_connectivity_extraction : public scanline_base<Unit> {
  2578. private:
  2579. typedef typename scanline_base<Unit>::Point Point;
  2580. //the first point is the vertex and and second point establishes the slope of an edge eminating from the vertex
  2581. //typedef std::pair<Point, Point> half_edge;
  2582. typedef typename scanline_base<Unit>::half_edge half_edge;
  2583. //scanline comparator functor
  2584. typedef typename scanline_base<Unit>::less_half_edge less_half_edge;
  2585. typedef typename scanline_base<Unit>::less_point less_point;
  2586. //this data structure assocates a property and count to a half edge
  2587. typedef std::pair<half_edge, std::pair<property_type, int> > vertex_property;
  2588. //this data type stores the combination of many half edges
  2589. typedef std::vector<vertex_property> property_merge_data;
  2590. //this is the data type used internally to store the combination of property counts at a given location
  2591. typedef std::vector<std::pair<property_type, int> > property_map;
  2592. //this data type is used internally to store the combined property data for a given half edge
  2593. typedef std::pair<half_edge, property_map> vertex_data;
  2594. property_merge_data pmd;
  2595. typename scanline_base<Unit>::evalAtXforYPack evalAtXforYPack_;
  2596. template<typename vertex_data_type>
  2597. class less_vertex_data {
  2598. typename scanline_base<Unit>::evalAtXforYPack* pack_;
  2599. public:
  2600. less_vertex_data() : pack_() {}
  2601. less_vertex_data(typename scanline_base<Unit>::evalAtXforYPack* pack) : pack_(pack) {}
  2602. bool operator()(const vertex_data_type& lvalue, const vertex_data_type& rvalue) const {
  2603. less_point lp;
  2604. if(lp(lvalue.first.first, rvalue.first.first)) return true;
  2605. if(lp(rvalue.first.first, lvalue.first.first)) return false;
  2606. Unit x = lvalue.first.first.get(HORIZONTAL);
  2607. int just_before_ = 0;
  2608. less_half_edge lhe(&x, &just_before_, pack_);
  2609. return lhe(lvalue.first, rvalue.first);
  2610. }
  2611. };
  2612. template <typename cT>
  2613. static void process_previous_x(cT& output) {
  2614. std::map<point_data<Unit>, std::set<property_type> >& y_prop_map = output.first.second;
  2615. if(y_prop_map.empty()) return;
  2616. Unit x = output.first.first;
  2617. for(typename std::map<point_data<Unit>, std::set<property_type> >::iterator itr =
  2618. y_prop_map.begin(); itr != y_prop_map.end(); ++itr) {
  2619. if((*itr).first.x() < x) {
  2620. y_prop_map.erase(y_prop_map.begin(), itr);
  2621. continue;
  2622. }
  2623. for(typename std::set<property_type>::iterator inner_itr = itr->second.begin();
  2624. inner_itr != itr->second.end(); ++inner_itr) {
  2625. std::set<property_type>& output_edges = (*(output.second))[*inner_itr];
  2626. typename std::set<property_type>::iterator inner_inner_itr = inner_itr;
  2627. ++inner_inner_itr;
  2628. for( ; inner_inner_itr != itr->second.end(); ++inner_inner_itr) {
  2629. output_edges.insert(output_edges.end(), *inner_inner_itr);
  2630. std::set<property_type>& output_edges_2 = (*(output.second))[*inner_inner_itr];
  2631. output_edges_2.insert(output_edges_2.end(), *inner_itr);
  2632. }
  2633. }
  2634. }
  2635. }
  2636. template <typename result_type, typename key_type>
  2637. class connectivity_extraction_output_functor {
  2638. public:
  2639. connectivity_extraction_output_functor() {}
  2640. void operator()(result_type& result, const half_edge& edge, const key_type& left, const key_type& right) {
  2641. Unit& x = result.first.first;
  2642. std::map<point_data<Unit>, std::set<property_type> >& y_prop_map = result.first.second;
  2643. point_data<Unit> pt = edge.first;
  2644. if(pt.x() != x) process_previous_x(result);
  2645. x = pt.x();
  2646. std::set<property_type>& output_set = y_prop_map[pt];
  2647. {
  2648. for(typename key_type::const_iterator itr1 =
  2649. left.begin(); itr1 != left.end(); ++itr1) {
  2650. output_set.insert(output_set.end(), *itr1);
  2651. }
  2652. for(typename key_type::const_iterator itr2 =
  2653. right.begin(); itr2 != right.end(); ++itr2) {
  2654. output_set.insert(output_set.end(), *itr2);
  2655. }
  2656. }
  2657. std::set<property_type>& output_set2 = y_prop_map[edge.second];
  2658. for(typename key_type::const_iterator itr1 =
  2659. left.begin(); itr1 != left.end(); ++itr1) {
  2660. output_set2.insert(output_set2.end(), *itr1);
  2661. }
  2662. for(typename key_type::const_iterator itr2 =
  2663. right.begin(); itr2 != right.end(); ++itr2) {
  2664. output_set2.insert(output_set2.end(), *itr2);
  2665. }
  2666. }
  2667. };
  2668. inline void sort_property_merge_data() {
  2669. less_vertex_data<vertex_property> lvd(&evalAtXforYPack_);
  2670. polygon_sort(pmd.begin(), pmd.end(), lvd);
  2671. }
  2672. public:
  2673. inline arbitrary_connectivity_extraction() : pmd(), evalAtXforYPack_() {}
  2674. inline arbitrary_connectivity_extraction
  2675. (const arbitrary_connectivity_extraction& pm) : pmd(pm.pmd), evalAtXforYPack_(pm.evalAtXforYPack_) {}
  2676. inline arbitrary_connectivity_extraction& operator=
  2677. (const arbitrary_connectivity_extraction& pm) { pmd = pm.pmd; return *this; }
  2678. template <typename result_type>
  2679. inline void execute(result_type& result) {
  2680. //intersect data
  2681. property_merge_data tmp_pmd;
  2682. line_intersection<Unit>::validate_scan(tmp_pmd, pmd.begin(), pmd.end());
  2683. pmd.swap(tmp_pmd);
  2684. sort_property_merge_data();
  2685. scanline<Unit, property_type, std::vector<property_type> > sl;
  2686. std::pair<std::pair<Unit, std::map<point_data<Unit>, std::set<property_type> > >,
  2687. result_type*> output
  2688. (std::make_pair(std::make_pair((std::numeric_limits<Unit>::max)(),
  2689. std::map<point_data<Unit>,
  2690. std::set<property_type> >()), &result));
  2691. connectivity_extraction_output_functor<std::pair<std::pair<Unit,
  2692. std::map<point_data<Unit>, std::set<property_type> > >, result_type*>,
  2693. std::vector<property_type> > ceof;
  2694. sl.scan(output, ceof, pmd.begin(), pmd.end());
  2695. process_previous_x(output);
  2696. }
  2697. inline void clear() {*this = arbitrary_connectivity_extraction();}
  2698. template <typename iT>
  2699. void populateTouchSetData(iT begin, iT end,
  2700. property_type property) {
  2701. for( ; begin != end; ++begin) {
  2702. pmd.push_back(vertex_property(half_edge((*begin).first.first, (*begin).first.second),
  2703. std::pair<property_type, int>(property, (*begin).second)));
  2704. }
  2705. }
  2706. };
  2707. }
  2708. }
  2709. #endif