acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
_aaa_shape.h
1//
2// shape.hpp
3// acme
4//
5// Created by Camilo Sasuke Thomas Borregaard Soerensen on 01/10/20.
6// Copyright (c) 2020 Camilo Sasuke Thomas Borregaard Soerensen. All rights reserved.
7//
8#pragma once
9
10
11//#include "_geometry2d.h"
12#include "../_collection.h"
13//#include "_polygon.h"
14
15
16//#include "acme/prototype/prototype/element.h"
17#include "acme/exception/interface_only.h"
18
19
20template < typename HOLDEE >
21class ___shape :
22virtual public ::particle
23{
24protected:
25
26
27 enum_shape m_eshape;
28
29
30 ___shape(enum_shape eshape) : m_eshape(eshape) { }
31 ~___shape() override {}
32
33public:
34
35
36 inline enum_shape eshape() const { return m_eshape; }
37 virtual void * raw_type() const {return nullptr;}
38
39
40 virtual HOLDEE * holdee() { return nullptr; }
41 virtual const HOLDEE * holdee() const { return nullptr; }
42 virtual void holdee(HOLDEE *) {}
43
44 template < typename SHAPE >
45 SHAPE & shape() { return *(SHAPE *)raw_type(); }
46
47
48 template < typename SHAPE >
49 const SHAPE & shape() const { return *(SHAPE *)raw_type(); }
50
51
52 virtual bool expand_bounding_rect(::f64_rectangle & rectangle) const;
53
54 virtual bool expand_bounding_rect(::i32_rectangle & rectangle) const;
55
56 virtual bool get_bounding_box(::f64_rectangle & rectangle) const;
57
58 virtual bool get_bounding_box(::i32_rectangle & prectangle) const;
59
60 virtual bool contains(const ::i32_point & point) const;
61
62 virtual bool contains(const ::f64_point & point) const;
63
64
65};
66
67
68template < typename HOLDEE >
69class begin_clip_shape :
70virtual public ___shape < HOLDEE >
71{
72public:
73
74 begin_clip_shape():___shape< HOLDEE>(e_shape_begin_clip) {}
75
76 ::particle * clone() const override
77 {
78
79 return ___new begin_clip_shape();
80
81 }
82
83};
84
85
86template < typename HOLDEE >
87class intersect_clip_shape :
88virtual public ___shape < HOLDEE >
89{
90public:
91
92
93 intersect_clip_shape():___shape< HOLDEE>(e_shape_intersect_clip) {}
94
95
96 ::particle * clone() const override
97 {
98
99 return ___new intersect_clip_shape();
100
101 }
102
103};
104
105
106template < typename HOLDEE >
107class begin_figure_shape :
108 virtual public ___shape < HOLDEE >
109{
110public:
111
112 begin_figure_shape() :___shape< HOLDEE>(e_shape_begin_figure) {}
113
114 ::particle * clone() const override
115 {
116
117 return ___new begin_figure_shape();
118
119 }
120
121};
122
123
124template < typename HOLDEE >
125class close_figure_shape :
126 virtual public ___shape < HOLDEE >
127{
128public:
129
130 close_figure_shape() :___shape< HOLDEE>(e_shape_close_figure) {}
131
132 ::particle * clone() const override
133 {
134
135 return ___new close_figure_shape();
136
137 }
138
139};
140
141
142template < typename HOLDEE >
143class end_figure_shape :
144 virtual public ___shape < HOLDEE >
145{
146public:
147
148 end_figure_shape() :___shape< HOLDEE>(e_shape_end_figure) {}
149
150 ::particle * clone() const override
151 {
152
153 return ___new end_figure_shape();
154
155 }
156
157
158};
159
160
161
162template < typename SHAPE, enum_shape ESHAPE, typename HOLDEE >
163class _shape :
164virtual public ___shape < HOLDEE >
165{
166public:
167
168
169 SHAPE m_shape;
170
171 ::pointer<HOLDEE> m_pholdee;
172
173
174 _shape():___shape< HOLDEE>(ESHAPE) {}
175 _shape(const SHAPE & shape) : ___shape< HOLDEE>(ESHAPE), m_shape(shape) {}
176 ~_shape() override {}
177
178
179 HOLDEE * holdee() override { return m_pholdee; }
180 const HOLDEE * holdee() const override { return m_pholdee; }
181 void holdee(HOLDEE * pholdee) override { m_pholdee = pholdee; }
182
183
184 virtual void * raw_type() const override { return (void*) &m_shape; }
185
186
187 bool expand_bounding_rect(::f64_rectangle & prectangle) const override;
188
189
190 bool expand_bounding_rect(::i32_rectangle & prectangle) const override;
191
192
193 bool get_bounding_box(::f64_rectangle & prectangle) const override;
194
195
196 bool get_bounding_box(::i32_rectangle & prectangle) const override;
197
198
199 bool contains(const ::i32_point & point) const override;
200
201
202 bool contains(const ::f64_point & point) const override;
203
204
205 ::particle * clone() const override
206 {
207
208 return ___new _shape(m_shape);
209
210 }
211
212
213};
214
215
216
217
218
219
220//using arc_shape = _shape < ::arc, e_shape_arc>;
221//using line_shape = _shape < ::line, e_shape_line >;
222//using rectangle_shape = _shape < ::f64_rectangle, e_shape_rectangle >;
223//using ellipse_shape = _shape < ::f64_ellipse, e_shape_ellipse >;
224//using lines_shape = _shape < ::lines, e_shape_lines >;
225//using polygon_shape = _shape < ::polygon, e_shape_polygon >;
226
227
228// template < typename GEOMETRY >
229// inline ::pointer<___shape>__create_shape(const GEOMETRY& geometry);
230
231// template < typename HOLDE >
232// class shape_factory
233// {
234// public:
235// // template < typename GEOMETRY >
236// // inline ::pointer<___shape>__create_shape(const GEOMETRY& geometry);
237
238// };
239
240
241
242
243template < typename GEOMETRY, typename HOLDEE >
244inline pointer< ___shape < HOLDEE > > __create_shape(const GEOMETRY& geometry, holdee < HOLDEE >)
245{
246
247 throw interface_only();
248
249 return nullptr;
250
251}
252
253template < typename HOLDEE >
254inline pointer< ___shape < HOLDEE > > __create_shape(const enum_shape& eshape);
255
256
257template < typename HOLDEE >
258bool ___shape <HOLDEE>::expand_bounding_rect(::f64_rectangle & rectangle) const
259{
260
261 ::f64_rectangle r;
262
263 if (!get_bounding_box(r))
264 {
265
266 return false;
267
268 }
269
270 expand_rect(rectangle, r);
271
272 return true;
273
274}
275
276
277template < typename HOLDEE >
278bool ___shape<HOLDEE>::expand_bounding_rect(::i32_rectangle & rectangle) const
279{
280
281 ::f64_rectangle r;
282
283 if (!expand_bounding_rect(r))
284 {
285
286 return false;
287
288 }
289
290 expand_rect(rectangle, r);
291
292 return true;
293
294}
295
296
297template < typename HOLDEE >
298bool ___shape<HOLDEE>::get_bounding_box(::f64_rectangle & rectangle) const
299{
300
301 ::null(rectangle);
302
303 return false;
304
305}
306
307
308template < typename HOLDEE >
309bool ___shape<HOLDEE>::get_bounding_box(::i32_rectangle & rectangle) const
310{
311
312 ::null(rectangle);
313
314 return false;
315
316}
317
318
319template < typename HOLDEE >
320bool ___shape<HOLDEE>::contains(const ::i32_point & point) const
321{
322
323 // BUG SS (STILL SIMPLE) using bounding box HAHA LOL ROFL
324
325 ::i32_rectangle r;
326
327 if (!get_bounding_box(r))
328 {
329
330 return false;
331
332 }
333
334 return r.contains(point);
335
336}
337
338
339
340template < typename HOLDEE >
341bool ___shape<HOLDEE>::contains(const ::f64_point & point) const
342{
343
344 // BUG SS (STILL SIMPLE) using bounding box HAHA LOL ROFL
345
346 ::f64_rectangle r;
347
348 if (!get_bounding_box(r))
349 {
350
351 return false;
352
353 }
354
355 return r.contains(point);
356
357}
358
359
360
361
362
363
364template < prototype_number NUMBER, typename HOLDEE >
365using arc_shape = _shape < ::arc_type < NUMBER >, e_shape_arc, HOLDEE >;
366
367template < prototype_number NUMBER, typename HOLDEE >
368using line_shape = _shape < ::line_base < NUMBER >, e_shape_line, HOLDEE >;
369
370template < prototype_number NUMBER, typename HOLDEE >
371using rectangle_shape = _shape < ::rectangle_type < NUMBER >, e_shape_rectangle, HOLDEE >;
372
373template < prototype_number NUMBER, typename HOLDEE >
374using ellipse_shape = _shape < ::ellipse_base < NUMBER >, e_shape_ellipse, HOLDEE >;
375
376template < prototype_number NUMBER, typename HOLDEE >
377using lines_shape = _shape < ::lines_base < NUMBER >, e_shape_lines, HOLDEE >;
378
379template < prototype_number NUMBER, typename HOLDEE >
380using polygon_shape = _shape < ::polygon_base < NUMBER >, e_shape_polygon, HOLDEE >;
381
382
383template < typename HOLDEE >
384using arc_f64_shape = arc_shape < ::f64, HOLDEE >;
385
386template < typename HOLDEE >
387using f64_line_shape = line_shape < ::f64, HOLDEE >;
388
389template < typename HOLDEE >
390using f64_rectangle_shape = rectangle_shape < ::f64, HOLDEE >;
391
392template < typename HOLDEE >
393using ellipse_f64_shape = ellipse_shape < ::f64, HOLDEE >;
394
395template < typename HOLDEE >
396using lines_f64_shape = lines_shape < ::f64, HOLDEE >;
397
398template < typename HOLDEE >
399using f64_polygon_shape = polygon_shape < ::f64, HOLDEE >;
400
401
402
Definition interface_only.h:9