]> Shamusworld >> Repos - architektonas/blobdiff - src/base/rs_solid.cpp
Changed RS_Graphic to Drawing; this is less confusing as a drawing is
[architektonas] / src / base / rs_solid.cpp
index 0b447a7319d898ee17b8374590f96980f9ad9e2e..2badd754754d78ee1a3e7974e7f75b4d45a1218b 100644 (file)
@@ -1,61 +1,47 @@
-/****************************************************************************
-** $Id: rs_solid.cpp 1938 2004-12-09 23:09:53Z andrew $
-**
-** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
-**
-** This file is part of the qcadlib Library project.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** Licensees holding valid qcadlib Professional Edition licenses may use
-** this file in accordance with the qcadlib Commercial License
-** Agreement provided with the Software.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.ribbonsoft.com for further details.
-**
-** Contact info@ribbonsoft.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
+// rs_solid.cpp
+//
+// Part of the Architektonas Project
+// Originally part of QCad Community Edition by Andrew Mustun
+// Extensively rewritten and refactored by James L. Hammons
+// (C) 2010 Underground Software
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -----------------------------------------------------------
+// JLH  06/02/2010  Added this text. :-)
+//
 
 #include "rs_solid.h"
 
 #include "rs_graphicview.h"
-//#include "rs_painter.h"
 #include "paintintf.h"
 
 /**
  * Default constructor.
  */
