LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
point.cpp
Go to the documentation of this file.
1 #include <memory>
2 #include <cad/primitive/point.h>
3 #include <cmath>
4 
5 #include <algorithm>
6 #include "cad/geometry/geoarea.h"
7 
8 using namespace lc;
9 using namespace entity;
10 
11 Point::Point(const double x, const double y,
12  const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, const Block_CSPtr block) :
13  CADEntity(layer, metaInfo, block),
14  geo::Coordinate(x, y) {
15 }
16 
18  const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, const Block_CSPtr block) :
19  CADEntity(layer, metaInfo, block),
20  geo::Coordinate(coord) {
21 }
22 
23 Point::Point(const Point_CSPtr other, bool sameID) : CADEntity(other, sameID), geo::Coordinate(other->x(), other->y()) {
24 }
25 
27  CADEntity(builder),
28  geo::Coordinate(builder.coordinate()) {
29 }
30 
31 CADEntity_CSPtr Point::move(const geo::Coordinate& offset) const {
32  auto newCoordinate = std::make_shared<Point>(this->x() + offset.x(), this->y() + offset.y(), layer());
33  newCoordinate->setID(this->id());
34  return newCoordinate;
35 }
36 
37 CADEntity_CSPtr Point::copy(const geo::Coordinate& offset) const {
38  auto newCoordinate = std::make_shared<Point>(this->x() + offset.x(), this->y() + offset.y(), layer());
39  return newCoordinate;
40 }
41 
42 CADEntity_CSPtr Point::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const {
43  auto rotcord = geo::Coordinate(this->x(), this->y()).rotate(rotation_center, rotation_angle);
44  auto newCoordinate = std::make_shared<Point>(rotcord.x(), rotcord.y(), layer());
45  newCoordinate->setID(this->id());
46  return newCoordinate;
47 }
48 
49 CADEntity_CSPtr Point::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const {
50  auto rotcord = geo::Coordinate(this->x(), this->y()).scale(scale_center, scale_factor);
51  auto newCoordinate = std::make_shared<Point>(rotcord.x(), rotcord.y(), layer());
52  newCoordinate->setID(this->id());
53  return newCoordinate;
54 }
55 
56 CADEntity_CSPtr Point::mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const {
57  auto rotcord = geo::Coordinate(this->x(), this->y()).rotate(axis1, axis2);
58  auto newCoordinate = std::make_shared<Point>(rotcord.x(), rotcord.y(), layer());
59  newCoordinate->setID(this->id());
60  return newCoordinate;
61 }
62 
64  return geo::Area(geo::Coordinate(this->x(), this->y()), 0., 0.);
65 }
66 
67 CADEntity_CSPtr Point::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const {
68  auto newEntity = std::make_shared<Point>(this->x(), this->y(),
69  layer,
70  metaInfo,
71  block
72  );
73  newEntity->setID(this->id());
74 
75  return newEntity;
76 }
77 
78 
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const override
copy, copies by an offset
Definition: point.cpp:37
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
Definition: point.cpp:49
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
Definition: point.cpp:42
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
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
Coordinate scale(const double &scale_factor) const
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 informat...
Definition: point.cpp:67
MetaInfo_CSPtr metaInfo() const
Definition: cadentity.h:123
Definition: cadentity.h:12
virtual CADEntity_CSPtr mirror(const geo::Coordinate &axis1, const geo::Coordinate &axis2) const override
Definition: point.cpp:56
Coordinate rotate(const Coordinate &angleVector) const
rotate around (0.,0.) with a given angle vector
Block_CSPtr block() const
Return the current entity block.
Definition: cadentity.cpp:33
Point(geo::Coordinate const &coord, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
Coordinate, Default Coordinate Constructor.
Definition: point.cpp:17
virtual const geo::Area boundingBox() const override
boundingBox of the entity
Definition: point.cpp:63
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
Definition: point.cpp:31