Skip to content

Commit

Permalink
Line, Circle Mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
gaganjyot committed Jun 5, 2016
1 parent 74d1ab8 commit 53e0a50
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lckernel/cad/base/cadentity.h
Expand Up @@ -78,6 +78,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const = 0;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const = 0;

/**
* @brief boundingBox
* Return the bounding box of this entity.
Expand Down
11 changes: 11 additions & 0 deletions lckernel/cad/geometry/geocoordinate.h
Expand Up @@ -204,6 +204,10 @@ namespace lc {
return _x * coord._x + _y * coord._y + _z * coord._z;
}

inline double dot(const Coordinate& v1, const Coordinate& v2) const {
return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
}

/**
* @brief rotate
* around (0.,0.) with a given angle vector
Expand Down Expand Up @@ -329,6 +333,13 @@ namespace lc {
return Coordinate(xx * _x + xy * _y + x0, yx * _x + yy * _y + y0, _z);
}

inline Coordinate mirror(const Coordinate& axis1, const Coordinate& axis2) const {
Coordinate dir(axis2 - axis1);
auto a= dir.squared();
auto ret= axis1 + dir* dot(*this- axis1, dir)/a; //projection point
return ret + ret - *this;
}

private:
friend std::ostream& operator<<(std::ostream& os, const Coordinate& coordinate) {
os << "Coordinate(x=" << coordinate._x << " y=" << coordinate._y << " z=" << coordinate._z << ")";
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/arc.h
Expand Up @@ -78,6 +78,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;


virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}
/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
7 changes: 7 additions & 0 deletions lckernel/cad/primitive/circle.cpp
Expand Up @@ -86,6 +86,13 @@ CADEntity_CSPtr Circle::scale(const geo::Coordinate &scale_center, const geo::Co
return newCircle;
}

CADEntity_CSPtr Circle::mirror(const geo::Coordinate &axis1, const geo::Coordinate &axis2) const {
auto newCircle = std::make_shared<Circle>(this->center().mirror(axis1, axis2),
this->radius(), layer(), metaInfo());
newCircle->setID(this->id());
return newCircle;
}

const geo::Area Circle::boundingBox() const {
return geo::Area(geo::Coordinate(center().x() - radius(), center().y() - radius()),
geo::Coordinate(center().x() + radius(), center().y() + radius()));
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/circle.h
Expand Up @@ -75,6 +75,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override;

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/dimaligned.h
Expand Up @@ -71,6 +71,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/dimangular.h
Expand Up @@ -71,6 +71,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/dimdiametric.h
Expand Up @@ -85,6 +85,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
2 changes: 2 additions & 0 deletions lckernel/cad/primitive/dimlinear.h
Expand Up @@ -73,6 +73,8 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}
/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/dimradial.h
Expand Up @@ -89,6 +89,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/ellipse.h
Expand Up @@ -65,6 +65,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/image.h
Expand Up @@ -84,6 +84,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
13 changes: 12 additions & 1 deletion lckernel/cad/primitive/line.cpp
Expand Up @@ -79,6 +79,17 @@ CADEntity_CSPtr Line::scale(const geo::Coordinate& scale_center, const geo::Coor
return newLine;
}

CADEntity_CSPtr Line::mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const {
auto newLine = std::make_shared<Line>(this->start().mirror(axis1,
axis2),
this->end().mirror(axis1,
axis2),
layer());
newLine->setID(this->id());
return newLine;
}

const geo::Area Line::boundingBox() const {
return geo::Area(start(), end());
}
Expand Down Expand Up @@ -108,4 +119,4 @@ CADEntity_CSPtr Line::setDragPoints(std::map<unsigned int, lc::geo::Coordinate>
//A point was not in the map, don't change the entity
return shared_from_this();
}
}
}
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/line.h
Expand Up @@ -101,6 +101,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override;

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/lwpolyline.h
Expand Up @@ -222,6 +222,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;


virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}
/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
7 changes: 7 additions & 0 deletions lckernel/cad/primitive/point.cpp
Expand Up @@ -49,6 +49,13 @@ CADEntity_CSPtr Point::scale(const geo::Coordinate& scale_center, const geo::Coo
return newCoordinate;
}

CADEntity_CSPtr Point::mirror(const geo::Coordinate& axis1, const geo::Coordinate& axis2) const {
auto rotcord = geo::Coordinate(this->x(), this->y()).rotate(axis1, axis2);
auto newCoordinate = std::make_shared<Point>(rotcord.x(), rotcord.y(), layer());
newCoordinate->setID(this->id());
return newCoordinate;
}

const geo::Area Point::boundingBox() const {
return geo::Area(geo::Coordinate(this->x(), this->y()), 0., 0.);
}
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/point.h
Expand Up @@ -74,6 +74,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override;

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/spline.h
Expand Up @@ -86,6 +86,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
3 changes: 3 additions & 0 deletions lckernel/cad/primitive/text.h
Expand Up @@ -139,6 +139,9 @@ namespace lc {
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center,
const geo::Coordinate &scale_factor) const override;

virtual CADEntity_CSPtr mirror(const geo::Coordinate& axis1,
const geo::Coordinate& axis2) const override {}

/**
* @brief boundingBox of the entity
* @return geo::Area area
Expand Down
10 changes: 9 additions & 1 deletion lcviewernoqt/drawitems/lcvline.cpp
Expand Up @@ -18,7 +18,15 @@ void LCVLine::draw(LcPainter& painter, const LcDrawOptions &options, const lc::g
painter.line_to(end().x(), end().y());
painter.stroke();

// auto c1 = lc::geo::Coordinate(0, 0);
// auto r = lc::geo::Coordinate(100, 100);
// painter.point(r.x(), r.y(), 5, 1);

// auto z = r.mirror(start(), end());

// painter.point(z.x(), z.y(), 5, 1);
// painter.stroke();

// auto c1 = lc::geo::Coordinate(0, 0);
// auto mp = lc::geo::Coordinate(1000, 0);
// auto rad = 100;
// auto sa = 0;
Expand Down

0 comments on commit 53e0a50

Please sign in to comment.