LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
snapable.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
6 #include "snapconstrain.h"
7 
8 namespace lc {
13  class Snapable {
14  public:
25  virtual std::vector<lc::EntityCoordinate> snapPoints(const geo::Coordinate& coord, const SimpleSnapConstrain &simpleSnapConstrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const = 0;
26 
33  virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate& coord) const = 0;
34 
35 
39  static void remove_ifDistanceGreaterThen(std::vector<EntityCoordinate> &points, const geo::Coordinate &reference, const double distance) {
40  points.erase(
41  std::remove_if(points.begin(), points.end(),
42  [reference, distance](const EntityCoordinate &entity) {
43  return entity.coordinate().distanceTo(reference) > distance;
44 
45  }),
46  points.end());
47  }
48 
53  static void snapPointsCleanup(std::vector<EntityCoordinate> &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap) {
54  // Remove point's further away then given by minDistanceToSnap
55  Snapable::remove_ifDistanceGreaterThen(points, reference, minDistanceToSnap);
56  // Sort in order of distance
57  std::sort(points.begin(), points.end(), EntityCoordinateSorter(reference));
58  // Only get maxNumberOfSnapPoints
59  if (points.size() > maxNumberOfSnapPoints) {
60  points.erase(points.begin() + maxNumberOfSnapPoints, points.end());
61  }
62  }
63  };
64 
65  DECLARE_SHORT_SHARED_PTR(Snapable)
66 }
67 
68 // SNAPABLE_H
69 
70 
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate &coord) const =0
Find the nearest point on the path for this entity for the coordinate coord The path of a entity that...
DECLARE_SHORT_SHARED_PTR(Document)
Definition: cadentity.h:12
static void snapPointsCleanup(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
Definition: snapable.h:53
Class that represents a Coordinate associated with a distance to a test point and a identifier for th...
static void remove_ifDistanceGreaterThen(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const double distance)
Definition: snapable.h:39
virtual std::vector< lc::EntityCoordinate > snapPoints(const geo::Coordinate &coord, const SimpleSnapConstrain &simpleSnapConstrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const =0
Find a number of snap points the line has available This function returns a ordered list...