1 #pragma once
2 
3 #ifndef T_L2LAUTOCLOSER_H
4 #define T_L2LAUTOCLOSER_H
5 
6 #include <memory>
7 
8 #include "tgeometry.h"
9 
10 #undef DVAPI
11 #undef DVVAR
12 #ifdef TVECTORIMAGE_EXPORTS
13 #define DVAPI DV_EXPORT_API
14 #define DVVAR DV_EXPORT_VAR
15 #else
16 #define DVAPI DV_IMPORT_API
17 #define DVVAR DV_IMPORT_VAR
18 #endif
19 
20 #ifdef _MSC_VER
21 #pragma warning(disable : 4251)
22 #endif
23 
24 // forward declaration
25 class TStroke;
26 
27 //-----------------------------------------------------------------------------
28 
29 //! Line-to-line autocloser
30 class DVAPI TL2LAutocloser {
31   class Imp;
32   std::unique_ptr<Imp> m_imp;
33 
34 public:
35   TL2LAutocloser();
36   ~TL2LAutocloser();
37 
38   struct Segment {
39     //! the segments returned by the Line-to-line autocloser
40     TStroke *stroke0, *stroke1;  // the two involved strokes
41     double w0, w1;               // the w-parameters
42     TThickPoint p0, p1;          // the related points
43     double dist2;                // the (squared) points distance
44   };
45 
46   //! segments longer than sqrt(dist2) are not considered. the default is 50^2
47   void setMaxDistance2(double dist2);
48   double getMaxDistance2() const;
49 
50   //! search line-to-line autoclosing segments.
51   //! Note: it computes and caches some information about stroke0 and stroke1
52   //! you are not supposed to change strokes between two subsequent calls to
53   //! search()
54   void search(std::vector<Segment> &segments, TStroke *stroke0,
55               TStroke *stroke1);
56 
57   //! use this method if you have already computed the intersections
58   void search(std::vector<Segment> &segments, TStroke *stroke0,
59               TStroke *stroke1, const std::vector<DoublePair> &intersection);
60 
61   //! debug only. show the internal state related to the last performed search
62   void draw();
63 
64 private:
65   // not implemented
66   TL2LAutocloser(const TL2LAutocloser &);
67   const TL2LAutocloser &operator=(const TL2LAutocloser &);
68 };
69 
70 //---------------------------------------------------------------------------------------
71 
72 #endif  // T_L2LAUTOCLOSER_H
73