X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Finformation.cpp;h=6c63857d2d584b6e636fbd4a9ba4bcb354740d1f;hb=2ee84c5948ede7fc2f7b4435c5edef42a030ac05;hp=ee95485fc182ed8b18d973061628af4c6a3109d1;hpb=3239ef39dcee08fa6e8cd68cdf2727fc68cc7a8c;p=architektonas diff --git a/src/base/information.cpp b/src/base/information.cpp index ee95485..6c63857 100644 --- a/src/base/information.cpp +++ b/src/base/information.cpp @@ -26,7 +26,7 @@ * entities. Usually that's an Drawing entity but * it can also be a polyline, text, ... */ -RS_Information::RS_Information(RS_EntityContainer& container) +Information::Information(EntityContainer& container) { this->container = &container; } @@ -35,7 +35,7 @@ RS_Information::RS_Information(RS_EntityContainer& container) * @return true: if the entity is a dimensioning enity. * false: otherwise */ -bool RS_Information::isDimension(RS2::EntityType type) +bool Information::isDimension(RS2::EntityType type) { if (type == RS2::EntityDimAligned || type == RS2::EntityDimLinear || type == RS2::EntityDimRadial || type == RS2::EntityDimDiametric @@ -53,7 +53,7 @@ bool RS_Information::isDimension(RS2::EntityType type) * @retval true the entity can be trimmed. * i.e. it is in a graphic or in a polyline. */ -bool RS_Information::isTrimmable(RS_Entity * e) +bool Information::isTrimmable(Entity * e) { if (e) { @@ -80,7 +80,7 @@ bool RS_Information::isTrimmable(RS_Entity * e) * @retval true the two entities can be trimmed to each other; * i.e. they are in a graphic or in the same polyline. */ -bool RS_Information::isTrimmable(RS_Entity * e1, RS_Entity * e2) +bool Information::isTrimmable(Entity * e1, Entity * e2) { if (e1 && e2) { @@ -91,10 +91,10 @@ bool RS_Information::isTrimmable(RS_Entity * e1, RS_Entity * e2) && e1->getParent()==e2->getParent()) { // in the same polyline - RS_EntityContainer * pl = e1->getParent(); + EntityContainer * pl = e1->getParent(); int idx1 = pl->findEntity(e1); int idx2 = pl->findEntity(e2); - RS_DEBUG->print("RS_Information::isTrimmable: idx1: %d, idx2: %d", idx1, idx2); + DEBUG->print("Information::isTrimmable: idx1: %d, idx2: %d", idx1, idx2); if (abs(idx1 - idx2) == 1 || abs(idx1 - idx2) == pl->count() - 1) { @@ -137,7 +137,7 @@ bool RS_Information::isTrimmable(RS_Entity * e1, RS_Entity * e2) * if there are no elements at all in this graphics * container. */ -Vector RS_Information::getNearestEndpoint(const Vector & coord, double * dist) const +Vector Information::getNearestEndpoint(const Vector & coord, double * dist) const { return container->getNearestEndpoint(coord, dist); } @@ -155,8 +155,8 @@ Vector RS_Information::getNearestEndpoint(const Vector & coord, double * dist) c * if there are no elements at all in this graphics * container. */ -Vector RS_Information::getNearestPointOnEntity(const Vector & coord, - bool onEntity, double * dist, RS_Entity ** entity) const +Vector Information::getNearestPointOnEntity(const Vector & coord, + bool onEntity, double * dist, Entity ** entity) const { return container->getNearestPointOnEntity(coord, onEntity, dist, entity); } @@ -172,7 +172,7 @@ Vector RS_Information::getNearestPointOnEntity(const Vector & coord, * @return the entity found or NULL if there are no elements * at all in this graphics container. */ -RS_Entity * RS_Information::getNearestEntity(const Vector & coord, +Entity * Information::getNearestEntity(const Vector & coord, double * dist, RS2::ResolveLevel level) const { return container->getNearestEntity(coord, dist, level); @@ -190,8 +190,8 @@ RS_Entity * RS_Information::getNearestEntity(const Vector & coord, * @return All intersections of the two entities. The tangent flag in * VectorSolutions is set if one intersection is a tangent point. */ -VectorSolutions RS_Information::getIntersection(RS_Entity * e1, - RS_Entity * e2, bool onEntities) +VectorSolutions Information::getIntersection(Entity * e1, + Entity * e2, bool onEntities) { VectorSolutions ret; double tol = 1.0e-4; @@ -212,15 +212,15 @@ VectorSolutions RS_Information::getIntersection(RS_Entity * e1, { if (e2->rtti() == RS2::EntityEllipse) { - RS_Entity * tmp = e1; + Entity * tmp = e1; e1 = e2; e2 = tmp; } if (e2->rtti() == RS2::EntityLine) { - RS_Ellipse * ellipse = (RS_Ellipse *)e1; - ret = getIntersectionLineEllipse((RS_Line *)e2, ellipse); + Ellipse * ellipse = (Ellipse *)e1; + ret = getIntersectionLineEllipse((Line *)e2, ellipse); tol = 1.0e-1; } // ellipse / arc, ellipse / ellipse: not supported: @@ -231,20 +231,20 @@ VectorSolutions RS_Information::getIntersection(RS_Entity * e1, } else { - RS_Entity * te1 = e1; - RS_Entity * te2 = e2; + Entity * te1 = e1; + Entity * te2 = e2; // entity copies - so we only have to deal with lines and arcs - RS_Line l1(NULL, RS_LineData(Vector(0.0, 0.0), Vector(0.0, 0.0))); - RS_Line l2(NULL, RS_LineData(Vector(0.0, 0.0), Vector(0.0, 0.0))); + Line l1(NULL, LineData(Vector(0.0, 0.0), Vector(0.0, 0.0))); + Line l2(NULL, LineData(Vector(0.0, 0.0), Vector(0.0, 0.0))); - RS_Arc a1(NULL, RS_ArcData(Vector(0.0, 0.0), 1.0, 0.0, 2 * M_PI, false)); - RS_Arc a2(NULL, RS_ArcData(Vector(0.0, 0.0), 1.0, 0.0, 2 * M_PI, false)); + Arc a1(NULL, ArcData(Vector(0.0, 0.0), 1.0, 0.0, 2 * M_PI, false)); + Arc a2(NULL, ArcData(Vector(0.0, 0.0), 1.0, 0.0, 2 * M_PI, false)); // convert construction lines to lines: if (e1->rtti() == RS2::EntityConstructionLine) { - RS_ConstructionLine * cl = (RS_ConstructionLine *)e1; + ConstructionLine * cl = (ConstructionLine *)e1; l1.setStartpoint(cl->getPoint1()); l1.setEndpoint(cl->getPoint2()); te1 = &l1; @@ -252,7 +252,7 @@ VectorSolutions RS_Information::getIntersection(RS_Entity * e1, if (e2->rtti() == RS2::EntityConstructionLine) { - RS_ConstructionLine * cl = (RS_ConstructionLine *)e2; + ConstructionLine * cl = (ConstructionLine *)e2; l2.setStartpoint(cl->getPoint1()); l2.setEndpoint(cl->getPoint2()); te2 = &l2; @@ -261,16 +261,16 @@ VectorSolutions RS_Information::getIntersection(RS_Entity * e1, // convert circles to arcs: if (e1->rtti() == RS2::EntityCircle) { - RS_Circle * c = (RS_Circle *)e1; - RS_ArcData data(c->getCenter(), c->getRadius(), 0.0, 2 * M_PI, false); + Circle * c = (Circle *)e1; + ArcData data(c->getCenter(), c->getRadius(), 0.0, 2 * M_PI, false); a1.setData(data); te1 = &a1; } if (e2->rtti() == RS2::EntityCircle) { - RS_Circle * c = (RS_Circle *)e2; - RS_ArcData data(c->getCenter(), c->getRadius(), 0.0, 2 * M_PI, false); + Circle * c = (Circle *)e2; + ArcData data(c->getCenter(), c->getRadius(), 0.0, 2 * M_PI, false); a2.setData(data); te2 = &a2; } @@ -280,37 +280,37 @@ VectorSolutions RS_Information::getIntersection(RS_Entity * e1, //else if (te1->rtti() == RS2::EntityLine && te2->rtti() == RS2::EntityLine) { - RS_Line * line1 = (RS_Line *)te1; - RS_Line * line2 = (RS_Line *)te2; + Line * line1 = (Line *)te1; + Line * line2 = (Line *)te2; ret = getIntersectionLineLine(line1, line2); } // line / arc: // else if (te1->rtti() == RS2::EntityLine && te2->rtti() == RS2::EntityArc) { - RS_Line * line = (RS_Line *)te1; - RS_Arc * arc = (RS_Arc *)te2; + Line * line = (Line *)te1; + Arc * arc = (Arc *)te2; ret = getIntersectionLineArc(line, arc); } // arc / line: // else if (te1->rtti() == RS2::EntityArc && te2->rtti() == RS2::EntityLine) { - RS_Arc * arc = (RS_Arc *)te1; - RS_Line * line = (RS_Line *)te2; + Arc * arc = (Arc *)te1; + Line * line = (Line *)te2; ret = getIntersectionLineArc(line, arc); } // arc / arc: // else if (te1->rtti() == RS2::EntityArc && te2->rtti() == RS2::EntityArc) { - RS_Arc * arc1 = (RS_Arc *)te1; - RS_Arc * arc2 = (RS_Arc *)te2; + Arc * arc1 = (Arc *)te1; + Arc * arc2 = (Arc *)te2; ret = getIntersectionArcArc(arc1, arc2); } else { - RS_DEBUG->print("RS_Information::getIntersection:: Unsupported entity type."); + DEBUG->print("Information::getIntersection:: Unsupported entity type."); } } @@ -360,7 +360,7 @@ VectorSolutions RS_Information::getIntersection(RS_Entity * e1, /** * @return Intersection between two lines. */ -VectorSolutions RS_Information::getIntersectionLineLine(RS_Line * e1, RS_Line * e2) +VectorSolutions Information::getIntersectionLineLine(Line * e1, Line * e2) { VectorSolutions ret; @@ -392,7 +392,7 @@ VectorSolutions RS_Information::getIntersectionLineLine(RS_Line * e1, RS_Line * /** * @return One or two intersection points between given entities. */ -VectorSolutions RS_Information::getIntersectionLineArc(RS_Line * line, RS_Arc * arc) +VectorSolutions Information::getIntersectionLineArc(Line * line, Arc * arc) { VectorSolutions ret; @@ -422,9 +422,9 @@ VectorSolutions RS_Information::getIntersectionLineArc(RS_Line * line, RS_Arc * Vector delta = p - c; // root term: - double term = RS_Math::pow(Vector::dotP(d, delta), 2.0) - - RS_Math::pow(d.magnitude(), 2.0) - * (RS_Math::pow(delta.magnitude(), 2.0) - RS_Math::pow(r, 2.0)); + double term = Math::pow(Vector::dotP(d, delta), 2.0) + - Math::pow(d.magnitude(), 2.0) + * (Math::pow(delta.magnitude(), 2.0) - Math::pow(r, 2.0)); // no intersection: if (term<0.0) { @@ -435,7 +435,7 @@ VectorSolutions RS_Information::getIntersectionLineArc(RS_Line * line, RS_Arc * // one or two intersections: else { double t1 = (- Vector::dotP(d, delta) + sqrt(term)) - / RS_Math::pow(d.magnitude(), 2.0); + / Math::pow(d.magnitude(), 2.0); double t2; bool tangent = false; @@ -448,7 +448,7 @@ VectorSolutions RS_Information::getIntersectionLineArc(RS_Line * line, RS_Arc * // two intersections else { t2 = (-Vector::dotP(d, delta) - sqrt(term)) - / RS_Math::pow(d.magnitude(), 2.0); + / Math::pow(d.magnitude(), 2.0); } Vector sol1; @@ -470,7 +470,7 @@ VectorSolutions RS_Information::getIntersectionLineArc(RS_Line * line, RS_Arc * /** * @return One or two intersection points between given entities. */ -VectorSolutions RS_Information::getIntersectionArcArc(RS_Arc * e1, RS_Arc * e2) +VectorSolutions Information::getIntersectionArcArc(Arc * e1, Arc * e2) { VectorSolutions ret; @@ -495,9 +495,9 @@ VectorSolutions RS_Information::getIntersectionArcArc(RS_Arc * e1, RS_Arc * e2) double s, t1, t2, term; - s = 1.0/2.0 * ((r1*r1 - r2*r2)/(RS_Math::pow(u.magnitude(), 2.0)) + 1.0); + s = 1.0/2.0 * ((r1*r1 - r2*r2)/(Math::pow(u.magnitude(), 2.0)) + 1.0); - term = (r1*r1)/(RS_Math::pow(u.magnitude(), 2.0)) - s*s; + term = (r1*r1)/(Math::pow(u.magnitude(), 2.0)) - s*s; // no intersection: if (term<0.0) { @@ -530,7 +530,7 @@ VectorSolutions RS_Information::getIntersectionArcArc(RS_Arc * e1, RS_Arc * e2) /** * @return One or two intersection points between given entities. */ -VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line * line, RS_Ellipse * ellipse) +VectorSolutions Information::getIntersectionLineEllipse(Line * line, Ellipse * ellipse) { VectorSolutions ret; @@ -558,7 +558,7 @@ VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line * line, RS_El double d = b*b - a*c; if (d < 0) { - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: outside 0"); + DEBUG->print("Information::getIntersectionLineEllipse: outside 0"); } else if ( d > 0 ) { double root = sqrt(d); double t_a = (-b - root) / a; @@ -566,24 +566,24 @@ VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line * line, RS_El /*if ( (t_a < 0 || 1 < t_a) && (t_b < 0 || 1 < t_b) ) { if ( (t_a < 0 && t_b < 0) || (t_a > 1 && t_b > 1) ) { - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: outside 1"); + DEBUG->print("Information::getIntersectionLineEllipse: outside 1"); } else { - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: inside 1"); + DEBUG->print("Information::getIntersectionLineEllipse: inside 1"); } } else {*/ - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: intersection 1"); + DEBUG->print("Information::getIntersectionLineEllipse: intersection 1"); Vector ret1(false); Vector ret2(false); //if ( 0 <= t_a && t_a <= 1 ) { - //RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: 0<=t_a<=1"); + //DEBUG->print("Information::getIntersectionLineEllipse: 0<=t_a<=1"); ret1 = a1.lerp(a2, t_a); - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: ret1: %f/%f", ret1.x, ret1.y); + DEBUG->print("Information::getIntersectionLineEllipse: ret1: %f/%f", ret1.x, ret1.y); //} //if ( 0 <= t_b && t_b <= 1 ) { - //RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: 0<=t_b<=1"); + //DEBUG->print("Information::getIntersectionLineEllipse: 0<=t_b<=1"); ret2 = a1.lerp(a2, t_b); - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: ret2: %f/%f", ret2.x, ret2.y); + DEBUG->print("Information::getIntersectionLineEllipse: ret2: %f/%f", ret2.x, ret2.y); //} if (ret1.valid && ret2.valid) { ret = VectorSolutions(ret1, ret2); @@ -600,12 +600,12 @@ VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line * line, RS_El } else { double t = -b/a; if ( 0 <= t && t <= 1 ) { - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: 0<=t<=1"); - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: intersection 2"); + DEBUG->print("Information::getIntersectionLineEllipse: 0<=t<=1"); + DEBUG->print("Information::getIntersectionLineEllipse: intersection 2"); ret = VectorSolutions(a1.lerp(a2, t)); - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: ret1: %f/%f", ret.get(0).x, ret.get(0).y); + DEBUG->print("Information::getIntersectionLineEllipse: ret1: %f/%f", ret.get(0).x, ret.get(0).y); } else { - RS_DEBUG->print("RS_Information::getIntersectionLineEllipse: outside 2"); + DEBUG->print("Information::getIntersectionLineEllipse: outside 2"); } } @@ -615,13 +615,13 @@ VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line * line, RS_El /* - RS_Arc* arc = new RS_Arc(NULL, - RS_ArcData(ellipse->getCenter(), + Arc* arc = new Arc(NULL, + ArcData(ellipse->getCenter(), ellipse->getMajorRadius(), ellipse->getAngle1(), ellipse->getAngle2(), false)); - RS_Line* other = (RS_Line*)line->clone(); + Line* other = (Line*)line->clone(); double angle = ellipse->getAngle(); //double ratio = ellipse->getRatio(); @@ -651,12 +651,12 @@ VectorSolutions RS_Information::getIntersectionLineEllipse(RS_Line * line, RS_El * @param onContour Will be set to true if the given point it exactly * on the contour. */ -bool RS_Information::isPointInsideContour(const Vector & point, - RS_EntityContainer * contour, bool * onContour) +bool Information::isPointInsideContour(const Vector & point, + EntityContainer * contour, bool * onContour) { if (contour==NULL) { - RS_DEBUG->print(RS_Debug::D_WARNING, - "RS_Information::isPointInsideContour: contour is NULL"); + DEBUG->print(Debug::D_WARNING, + "Information::isPointInsideContour: contour is NULL"); return false; } @@ -677,18 +677,18 @@ bool RS_Information::isPointInsideContour(const Vector & point, // create ray: Vector v; v.setPolar(width*10.0, rayAngle); - RS_Line ray(NULL, RS_LineData(point, point+v)); + Line ray(NULL, LineData(point, point+v)); counter = 0; VectorSolutions sol; if (onContour) *onContour = false; - for(RS_Entity * e=contour->firstEntity(RS2::ResolveAll); e!=NULL; + for(Entity * e=contour->firstEntity(RS2::ResolveAll); e!=NULL; e=contour->nextEntity(RS2::ResolveAll)) { // intersection(s) from ray with contour entity: - sol = RS_Information::getIntersection(&ray, e, true); + sol = Information::getIntersection(&ray, e, true); for(int i=0; i<=1; ++i) { @@ -708,12 +708,12 @@ bool RS_Information::isPointInsideContour(const Vector & point, { if (e->rtti() == RS2::EntityLine) { - RS_Line * line = (RS_Line *)e; + Line * line = (Line *)e; // ray goes through startpoint of line: if (p.distanceTo(line->getStartpoint()) < 1.0e-4) { - if (RS_Math::correctAngle(line->getAngle1()) < M_PI) + if (Math::correctAngle(line->getAngle1()) < M_PI) { counter++; sure = false; @@ -722,7 +722,7 @@ bool RS_Information::isPointInsideContour(const Vector & point, // ray goes through endpoint of line: else if (p.distanceTo(line->getEndpoint()) < 1.0e-4) { - if (RS_Math::correctAngle(line->getAngle2()) < M_PI) + if (Math::correctAngle(line->getAngle2()) < M_PI) { counter++; sure = false; @@ -736,7 +736,7 @@ bool RS_Information::isPointInsideContour(const Vector & point, } else if (e->rtti() == RS2::EntityArc) { - RS_Arc * arc = (RS_Arc *)e; + Arc * arc = (Arc *)e; if (p.distanceTo(arc->getStartpoint()) < 1.0e-4) {