LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lc::entity::Arc Class Reference

#include <arc.h>

Inheritance diagram for lc::entity::Arc:
Collaboration diagram for lc::entity::Arc:

Public Member Functions

 Arc (const geo::Coordinate &center, double radius, double startAngle, double endAngle, bool CCW, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
 Arc, Arc constructor. More...
 
 Arc (const geo::Arc &a, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, const Block_CSPtr block=nullptr)
 
 Arc (const Arc_CSPtr other, bool sameID=false)
 
virtual CADEntity_CSPtr move (const geo::Coordinate &offset) const override
 move, moves by an offset More...
 
virtual CADEntity_CSPtr copy (const geo::Coordinate &offset) const override
 copy, copies line by an offset More...
 
virtual CADEntity_CSPtr rotate (const geo::Coordinate &rotation_center, const double rotation_angle) const override
 rotate, rotate operation More...
 
virtual CADEntity_CSPtr scale (const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
 scale, scales the entity More...
 
virtual CADEntity_CSPtr mirror (const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
 
virtual const geo::Area boundingBox () const override
 boundingBox of the entity More...
 
virtual CADEntity_CSPtr modify (Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const override
 modify Return a new entity with the same ID bit with possible modified metainfo and/pr layer information #return new entity with same ID More...
 
virtual std::vector
< EntityCoordinate
snapPoints (const geo::Coordinate &coord, const SimpleSnapConstrain &constrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const override
 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 override
 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...
 
virtual void accept (GeoEntityVisitor &v) const override
 
virtual void dispatch (EntityDispatch &ed) const override
 
virtual std::map< unsigned int,
lc::geo::Coordinate
dragPoints () const override
 Get all points of the entity that can be dragged. More...
 
virtual CADEntity_CSPtr setDragPoints (std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
 Return modified entity. More...
 
- Public Member Functions inherited from lc::entity::CADEntity
 CADEntity ()
 
 CADEntity (Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
 CADEntity Constructor. More...
 
 CADEntity (CADEntity_CSPtr cadEntity, bool sameID)
 
 CADEntity (CADEntity_CSPtr cadEntity)
 
virtual ~CADEntity ()=default
 
Layer_CSPtr layer () const
 layer return the layer this entity is placed on More...
 
template<typename T >
const std::shared_ptr< const T > metaInfo (std::string metaName) const
 
MetaInfo_CSPtr metaInfo () const
 
Block_CSPtr block () const
 Return the current entity block. More...
 
- Public Member Functions inherited from lc::ID
 ID ()
 Default constructor, provides a new unique ID to each entity. More...
 
 ID (ID_DATATYPE)
 
virtual ~ID ()=default
 
ID_DATATYPE id () const
 returns the ID of the entity More...
 
bool operator== (const ID &id) const
 
void setID (ID_DATATYPE id)
 
- Public Member Functions inherited from lc::Visitable
virtual ~Visitable ()=default
 
- Public Member Functions inherited from lc::geo::Arc
 Arc (const Coordinate &center, double radius, double startAngle, double endAngle)
 
 Arc (const Coordinate &center, double radius, double startAngle, double endAngle, bool CCW)
 
 Arc (const Arc &c)
 
 Arc (Arc &&c) noexcept
 
Arcoperator= (Arc &&c) noexcept
 
const Coordinate center () const
 Returns center of Arc. More...
 
double radius () const
 Returns the radius of Arc. More...
 
double startAngle () const
 Returns the startAngle. More...
 
double endAngle () const
 Returns the EndAngle. More...
 
double length () const
 
Coordinate startP () const
 
Coordinate endP () const
 
Area boundingBox () const
 
bool CCW () const
 Returns of the arc is in reversed direction. More...
 
Coordinate nearestPointOnPath (const Coordinate &coord) const
 
Coordinate nearestPointOnEntity (const Coordinate &coord) const
 
const maths::Equation equation () const
 
bool isAngleBetween (double angle) const
 
double angle () const
 
double bulge () const
 
- Public Member Functions inherited from lc::geo::Base
virtual ~Base ()=default
 

Private Member Functions

 Arc (const builder::ArcBuilder &builder)
 

Friends

class builder::ArcBuilder
 

Additional Inherited Members

- Static Public Member Functions inherited from lc::geo::Arc
static Arc createArc3P (const Coordinate &p1, const Coordinate &p2, const Coordinate &p3)
 
static Arc createArcBulge (const Coordinate &p1, const Coordinate &p2, const double bulge)
 
- Static Public Member Functions inherited from lc::Snapable
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)
 
- Static Public Attributes inherited from lc::ID
static std::atomic< ID_DATATYPE__idCounter
 
- Protected Member Functions inherited from lc::entity::CADEntity
 CADEntity (const lc::builder::CADEntityBuilder &builder)
 

Detailed Description

Definition at line 19 of file arc.h.

Constructor & Destructor Documentation

Arc::Arc ( const geo::Coordinate center,
double  radius,
double  startAngle,
double  endAngle,
bool  CCW,
const Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo = nullptr,
const Block_CSPtr  block = nullptr 
)

Arc, Arc constructor.

Parameters
geo::Coordinatecenter, center of Arc
doubleradius, radius of Arc
doublestartAngle, starting angle of Arc
doubleendAngle, ending angle of Arc
Layer_CSPtrlayer, layer of entity
MetaTypesmetaTypes

Definition at line 6 of file arc.cpp.

7  :
9  geo::Arc(center, radius, startAngle, endAngle, isCCW) {
10 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
Arc::Arc ( const geo::Arc a,
const Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo,
const Block_CSPtr  block = nullptr 
)

Definition at line 12 of file arc.cpp.

12  :
14  geo::Arc(a) {
15 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
Arc::Arc ( const Arc_CSPtr  other,
bool  sameID = false 
)

Definition at line 17 of file arc.cpp.

17  : CADEntity(other, sameID),
18  geo::Arc(other->center(), other->radius(), other->startAngle(),
19  other->endAngle(), other->CCW()) {
20 }
Arc::Arc ( const builder::ArcBuilder builder)
private

Definition at line 22 of file arc.cpp.

22  :
23  CADEntity(builder),
24  geo::Arc(builder.center(), builder.radius(), builder.startAngle(), builder.endAngle(), builder.isCCW()) {
25 }
const geo::Coordinate & center() const
Definition: arc.cpp:14
double endAngle() const
Definition: arc.cpp:41
double startAngle() const
Definition: arc.cpp:32
bool isCCW() const
Definition: arc.cpp:50
double radius() const
Definition: arc.cpp:23

Member Function Documentation

virtual void lc::entity::Arc::accept ( GeoEntityVisitor v) const
inlineoverridevirtual

Reimplemented from lc::entity::CADEntity.

Definition at line 93 of file arc.h.

93 { v.visit(*this); }
const geo::Area Arc::boundingBox ( ) const
overridevirtual

boundingBox of the entity

Returns
geo::Area area

Implements lc::entity::CADEntity.

Definition at line 136 of file arc.cpp.

136  {
137  return geo::Arc::boundingBox();
138 }
Area boundingBox() const
Definition: geoarc.cpp:138
CADEntity_CSPtr Arc::copy ( const geo::Coordinate offset) const
overridevirtual

copy, copies line by an offset

Parameters
geo::Coordinateoffset
Returns
CADEntity_CSPtr copied entity

Implements lc::entity::CADEntity.

Definition at line 100 of file arc.cpp.

100  {
101  auto newArc = std::make_shared<Arc>(this->center() + offset, this->radius(), this->startAngle(), this->endAngle(),
102  this->CCW(), layer());
103  return newArc;
104 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
virtual void lc::entity::Arc::dispatch ( EntityDispatch ed) const
inlineoverridevirtual

Implements lc::entity::CADEntity.

Definition at line 95 of file arc.h.

95  {
96  ed.visit(shared_from_this());
97  }
std::map< unsigned int, lc::geo::Coordinate > Arc::dragPoints ( ) const
overridevirtual

Get all points of the entity that can be dragged.

Returns
Map of points

Implements lc::Draggable.

Definition at line 148 of file arc.cpp.

148  {
149  std::map<unsigned int, lc::geo::Coordinate> dragPoints;
150 
151  dragPoints[0] = startP();
152  dragPoints[1] = endP();
153 
154  return dragPoints;
155 }
Coordinate startP() const
Definition: geoarc.cpp:130
Coordinate endP() const
Definition: geoarc.cpp:134
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: arc.cpp:148
CADEntity_CSPtr Arc::mirror ( const geo::Coordinate axis1,
const geo::Coordinate axis2 
) const
overridevirtual

Implements lc::entity::CADEntity.

Definition at line 123 of file arc.cpp.

123  {
124  double a= (axis2- axis1).angle()*2;
125 
126  auto newArc = std::make_shared<Arc>(this->center().mirror(axis1,axis2),
127  this->radius(),
128  lc::Math::correctAngle(a - this->startAngle()),
129  lc::Math::correctAngle(a - this->endAngle()),
130  !this->CCW(), layer());
131  newArc->setID(this->id());
132  return newArc;
133 
134 }
Coordinate mirror(const Coordinate &axis1, const Coordinate &axis2) const
mirror a coordinate
double angle() const
Definition: geoarc.cpp:167
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
static double correctAngle(double a)
correctAngle, Corrects angle to be in -PI to PI
Definition: lcmath.cpp:33
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
CADEntity_CSPtr Arc::modify ( Layer_CSPtr  layer,
const MetaInfo_CSPtr  metaInfo,
Block_CSPtr  block 
) const
overridevirtual

modify Return a new entity with the same ID bit with possible modified metainfo and/pr layer information #return new entity with same ID

Implements lc::entity::CADEntity.

Definition at line 140 of file arc.cpp.

140  {
141  auto newArc = std::make_shared<Arc>(this->center(), this->radius(), this->startAngle(), this->endAngle(),
142  this->CCW(), layer, metaInfo, block);
143  newArc->setID(this->id());
144  return newArc;
145 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
CADEntity_CSPtr Arc::move ( const geo::Coordinate offset) const
overridevirtual

move, moves by an offset

Parameters
geo::Coordinateoffset
Returns
CADEntity_CSPtr moved entity

Implements lc::entity::CADEntity.

Definition at line 93 of file arc.cpp.

93  {
94  auto newArc = std::make_shared<Arc>(this->center() + offset, this->radius(), this->startAngle(), this->endAngle(),
95  this->CCW(), layer());
96  newArc->setID(this->id());
97  return newArc;
98 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
geo::Coordinate Arc::nearestPointOnPath ( const geo::Coordinate coord) const
overridevirtual

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

Implements lc::Snapable.

Definition at line 81 of file arc.cpp.

81  {
82  const geo::Coordinate pointOnPath = geo::Arc::nearestPointOnPath(coord);
83  /*
84  double vl1 = (center() - coord).magnitude();
85  double vl2 = (pointOnPath - coord).magnitude();
86  if (vl1 < vl2) {
87  return center();
88  } */
89 
90  return pointOnPath;
91 }
Coordinate nearestPointOnPath(const Coordinate &coord) const
Definition: geoarc.cpp:95
CADEntity_CSPtr Arc::rotate ( const geo::Coordinate rotation_center,
const double  rotation_angle 
) const
overridevirtual

rotate, rotate operation

Parameters
geo::Coordinaterotation_center
doublerotation_angle
Returns
CADEntity_CSPtr rotated entity

Implements lc::entity::CADEntity.

Definition at line 106 of file arc.cpp.

106  {
107  auto newArc = std::make_shared<Arc>(this->center().rotate(rotation_center, rotation_angle),
108  this->radius(), this->startAngle() + rotation_angle,
109  this->endAngle() + rotation_angle, this->CCW(), layer());
110  newArc->setID(this->id());
111  return newArc;
112 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
CADEntity_CSPtr Arc::scale ( const geo::Coordinate scale_center,
const geo::Coordinate scale_factor 
) const
overridevirtual

scale, scales the entity

Parameters
geo::Coordinatescale_center
doublescale_factor
Returns

Implements lc::entity::CADEntity.

Definition at line 114 of file arc.cpp.

114  {
115  auto newArc = std::make_shared<Arc>(this->center().scale(scale_center, scale_factor),
116  this->radius() * fabs(scale_factor.x()),
117  this->startAngle(), this->endAngle(), this->CCW(), layer());
118  newArc->setID(this->id());
119  return newArc;
120 
121 }
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
Coordinate scale(const double &scale_factor) const
bool CCW() const
Returns of the arc is in reversed direction.
Definition: geoarc.cpp:126
double endAngle() const
Returns the EndAngle.
Definition: geoarc.cpp:87
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
double startAngle() const
Returns the startAngle.
Definition: geoarc.cpp:83
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91
CADEntity_CSPtr Arc::setDragPoints ( std::map< unsigned int, lc::geo::Coordinate dragPoints) const
overridevirtual

Return modified entity.

Parameters
dragPointsModified points
Returns
New entity or same entity if an error occurred Return the new entity which corresponds to the given points. Points must be associated to the same number given in dragPoints().

Implements lc::Draggable.

Definition at line 158 of file arc.cpp.

158  {
159  try {
160  auto newEntity = std::make_shared<Arc>(geo::Arc::createArcBulge(dragPoints.at(0), dragPoints.at(1), bulge()), layer(), metaInfo());
161  newEntity->setID(id());
162  return newEntity;
163  }
164  catch(std::out_of_range& e) {
165  return shared_from_this();
166  }
167 }
Layer_CSPtr layer() const
layer return the layer this entity is placed on
Definition: cadentity.cpp:29
static Arc createArcBulge(const Coordinate &p1, const Coordinate &p2, const double bulge)
Definition: geoarc.cpp:51
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
Definition: arc.cpp:148
double bulge() const
Definition: geoarc.cpp:171
std::vector< EntityCoordinate > Arc::snapPoints ( const geo::Coordinate coord,
const SimpleSnapConstrain simpleSnapConstrain,
double  minDistanceToSnap,
int  maxNumberOfSnapPoints 
) const
overridevirtual

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

Implements lc::Snapable.

Definition at line 27 of file arc.cpp.

28  {
29  std::vector<EntityCoordinate> points;
30  if (constrain.constrain() & SimpleSnapConstrain::LOGICAL) {
31  // Add center
32  lc::geo::Coordinate coord = center();
33  points.emplace_back(coord, 0);
34  points.emplace_back(startP(), 1);
35  points.emplace_back(endP(), 2);
36 
37  // Add 4 coordinates
38  // Top Point
39  if (geo::Arc::isAngleBetween(.5 * M_PI)) {
40  coord = center() + lc::geo::Coordinate(0., radius());
41  points.emplace_back(coord, 1);
42  }
43  // Right Point
44  if (geo::Arc::isAngleBetween(0)) {
45  coord = center() + lc::geo::Coordinate(radius(), 0.);
46  points.emplace_back(coord, 2);
47  }
48  // Left Point
50  coord = center() + lc::geo::Coordinate(-radius(), 0.);
51  points.emplace_back(coord, 3);
52  }
53  // Bottom Point
54  if (geo::Arc::isAngleBetween(-.5 * M_PI)) {
55  coord = center() + lc::geo::Coordinate(0., -radius());
56  points.emplace_back(coord, 4);
57  }
58  }
59 
60  // Any where on entity path
61  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITYPATH) {
62  geo::Coordinate npoe = nearestPointOnPath(coord);
63  points.emplace_back(npoe, -1);
64  }
65 
66  // Any where on entity
67  if (constrain.constrain() & SimpleSnapConstrain::ON_ENTITY) {
68  geo::Coordinate npoe = nearestPointOnPath(coord);
69  const double a = (npoe - center()).angle();
70  if (isAngleBetween(a)) {
71  points.emplace_back(npoe, -1);
72  }
73  }
74 
75  // Cleanup array of snappoints
76  Snapable::snapPointsCleanup(points, coord, maxNumberOfSnapPoints, minDistanceToSnap);
77  return points;
78 }
double angle() const
Definition: geoarc.cpp:167
Coordinate startP() const
Definition: geoarc.cpp:130
static const uint16_t LOGICAL
Definition: snapconstrain.h:22
static const uint16_t ON_ENTITYPATH
Definition: snapconstrain.h:19
static const uint16_t ON_ENTITY
Definition: snapconstrain.h:18
static void snapPointsCleanup(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
Definition: snapable.h:53
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate &coord) const override
Find the nearest point on the path for this entity for the coordinate coord The path of a entity that...
Definition: arc.cpp:81
#define M_PI
Definition: const.h:16
Coordinate endP() const
Definition: geoarc.cpp:134
double radius() const
Returns the radius of Arc.
Definition: geoarc.cpp:79
bool isAngleBetween(double angle) const
Definition: geoarc.cpp:163
const Coordinate center() const
Returns center of Arc.
Definition: geoarc.cpp:91

Friends And Related Function Documentation

friend class builder::ArcBuilder
friend

Definition at line 20 of file arc.h.


The documentation for this class was generated from the following files:
  • lckernel/cad/primitive/arc.h
  • lckernel/cad/primitive/arc.cpp