1 | /*
|
---|
2 | * ShapeOps.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jun 18, 2010
|
---|
5 | * Author: crueger
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Shapes/ShapeOps.hpp"
|
---|
9 | #include "Shapes/ShapeOps_impl.hpp"
|
---|
10 |
|
---|
11 | #include "Helpers/Assert.hpp"
|
---|
12 |
|
---|
13 | /********************* Resize ********************/
|
---|
14 |
|
---|
15 | Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) :
|
---|
16 | arg(_arg), size(_size)
|
---|
17 | {
|
---|
18 | ASSERT(size>0,"Cannot resize a Shape to size zero or below");
|
---|
19 | }
|
---|
20 |
|
---|
21 | Resize_impl::~Resize_impl(){}
|
---|
22 |
|
---|
23 | bool Resize_impl::isInside(const Vector& point){
|
---|
24 | return arg->isInside((1/size) * point);
|
---|
25 | }
|
---|
26 |
|
---|
27 | Shape resize(const Shape &arg,double size){
|
---|
28 | Shape::impl_ptr impl = Shape::impl_ptr(new Resize_impl(getShapeImpl(arg),size));
|
---|
29 | return Shape(impl);
|
---|
30 | }
|
---|
31 |
|
---|
32 | /*************************** translate *******************/
|
---|
33 |
|
---|
34 | Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) :
|
---|
35 | arg(_arg),offset(_offset)
|
---|
36 | {}
|
---|
37 |
|
---|
38 | Translate_impl::~Translate_impl(){}
|
---|
39 |
|
---|
40 | bool Translate_impl::isInside(const Vector& point){
|
---|
41 | return arg->isInside(point-offset);
|
---|
42 | }
|
---|
43 |
|
---|
44 | Shape translate(const Shape &arg, const Vector &offset){
|
---|
45 | Shape::impl_ptr impl = Shape::impl_ptr(new Translate_impl(getShapeImpl(arg),offset));
|
---|
46 | return Shape(impl);
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*********************** stretch ******************/
|
---|
50 |
|
---|
51 | Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) :
|
---|
52 | arg(_arg),factors(_factors)
|
---|
53 | {
|
---|
54 | ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount");
|
---|
55 | ASSERT(factors[1]>0,"cannot stretch a shape by a negative amount");
|
---|
56 | ASSERT(factors[2]>0,"cannot stretch a shape by a negative amount");
|
---|
57 | for(int i = NDIM;i--;){
|
---|
58 | reciFactors[i] = 1/factors[i];
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | Stretch_impl::~Stretch_impl(){}
|
---|
63 |
|
---|
64 | bool Stretch_impl::isInside(const Vector& point){
|
---|
65 | Vector helper=point;
|
---|
66 | helper.ScaleAll(reciFactors);
|
---|
67 | return arg->isInside(helper);
|
---|
68 | }
|
---|
69 |
|
---|
70 | Shape stretch(const Shape &arg, const Vector &factors){
|
---|
71 | Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors));
|
---|
72 | return Shape(impl);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /************************* transform *****************/
|
---|
76 |
|
---|
77 | Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) :
|
---|
78 | arg(_arg),transformation(_transformation)
|
---|
79 | {
|
---|
80 | transformationInv = transformation.invert();
|
---|
81 | }
|
---|
82 |
|
---|
83 | Transform_impl::~Transform_impl(){}
|
---|
84 |
|
---|
85 | bool Transform_impl::isInside(const Vector& point){
|
---|
86 | return arg->isInside(transformationInv * point);
|
---|
87 | }
|
---|
88 |
|
---|
89 | Shape transform(const Shape &arg, const Matrix &transformation){
|
---|
90 | Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation));
|
---|
91 | return Shape(impl);
|
---|
92 | }
|
---|