Aurelon Open API 8.1.1
Loading...
Searching...
No Matches
AOI_Types.cpp
1#include "./AOI_Types.h"
2#include <ACPL/Types.h>
3#include "../GTypes.h"
4#include <memory.h>
5
39{
40 left = top = AOI_PosInf;
41 right = bottom = AOI_NegInf;
42}
43
52AOI_Rectangle::AOI_Rectangle( float x1, float y1, float x2, float y2 )
53{
54 left = x1;
55 top = y1;
56 right = x2;
57 bottom = y2;
58}
59
66{
67 left = inBounds.left;
68 top = inBounds.top;
69 right = inBounds.right;
70 bottom = inBounds.bottom;
71}
72
79void AOI_Rectangle::Union( const AOI_Rectangle& inBounds )
80{
81 if( inBounds.left < left )
82 left = inBounds.left;
83 if( inBounds.top < top )
84 top = inBounds.top;
85 if( inBounds.right > right )
86 right = inBounds.right;
87 if( inBounds.bottom > bottom )
88 bottom = inBounds.bottom;
89}
90
100{
101 if( inBounds.left > left )
102 left = inBounds.left;
103 if( inBounds.top > top )
104 top = inBounds.top;
105 if( inBounds.right < right )
106 right = inBounds.right;
107 if( inBounds.bottom < bottom )
108 bottom = inBounds.bottom;
109 return left <= right && top <= bottom;
110}
111
117bool AOI_Rectangle::CoordInBounds( const AOI_Point& inCoord ) const
118{
119 return inCoord.x >= left && inCoord.x <= right && inCoord.y >= top && inCoord.y <= bottom;
120}
121
127bool AOI_Rectangle::Overlaps( const AOI_Rectangle& inBounds ) const
128{
129 return inBounds.left < right && inBounds.top < bottom && inBounds.right > left && inBounds.bottom > top;
130}
131
138{
139 float h;
140 if( left > right )
141 {
142 h = left;
143 left = right;
144 right = h;
145 }
146 if( top > bottom )
147 {
148 h = top;
149 top = bottom;
150 bottom = h;
151 }
152}
153
161
168{
169 ::memcpy( &map, &inMap.map, 9 * sizeof(float) );
170}
171
187AOI_Mapping::AOI_Mapping( const float* array )
188{
189 ::memcpy( &map, array, 9 * sizeof(float) );
190}
191
207AOI_Mapping::AOI_Mapping( const double* array )
208{
209 map[0][0] = float( array[0] );
210 map[0][1] = float( array[1] );
211 map[0][2] = 0;
212 map[1][0] = float( array[2] );
213 map[1][1] = float( array[3] );
214 map[1][2] = 0;
215 map[2][0] = float( array[4] );
216 map[2][1] = float( array[5] );
217 map[2][2] = 1;
218}
219
224{
225 for( int32_t i = 0; i != 3; ++i )
226 for( int32_t j = 0; j != 3; ++j )
227 map[i][j] = 0;
228 map[0][0] = map[1][1] = map[2][2] = 1;
229}
230
235{
236 double a=1,b=0,c=0,d=0,e=1,f=0,g=0,h=0,i=1,
237 j=map[0][0],k=map[1][0],l=map[2][0],
238 m=map[0][1],n=map[1][1],o=map[2][1],
239 p=map[0][2],q=map[1][2],r=map[2][2];
240
241 if( j == 0 ) // m != 0
242 {
243 b=1; j = m; k += n; l+=o;
244 }
245 if( n == 0 )
246 {
247 d = 1; e += b; m += j; n = k; o +=l;
248 }
249 if( j != 1.0 )
250 {
251 a/=j; b/=j; c/=j; k/=j; l/=j; j=1;
252 }
253 if( m )
254 {
255 d-=m*a; e-=m*b; f-=m*c; n-=m*k; o-=m*l; m=0;
256 }
257 if( p )
258 {
259 g-=p*a; h-=p*b; i-=p*c; q-=p*k; r-=p*l; p=0;
260 }
261 if( n != 1.0 )
262 {
263 d/=n; e/=n; f/=n; o/=n; n=1;
264 }
265 if( k )
266 {
267 a-=k*d; b-=k*e; c-=k*f; l-=k*o; k=0;
268 }
269 if( q )
270 {
271 g-=q*d; h-=q*e; i-=q*f; r-=q*o; q=0;
272 }
273 if( r != 1.0 )
274 {
275 g/=r; h/=r; i/=r; r=1;
276 }
277 if( o )
278 {
279 d-=o*g; e-=o*h; f-=o*i; o=0;
280 }
281 if( l )
282 {
283 a-=l*g; b-=l*h; c-=l*i; l=0;
284 }
285
286 map[0][0] = float( a );
287 map[1][0] = float( b );
288 map[2][0] = float( c );
289 map[0][1] = float( d );
290 map[1][1] = float( e );
291 map[2][1] = float( f );
292 Check();
293}
294
301void AOI_Mapping::Move( float dx, float dy )
302{
303 map[2][0] += dx;
304 map[2][1] += dy;
305}
306
314void AOI_Mapping::Rotate( float degreeAngle, float x, float y )
315{
316#if ACPL_MAC
317 float co = cos( degreeAngle * M_PI / 180 ),
318 si = sin( degreeAngle * M_PI / 180 ),
319 rot[] = { co, -si, 0 , si, co, 0, x, y, 1 };
320#else
321 double angle = ( degreeAngle / 180.0 ) * M_PI;
322 float co = float( cos( angle ) ),
323 si = float( sin( angle ) );
324 if( co > -0.0001 && co < 0.0001 )
325 co = 0;
326 else if( co > 0.9999 )
327 co = 1;
328 else if( co < -0.9999 )
329 co = -1;
330 if( si > -0.0001 && si < 0.0001 )
331 si = 0;
332 else if( si > 0.9999 )
333 si = 1;
334 else if( si < -0.9999 )
335 si = -1;
336 float rot[] = { co, -si, 0 , si, co, 0, x, y, 1 };
337#endif
338 AOI_Mapping r( rot );
339 map[2][0] -= x;
340 map[2][1] -= y;
341 Map( r );
342}
343
352void AOI_Mapping::Scale( float x, float y, float sx, float sy )
353{
354 float scal[] = { sx, 0.0f, 0.0f, 0.0f, sy, 0.0f, x, y, 1.0f };
355 AOI_Mapping s( scal );
356 map[2][0] -= x;
357 map[2][1] -= y;
358 Map( s );
359}
360
369void AOI_Mapping::Skew( float x, float y, float sx, float sy )
370{
371 float skew[] = { 1.0f, sy, 0.0f,sx, 1.0f, 0.0f, x, y, 1.0f };
372 AOI_Mapping s( skew );
373 map[2][0] -= x;
374 map[2][1] -= y;
375 Map( s );
376}
377
385{
386 float nieuwe[3][3];
387
388 nieuwe[0][0] = map[0][0] * in.map[0][0] + map[0][1] * in.map[1][0];
389 nieuwe[0][1] = map[0][0] * in.map[0][1] + map[0][1] * in.map[1][1];
390 nieuwe[0][2] = map[0][0] * in.map[0][2] + map[0][1] * in.map[1][2];
391
392 nieuwe[1][0] = map[1][0] * in.map[0][0] + map[1][1] * in.map[1][0];
393 nieuwe[1][1] = map[1][0] * in.map[0][1] + map[1][1] * in.map[1][1];
394 nieuwe[1][2] = map[1][0] * in.map[0][2] + map[1][1] * in.map[1][2];
395
396 nieuwe[2][0] = map[2][0] * in.map[0][0] + map[2][1] * in.map[1][0] + map[2][2] * in.map[2][0];
397 nieuwe[2][1] = map[2][0] * in.map[0][1] + map[2][1] * in.map[1][1] + map[2][2] * in.map[2][1];
398 nieuwe[2][2] = 1;
399
400 ::memcpy( &map,&nieuwe, 9 * sizeof(int32_t) );
401 Check();
402}
403
410{
411 return fabsf(map[0][0] * map[1][1] - map[0][1] * map[1][0]);
412}
413
420{
421 return map[0][0] == 1 && map[0][1] == 0 &&
422 map[1][0] == 0 && map[1][1] == 1 &&
423 map[2][0] == 0 && map[2][1] == 0;
424}
425
432{
433 return map[0][0] == 1 && map[0][1] == 0 &&
434 map[1][0] == 0 && map[1][1] == 1;
435}
436
443{
444 return map[0][1] == 0 && map[1][0] == 0 &&
445 map[2][0] == 0 && map[2][1] == 0;
446}
447
453{
454 for( short i = 0; i<3; i++ )
455 for( short j = 0; j < 3; j++ )
456 if( map[i][j] != 0.0 && fabsf( map[i][j] ) < 0.0000001f )
457 map[i][j] = 0.0;
458}
459
464{
465 x = y = 0;
466}
467
474AOI_Point::AOI_Point( float inX, float inY )
475{
476 x = inX;
477 y = inY;
478}
479
486{
487 x = inCoord.x;
488 y = inCoord.y;
489}
490
498int32_t AOIAPI AOI_ColorSpaceComponents( AOI_ColorSpaceEnum space )
499{
500 return aur::PDF::ColorSpaceComponents( aur::PDF::ColorSpace( space ) );
501}
3x3 matrix
Definition AOI_Types.h:113
void Invert()
float Determinant() const
void Map(const AOI_Mapping &)
void Scale(float, float, float, float)
void Skew(float, float, float, float)
bool IsMove() const
void Rotate(float, float, float)
bool IsUnity() const
void Move(float, float)
bool IsScale() const
Coordinate.
Definition AOI_Types.h:137
Rectangle.
Definition AOI_Types.h:148
bool Overlaps(const AOI_Rectangle &) const
bool Intersect(const AOI_Rectangle &)
Definition AOI_Types.cpp:99
bool CoordInBounds(const AOI_Point &) const
void Union(const AOI_Rectangle &)
Definition AOI_Types.cpp:79
int32_t AOIAPI AOI_ColorSpaceComponents(AOI_ColorSpaceEnum space)