-RS_Solid::RS_Solid(RS_EntityContainer* parent,
-                   const RS_SolidData& d)
-        :RS_AtomicEntity(parent), data(d) {
-    calculateBorders();
+RS_Solid::RS_Solid(RS_EntityContainer * parent, const RS_SolidData& d):
+       RS_AtomicEntity(parent), data(d)
+{
+       calculateBorders();
 }
 
-
-
 /**
  * @return Corner number 'num'.
  */
-Vector RS_Solid::getCorner(int num) {
-    if (num>=0 && num<4) {
-        return data.corner[num];
-    } else {
-        RS_DEBUG->print("Illegal corner requested from Solid",
-                        RS_Debug::D_WARNING);
-        return Vector(false);
-    }
+Vector RS_Solid::getCorner(int num)
+{
+       if (num >= 0 && num < 4)
+       {
+               return data.corner[num];
+       }
+       else
+       {
+               RS_DEBUG->print("Illegal corner requested from Solid", RS_Debug::D_WARNING);
+               return Vector(false);
+       }
 }
 
-
-
 /**
  * Shapes this Solid into a standard arrow (used in dimensions).
  *
@@ -63,157 +49,139 @@ Vector RS_Solid::getCorner(int num) {
  * @param angle Direction of the arrow.
  * @param arrowSize Size of arrow (length).
  */
-void RS_Solid::shapeArrow(const Vector& point,
-                          double angle,
-                          double arrowSize) {
-
-    double cosv1, sinv1, cosv2, sinv2;
-    double arrowSide = arrowSize/cos(0.165);
+void RS_Solid::shapeArrow(const Vector & point, double angle, double arrowSize)
+{
+       double cosv1, sinv1, cosv2, sinv2;
+       double arrowSide = arrowSize/cos(0.165);
 
-    cosv1 = cos(angle+0.165)*arrowSide;
-    sinv1 = sin(angle+0.165)*arrowSide;
-    cosv2 = cos(angle-0.165)*arrowSide;
-    sinv2 = sin(angle-0.165)*arrowSide;
+       cosv1 = cos(angle+0.165)*arrowSide;
+       sinv1 = sin(angle+0.165)*arrowSide;
+       cosv2 = cos(angle-0.165)*arrowSide;
+       sinv2 = sin(angle-0.165)*arrowSide;
 
-    data.corner[0] = point;
-    data.corner[1] = Vector(point.x - cosv1, point.y - sinv1);
-    data.corner[2] = Vector(point.x - cosv2, point.y - sinv2);
-    data.corner[3] = Vector(false);
+       data.corner[0] = point;
+       data.corner[1] = Vector(point.x - cosv1, point.y - sinv1);
+       data.corner[2] = Vector(point.x - cosv2, point.y - sinv2);
+       data.corner[3] = Vector(false);
 
-    calculateBorders();
+       calculateBorders();
 }
 
+void RS_Solid::calculateBorders()
+{
+       resetBorders();
 
-
-void RS_Solid::calculateBorders() {
-    resetBorders();
-
-    for (int i=0; i<4; ++i) {
-        if (data.corner[i].valid) {
-            minV = Vector::minimum(minV, data.corner[i]);
-            maxV = Vector::maximum(maxV, data.corner[i]);
-        }
-    }
+       for(int i=0; i<4; ++i)
+       {
+               if (data.corner[i].valid)
+               {
+                       minV = Vector::minimum(minV, data.corner[i]);
+                       maxV = Vector::maximum(maxV, data.corner[i]);
+               }
+       }
 }
 
+Vector RS_Solid::getNearestEndpoint(const Vector & coord, double * dist)
+{
+       double minDist = RS_MAXDOUBLE;
+       double curDist;
+       Vector ret;
 
+       for (int i=0; i<4; ++i)
+       {
+               if (data.corner[i].valid)
+               {
+                       curDist = data.corner[i].distanceTo(coord);
 
-Vector RS_Solid::getNearestEndpoint(const Vector& coord, double* dist) {
-
-    double minDist = RS_MAXDOUBLE;
-    double curDist;
-    Vector ret;
-
-    for (int i=0; i<4; ++i) {
-        if (data.corner[i].valid) {
-            curDist = data.corner[i].distanceTo(coord);
-            if (curDist<minDist) {
-                ret = data.corner[i];
-                minDist = curDist;
-            }
-        }
-    }
+                       if (curDist < minDist)
+                       {
+                               ret = data.corner[i];
+                               minDist = curDist;
+                       }
+               }
+       }
 
-    if (dist!=NULL) {
-        *dist = minDist;
-    }
+       if (dist != NULL)
+               *dist = minDist;
 
-    return ret;
+       return ret;
 }
 
-
-
 /**
  * @todo Implement this.
  */
-Vector RS_Solid::getNearestPointOnEntity(const Vector& /*coord*/,
-        bool /*onEntity*/, double* /*dist*/, RS_Entity** /*entity*/) {
-
-    Vector ret(false);
-    return ret;
+Vector RS_Solid::getNearestPointOnEntity(const Vector & /*coord*/,
+       bool /*onEntity*/, double * /*dist*/, RS_Entity ** /*entity*/)
+{
+       Vector ret(false);
+       return ret;
 }
 
+Vector RS_Solid::getNearestCenter(const Vector & /*coord*/, double * dist)
+{
+       if (dist != NULL)
+               *dist = RS_MAXDOUBLE;
 
+       return Vector(false);
+}
 
-Vector RS_Solid::getNearestCenter(const Vector& /*coord*/,
-                                     double* dist) {
-
-    if (dist!=NULL) {
+Vector RS_Solid::getNearestMiddle(const Vector & /*coord*/, double * dist)
+{
+    if (dist != NULL)
         *dist = RS_MAXDOUBLE;
-    }
 
-    return Vector(false);
+       return Vector(false);
 }
 
-
-
-Vector RS_Solid::getNearestMiddle(const Vector& /*coord*/,
-                                     double* dist) {
-    if (dist!=NULL) {
+Vector RS_Solid::getNearestDist(double /*distance*/, const Vector & /*coord*/, double * dist)
+{
+    if (dist != NULL)
         *dist = RS_MAXDOUBLE;
-    }
-    return Vector(false);
-}
-
-
 
-Vector RS_Solid::getNearestDist(double /*distance*/,
-                                   const Vector& /*coord*/,
-                                   double* dist) {
-    if (dist!=NULL) {
-        *dist = RS_MAXDOUBLE;
-    }
-    return Vector(false);
+       return Vector(false);
 }
 
-
-
 /**
  * @return Distance from one of the boundry lines of this solid to given point.
  *
  * @todo implement
  */
-double RS_Solid::getDistanceToPoint(const Vector& /*coord*/,
-                                    RS_Entity** /*entity*/,
-                                    RS2::ResolveLevel /*level*/,
-                                                                   double /*solidDist*/) {
-    return RS_MAXDOUBLE;
+double RS_Solid::getDistanceToPoint(const Vector & /*coord*/, RS_Entity ** /*entity*/,
+       RS2::ResolveLevel /*level*/, double /*solidDist*/)
+{
+       return RS_MAXDOUBLE;
 }
 
+void RS_Solid::move(Vector offset)
+{
+       for(int i=0; i<4; ++i)
+               data.corner[i].move(offset);
 
-
-void RS_Solid::move(Vector offset) {
-    for (int i=0; i<4; ++i) {
-        data.corner[i].move(offset);
-    }
-    calculateBorders();
+       calculateBorders();
 }
 
+void RS_Solid::rotate(Vector center, double angle)
+{
+       for(int i=0; i<4; ++i)
+               data.corner[i].rotate(center, angle);
 
-
-void RS_Solid::rotate(Vector center, double angle) {
-    for (int i=0; i<4; ++i) {
-        data.corner[i].rotate(center, angle);
-    }
-    calculateBorders();
+       calculateBorders();
 }
 
+void RS_Solid::scale(Vector center, Vector factor)
+{
+       for(int i=0; i<4; ++i)
+               data.corner[i].scale(center, factor);
 
-
-void RS_Solid::scale(Vector center, Vector factor) {
-    for (int i=0; i<4; ++i) {
-        data.corner[i].scale(center, factor);
-    }
-    calculateBorders();
+       calculateBorders();
 }
 
+void RS_Solid::mirror(Vector axisPoint1, Vector axisPoint2)
+{
+       for(int i=0; i<4; ++i)
+               data.corner[i].mirror(axisPoint1, axisPoint2);
 
-
-void RS_Solid::mirror(Vector axisPoint1, Vector axisPoint2) {
-    for (int i=0; i<4; ++i) {
-        data.corner[i].mirror(axisPoint1, axisPoint2);
-    }
-    calculateBorders();
+       calculateBorders();
 }
 
 //void RS_Solid::draw(RS_Painter* painter, RS_GraphicView* view, double /*patternOffset*/)