Changes in src/Shapes/ShapeOps.cpp [5e588b5:79dd0e]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Shapes/ShapeOps.cpp
r5e588b5 r79dd0e 11 11 #include "Helpers/Assert.hpp" 12 12 13 /*************** Base case ***********************/ 14 15 ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) : 16 arg(_arg){} 17 18 ShapeOpsBase_impl::~ShapeOpsBase_impl(){} 19 20 bool ShapeOpsBase_impl::isInside(const Vector &point){ 21 return arg->isInside(translateIn(point)); 22 } 23 24 bool ShapeOpsBase_impl::isOnSurface(const Vector &point){ 25 return arg->isOnSurface(translateIn(point)); 26 } 27 28 Vector ShapeOpsBase_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){ 29 Vector helper = translateIn(point); 30 if(!arg->isOnSurface(helper)){ 31 throw NotOnSurfaceException(__FILE__,__LINE__); 32 } 33 return translateOutNormal(arg->getNormal(helper)); 34 } 35 36 Shape::impl_ptr ShapeOpsBase_impl::getArg(){ 37 return arg; 38 } 39 13 40 /********************* Resize ********************/ 14 41 15 42 Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) : 16 arg(_arg), size(_size)43 ShapeOpsBase_impl(_arg), size(_size) 17 44 { 18 45 ASSERT(size>0,"Cannot resize a Shape to size zero or below"); … … 21 48 Resize_impl::~Resize_impl(){} 22 49 23 bool Resize_impl::isInside(const Vector& point){ 24 return arg->isInside((1/size) * point); 50 Vector Resize_impl::translateIn(const Vector& point){ 51 return (1/size) * point; 52 } 53 54 Vector Resize_impl::translateOutPos(const Vector& point){ 55 return size * point; 56 } 57 58 Vector Resize_impl::translateOutNormal(const Vector& point){ 59 return point; 60 } 61 62 string Resize_impl::toString(){ 63 stringstream sstr; 64 sstr << "resize(" << getArg()->toString() << "," << size << ")"; 65 return sstr.str(); 25 66 } 26 67 … … 33 74 34 75 Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) : 35 arg(_arg),offset(_offset)76 ShapeOpsBase_impl(_arg),offset(_offset) 36 77 {} 37 78 38 79 Translate_impl::~Translate_impl(){} 39 80 40 bool Translate_impl::isInside(const Vector& point){ 41 return arg->isInside(point-offset); 81 Vector Translate_impl::translateIn(const Vector& point){ 82 return point-offset; 83 } 84 85 Vector Translate_impl::translateOutPos(const Vector& point){ 86 return point+offset; 87 } 88 89 Vector Translate_impl::translateOutNormal(const Vector& point){ 90 return point; 91 } 92 93 string Translate_impl::toString(){ 94 stringstream sstr; 95 sstr << "translate(" << getArg()->toString() << "," << offset << ")"; 96 return sstr.str(); 42 97 } 43 98 … … 50 105 51 106 Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) : 52 arg(_arg),factors(_factors)107 ShapeOpsBase_impl(_arg),factors(_factors) 53 108 { 54 109 ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount"); … … 62 117 Stretch_impl::~Stretch_impl(){} 63 118 64 bool Stretch_impl::isInside(const Vector& point){119 Vector Stretch_impl::translateIn(const Vector& point){ 65 120 Vector helper=point; 66 121 helper.ScaleAll(reciFactors); 67 return arg->isInside(helper); 122 return helper; 123 } 124 125 Vector Stretch_impl::translateOutPos(const Vector& point){ 126 Vector helper=point; 127 helper.ScaleAll(factors); 128 return helper; 129 } 130 131 Vector Stretch_impl::translateOutNormal(const Vector& point){ 132 Vector helper=point; 133 // the normalFactors are derived from appearances of the factors 134 // with in the vectorproduct 135 Vector normalFactors; 136 normalFactors[0]=factors[1]*factors[2]; 137 normalFactors[1]=factors[0]*factors[2]; 138 normalFactors[2]=factors[0]*factors[1]; 139 helper.ScaleAll(normalFactors); 140 return helper; 141 } 142 143 string Stretch_impl::toString(){ 144 stringstream sstr; 145 sstr << "stretch(" << getArg()->toString() << "," << factors << ")"; 146 return sstr.str(); 68 147 } 69 148 … … 76 155 77 156 Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) : 78 arg(_arg),transformation(_transformation)157 ShapeOpsBase_impl(_arg),transformation(_transformation) 79 158 { 80 159 transformationInv = transformation.invert(); … … 83 162 Transform_impl::~Transform_impl(){} 84 163 85 bool Transform_impl::isInside(const Vector& point){ 86 return arg->isInside(transformationInv * point); 164 Vector Transform_impl::translateIn(const Vector& point){ 165 return transformationInv * point; 166 } 167 168 Vector Transform_impl::translateOutPos(const Vector& point){ 169 return transformation * point; 170 } 171 172 Vector Transform_impl::translateOutNormal(const Vector& point){ 173 Matrix mat = transformation.determinant() * transformation.invert().transpose(); 174 return mat * point; 175 } 176 177 string Transform_impl::toString(){ 178 stringstream sstr; 179 sstr << "transform(" << getArg()->toString() << "," << transformation << ")"; 180 return sstr.str(); 87 181 } 88 182
Note:
See TracChangeset
for help on using the changeset viewer.