GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Pullback.hh
Go to the documentation of this file.
1#include "Effect.hh"
2
3template<class X>
4class X_Eq_Class : public Function<X, bool>
5{
6public:
7 X_Eq_Class(X x) : x(x) { }
8 bool Index(X y) { return x==y; }
9private:
10 X x;
11};
12
13class Eq_Class_Float : public Function<float, bool>
14{
15public:
16 Eq_Class_Float(float val) : val(val) { }
17 bool Index(float x) const
18 {
19 return fabs(x-val)<0.001;
20 }
21private:
22 float val;
23};
24
25class Eq_Class_Point : public Function<Point, bool>
26{
27public:
28 Eq_Class_Point(Point p) : p(p) { }
29 bool Index(Point pp) const
30 {
31 return (pp-p).Dist()<0.001;
32 }
33private:
34 Point p;
35};
36
37template<class T, class K>
38class Intersection : public Function<std::pair<T,K>,bool>
39{
40public:
41 Intersection(Function<T,bool> &f1, Function<K,bool> &f2) : f1(f1), f2(f2) { }
42 bool Index(std::pair<T,K> t) const { return f1.Index(t.first) && f2.Index(t.second); }
43private:
46};
47
48class Lattice : public Function<float,bool>
49{
50public:
51 Lattice() { }
52 bool Index(float x) const
53 {
54 int val = x;
55 float d = x-float(val);
56 return fabs(d)<0.001;
57 }
58};
59
60class Lattice2d : public Function<Point2d, bool>
61{
62public:
63 bool Index(Point2d p) const
64 {
65 bool xb = x.Index(p.first);
66 bool yb = y.Index(p.second);
67 return xb&&yb;
68 }
69private:
70 Lattice x;
71 Lattice y;
72};
73
74class Lattice3d : public Function<Point, bool>
75{
76public:
77 bool Index(Point p) const
78 {
79 bool xb = x.Index(p.x);
80 bool yb = y.Index(p.y);
81 bool zb = z.Index(p.z);
82 return xb&&yb&&zb;
83 }
84private:
85 Lattice x;
86 Lattice y;
87 Lattice z;
88};
89
90template<class T>
91class Subset : public Function<T,bool>
92{
93 virtual bool Index(T t) const=0; // characteristic function
94};
95
96template<class T>
97class Power : public Function<subset<T>*, bool>
98{
99public:
100 virtual std::vector<subset<T>*> Subsets() const=0;
101 virtual bool Index(subset<T> *power) const=0;
102 virtual subset<T> *Unique() const=0;
103};
104
105template<class I1, class I2, class C>
107{
108public:
109 virtual I1 SizeX() const=0;
110 virtual I2 SizeY() const=0;
111 virtual C Map(I1 i1, I2 i2) const=0;
112};
113
114template<class T, class K>
115class PowerIntersection : public PowerBitmap<subset<T>*, subset<K>*, bool>
116{
117public:
118 PowerIntersection(Power<T> *pw1, Power<K> *pw2) : pw1(pw1), pw2(pw2) { }
119 virtual subset<T>* SizeX() const { return NULL; }
120 virtual subset<K>* SizeY() const { return NULL; }
121 virtual bool Map(subset<T>* i1, subset<K> *i2) const
122 {
123 reutrn pw1.Index(i1) && pw2.Index(i2);
124 }
125private:
126 Power<T> *pw1;
127 Power<K> *pw2;
128};
129
130template<class P, class T, class K>
131class PowerSubsetP : public Power<subset<P> *>
132{
133public:
134 PowerSubsetP(Power<T> *left_p, Power<K> *right_p) : intersect(left_p, right_p), l(left_p), r(right_p) { }
135 virtual std::vector<subset<subset<P>*>*> Subsets() const=0;
136 virtual bool Index(subset<subset<P>*> *power) const
137 {
138 return intersect.Map(left_p->Unique(), right_p->Unique());
139 }
140 virtual subset<subset<P>*> *Unique() const=0;
141private:
142 PowerIntersection intersect;
143 Power<T> *left_p;
144 Power<K> *right_p;
145};
146
147template<class T, class K, class P>
149{
150 return new PowerSubsetP<P,T,K>(left_p, right_p);
151}
152
153template<class T>
154class SubsetSingle : public Subset<T>
155{
156public:
157 SubsetSingle(T t) : m_t(t) { }
158 bool Map(T t) const { return t==m_t; }
159private:
160 T m_t;
161};
162
163template<class T>
164class PSingle : public Power<T>
165{
166public:
167 PSingle(SubsetSingle<T> *subset) : subset(subset) { }
168 bool Inside(subset<T> *power) { return subset==power; }
169 subset<T> *Unique() const { return subset; }
170private:
171 SubsetSingle<T> *subset;
172};
173
174template<class T, class K>
176{
177public:
178 virtual K Map(T t) const=0;
179 virtual Power<T> *PMap(Power<K> *k) const=0; // contravariant powerset functor
180};
181
182template<class Top, class P, class A, class B, class C>
192
193template<class Top, class Pr, class A, class B, class C>
195{
196 PullBackArrow<Top,P> *pr = d.Product();
197 PullBackArrow<P,A> *lp = d.LeftProjection();
198 PullBackArrow<P,B> *rp = d.RightProjection();
199 PullBackArrow<A,C> *leq = d.LeftEq();
200 PullBackArrow<B,C> *req = d.RightEq();
201
202 P product = pr->Map(t);
203 A a = lp->Map(product);
204 C c = leq->Map(a);
205 SubsetSingle<C> subset(c);
206 PSingle<C> power(&subset);
207 Power<B> *pb = req->PMap(&power);
208 Power<P> *pp = rp->PMap(pb);
209 return pp->Unique();
210}
211
212template<class Top, class Pr, class A, class B, class C>
214{
215 PullBackArrow<Top,P> *pr = d.Product();
216 PullBackArrow<P,A> *lp = d.LeftProjection();
217 PullBackArrow<P,B> *rp = d.RightProjection();
218 PullBackArrow<A,C> *leq = d.LeftEq();
219 PullBackArrow<B,C> *req = d.RightEq();
220
221 // find correct c : C
222 P product = pr->Map(t);
223 A a = lp->Map(product);
224 C c = leq->Map(a);
225
226 // apply powerset functor for the object
227 SubsetSingle<C> subset(c);
228 PSingle<C> power(&subset);
229
230 // apply powerset functor for the pullback diagram arrows
231 // both sides of the equation
232 Power<A> *left_a = leq->PMap(&power);
233 Power<B> *right_b = req->PMap(&power);
234 Power<P> *left_p = lp->PMap(left_a);
235 Power<P> *right_p = lp->PMap(right_b);
236
237 // intersect
238 Power<subset<P>*> *i = Intersect(left_p, right_p);
239
240 // find unique subset
241 return i->Unique();
242}
subset< P > * PullBackLeft(PullBackDiagram< Top, P, A, B, C > &d, Top t)
Definition Pullback.hh:194
Power< subset< P > * > * Intersect(Power< T > *left_p, Power< K > *right_p)
subset< P > * PullBack(PullBackDiagram< Top, P, A, B, C > &d, Top t)
Definition Pullback.hh:213
Definition compiled_tests.cpp:1189
bool Index(float x) const
Definition Pullback.hh:17
Eq_Class_Float(float val)
Definition Pullback.hh:16
Eq_Class_Point(Point p)
Definition Pullback.hh:28
bool Index(Point pp) const
Definition Pullback.hh:29
Definition EffectI.hh:11
Definition Equalizer.hh:478
Intersection(Function< T, bool > &f1, Function< K, bool > &f2)
Definition Pullback.hh:41
bool Index(std::pair< T, K > t) const
Definition Pullback.hh:42
Definition Pullback.hh:61
bool Index(Point2d p) const
Definition Pullback.hh:63
Definition Pullback.hh:75
bool Index(Point p) const
Definition Pullback.hh:77
Definition Pullback.hh:49
bool Index(float x) const
Definition Pullback.hh:52
Lattice()
Definition Pullback.hh:51
Definition Pullback.hh:165
subset< T > * Unique() const
Definition Pullback.hh:169
PSingle(SubsetSingle< T > *subset)
Definition Pullback.hh:167
bool Inside(subset< T > *power)
Definition Pullback.hh:168
Definition Pullback.hh:107
virtual I2 SizeY() const =0
virtual C Map(I1 i1, I2 i2) const =0
virtual I1 SizeX() const =0
Definition Pullback.hh:116
virtual bool Map(subset< T > *i1, subset< K > *i2) const
Definition Pullback.hh:121
virtual subset< K > * SizeY() const
Definition Pullback.hh:120
virtual subset< T > * SizeX() const
Definition Pullback.hh:119
PowerIntersection(Power< T > *pw1, Power< K > *pw2)
Definition Pullback.hh:118
Definition Pullback.hh:132
virtual bool Index(subset< subset< P > * > *power) const
Definition Pullback.hh:136
PowerSubsetP(Power< T > *left_p, Power< K > *right_p)
Definition Pullback.hh:134
virtual std::vector< subset< subset< P > * > * > Subsets() const =0
virtual subset< subset< P > * > * Unique() const =0
Definition Pullback.hh:98
virtual subset< T > * Unique() const =0
virtual bool Index(subset< T > *power) const =0
virtual std::vector< subset< T > * > Subsets() const =0
Definition Pullback.hh:176
virtual Power< T > * PMap(Power< K > *k) const =0
virtual K Map(T t) const =0
Definition Pullback.hh:184
virtual PullBackArrow< Top, P > * Product()=0
virtual PullBackArrow< P, B > * RightProjection()=0
virtual PullBackArrow< B, C > * RightEq()=0
virtual PullBackArrow< P, A > * LeftProjection()=0
virtual PullBackArrow< A, C > * LeftEq()=0
Definition Pullback.hh:155
SubsetSingle(T t)
Definition Pullback.hh:157
bool Map(T t) const
Definition Pullback.hh:158
Definition Graph.hh:7961
Subset(Array< int, T > &enumeration, Function< T, B > &subsetfunc, Function< B, bool > &characteristic)
Definition Graph.hh:7963
X_Eq_Class(X x)
Definition Pullback.hh:7
bool Index(X y)
Definition Pullback.hh:8
Definition Equalizer.hh:1800
d
Definition meshpage.php:3895
int f2(char c)
Definition test.cpp:51
Definition GameApi.h:30
Definition FreeType2.cc:432
Definition GameApi.h:23
Definition VectorTools.hh:910
Definition Parser.cc:60
float x
Definition Parser.cc:60
float y
Definition Parser.cc:60
float z
Definition Parser.cc:60
Definition GameApi.h:42