LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::Snapable Class Referenceabstract

#include <snapable.h>

Inheritance diagram for lc::Snapable:

Public Member Functions

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, closest to coord and can return multiple snap points. More...
 
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 it can possibly take. More...
 

Static Public Member Functions

static void remove_ifDistanceGreaterThen (std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const double distance)
 
static void snapPointsCleanup (std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
 

Detailed Description

Any entity that we can snap against needs to implement the snapable interface

Definition at line 13 of file snapable.h.

Member Function Documentation

virtual geo::Coordinate lc::Snapable::nearestPointOnPath ( const geo::Coordinate coord) const
pure virtual

Find the nearest point on the path for this entity for the coordinate coord The path of a entity that it can possibly take.

For example for any Arc the path is the full circle if the start/stop angle is 0 to 2*pi

Parameters
coordCoordinate to lookup the nearest coordinate from
See also
lc::entity::CADEntity

Implemented in lc::entity::LWPolyline, lc::entity::Ellipse, lc::entity::Arc, lc::entity::Line, lc::entity::Spline, lc::entity::Image, lc::entity::Insert, lc::entity::Circle, and lc::entity::CustomEntity.

static void lc::Snapable::remove_ifDistanceGreaterThen ( std::vector< EntityCoordinate > &  points,
const geo::Coordinate reference,
const double  distance 
)
inlinestatic

Remove point's from vector if the distance to references is > distance

Definition at line 39 of file snapable.h.

39  {
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  }
virtual std::vector<lc::EntityCoordinate> lc::Snapable::snapPoints ( const geo::Coordinate coord,
const SimpleSnapConstrain simpleSnapConstrain,
double  minDistanceToSnap,
int  maxNumberOfSnapPoints 
) const
pure virtual

Find a number of snap points the line has available This function returns a ordered list, closest to coord and can return multiple snap points.

Parameters
coordCoordinate to lookup the nearest coordinate from
minDistanceToSnapMinimum distance to the path to snap into. THis is a hint parameter and we should follow this, but it will be later filtered again
maxNumberOfSnapPointsMaximum number of snappoints that have to be looked up
See also
lc::EntityCoordinate

Implemented in lc::entity::LWPolyline, lc::entity::Ellipse, lc::entity::Arc, lc::entity::Line, lc::entity::Spline, lc::entity::Image, lc::entity::Insert, lc::entity::Circle, and lc::entity::CustomEntity.

static void lc::Snapable::snapPointsCleanup ( std::vector< EntityCoordinate > &  points,
const geo::Coordinate reference,
const unsigned int  maxNumberOfSnapPoints,
const double  minDistanceToSnap 
)
inlinestatic

Use this function in your snapPoints function to cleanup any additional point's and confirm to the requirements of maxNumberOfSnapPoints and minDistanceToSnap

Definition at line 53 of file snapable.h.

53  {
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  }
static void remove_ifDistanceGreaterThen(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const double distance)
Definition: snapable.h:39

The documentation for this class was generated from the following file: