summaryrefslogtreecommitdiffstats
path: root/src/line-snapper.h
blob: ea98124c954f3af3915158ab0513bc89d90f962b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_LINE_SNAPPER_H
#define SEEN_LINE_SNAPPER_H
/*
 *    Authors:
 *      Carl Hetherington <inkscape@carlh.net>
 *      Diederik van Lierop <mail@diedenrezi.nl>
 *
 * 	  Copyright (C) 1999-2008 Authors
 *
 *    Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "snapper.h"

namespace Inkscape {

class SnapCandidatePoint;

/**
 * Superclass for snappers to horizontal and vertical lines.
 */
class LineSnapper : public Snapper
{
public:
  LineSnapper(SnapManager *sm, Geom::Coord const d);

  void freeSnap(IntermSnapResults &isr,
                   Inkscape::SnapCandidatePoint const &p,
                   Geom::OptRect const &bbox_to_snap,
                   std::vector<SPItem const *> const *it,
                   std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes) const override;

  void constrainedSnap(IntermSnapResults &isr,
                          Inkscape::SnapCandidatePoint const &p,
                          Geom::OptRect const &bbox_to_snap,
                          SnapConstraint const &c,
                          std::vector<SPItem const *> const *it,
                          std::vector<SnapCandidatePoint> *unselected_nodes) const override;

protected:
  typedef std::list<std::pair<Geom::Point, Geom::Point> > LineList;
  //first point is a vector normal to the line
  //second point is a point on the line

private:
  /**
   *  \param p Point that we are trying to snap.
   *  \return List of lines that we should try snapping to.
   */
  virtual LineList _getSnapLines(Geom::Point const &p) const = 0;

  virtual void _addSnappedLine(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const &normal_to_line, Geom::Point const &point_on_line) const = 0;

  // Will only be implemented for guide lines, because grid lines don't have an origin
  virtual void _addSnappedLinesOrigin(IntermSnapResults &isr, Geom::Point const &origin, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const;

  virtual void _addSnappedLinePerpendicularly(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const = 0;
  virtual void _addSnappedPoint(IntermSnapResults &isr, Geom::Point const &snapped_point, Geom::Coord const &snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const = 0;
};

}

#endif /* !SEEN_LINE_SNAPPER_H */