1 /****************************************************************************
2 ** $Id: rs_ellipse.h 2367 2005-04-04 16:57:36Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
31 #include "rs_atomicentity.h"
34 * Holds the data that defines an ellipse.
36 class RS_EllipseData {
38 RS_EllipseData(const Vector& center,
41 double angle1, double angle2,
44 this->center = center;
45 this->majorP = majorP;
47 this->angle1 = angle1;
48 this->angle2 = angle2;
49 this->reversed = reversed;
52 friend class RS_Ellipse;
54 friend std::ostream& operator << (std::ostream& os, const RS_EllipseData& ed) {
55 os << "(" << ed.center <<
67 //! Endpoint of major axis relative to center.
69 //! Ratio of minor axis to major axis.
75 //! Reversed (cw) flag
83 * Class for an ellipse entity. All angles are in Rad.
85 * @author Andrew Mustun
87 class RS_Ellipse : public RS_AtomicEntity {
89 RS_Ellipse(RS_EntityContainer* parent,
90 const RS_EllipseData& d);
91 virtual ~RS_Ellipse() {}
93 virtual RS_Entity* clone() {
94 RS_Ellipse* e = new RS_Ellipse(*this);
99 /** @return RS2::EntityEllipse */
100 virtual RS2::EntityType rtti() const {
101 return RS2::EntityEllipse;
106 * @return Start point of the entity.
108 virtual Vector getStartpoint() const {
110 p.set(data.center.x + cos(data.angle1) * getMajorRadius(),
111 data.center.y + sin(data.angle1) * getMinorRadius());
112 p.rotate(data.center, getAngle());
116 * @return End point of the entity.
118 virtual Vector getEndpoint() const {
120 p.set(data.center.x + cos(data.angle2) * getMajorRadius(),
121 data.center.y + sin(data.angle2) * getMinorRadius());
122 p.rotate(data.center, getAngle());
126 virtual void moveStartpoint(const Vector& pos);
127 virtual void moveEndpoint(const Vector& pos);
129 virtual RS2::Ending getTrimPoint(const Vector& coord,
130 const Vector& trimPoint);
132 double getEllipseAngle(const Vector& pos);
134 /** @return Copy of data that defines the ellipse. **/
135 RS_EllipseData getData() {
139 virtual VectorSolutions getRefPoints();
142 * @retval true if the arc is reversed (clockwise),
143 * @retval false otherwise
145 bool isReversed() const {
146 return data.reversed;
148 /** sets the reversed status. */
149 void setReversed(bool r) {
153 /** @return The rotation angle of this ellipse */
154 double getAngle() const {
155 return data.majorP.angle();
158 /** @return The start angle of this arc */
162 /** Sets new start angle. */
163 void setAngle1(double a1) {
166 /** @return The end angle of this arc */
170 /** Sets new end angle. */
171 void setAngle2(double a2) {
176 /** @return The center point (x) of this arc */
180 /** Sets new center. */
181 void setCenter(const Vector& c) {
185 /** @return The endpoint of the major axis (relative to center). */
189 /** Sets new major point (relative to center). */
190 void setMajorP(const Vector& p) {
194 /** @return The ratio of minor to major axis */
198 /** Sets new ratio. */
199 void setRatio(double r) {
205 * @return Angle length in rad.
207 virtual double getAngleLength() const {
209 return data.angle1-data.angle2;
211 return data.angle2-data.angle1;
215 /** @return The major radius of this ellipse. Same as getRadius() */
216 double getMajorRadius() const {
217 return data.majorP.magnitude();
220 /** @return The minor radius of this ellipse */
221 double getMinorRadius() const {
222 return data.majorP.magnitude()*data.ratio;
225 virtual Vector getNearestEndpoint(const Vector& coord,
226 double* dist = NULL);
227 virtual Vector getNearestPointOnEntity(const Vector& coord,
228 bool onEntity = true, double* dist = NULL, RS_Entity** entity=NULL);
229 virtual Vector getNearestCenter(const Vector& coord,
230 double* dist = NULL);
231 virtual Vector getNearestMiddle(const Vector& coord,
232 double* dist = NULL);
233 virtual Vector getNearestDist(double distance,
235 double* dist = NULL);
236 virtual double getDistanceToPoint(const Vector& coord,
237 RS_Entity** entity=NULL,
238 RS2::ResolveLevel level=RS2::ResolveNone,
239 double solidDist = RS_MAXDOUBLE);
240 virtual bool isPointOnEntity(const Vector& coord,
241 double tolerance=RS_TOLERANCE);
243 virtual void move(Vector offset);
244 virtual void rotate(Vector center, double angle);
245 virtual void scale(Vector center, Vector factor);
246 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
247 virtual void moveRef(const Vector& ref, const Vector& offset);
249 // virtual void draw(RS_Painter* painter, RS_GraphicView* view, double patternOffset=0.0);
250 virtual void draw(PaintInterface * painter, RS_GraphicView * view, double patternOffset = 0.0);
252 friend std::ostream & operator<<(std::ostream & os, const RS_Ellipse & a);
254 //virtual void calculateEndpoints();
255 virtual void calculateBorders();