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