Debian Codegraph @

pencil/include/geometry/geometry_offset.inl

raw
1 /* File: geometry_offset.inl; Copyright and License: see below */
2
3 #include "u8/u8_trace.h"
4 #include "u8/u8_log.h"
5 #include <assert.h>
6 #include <math.h>
7
8 static inline void geometry_offset_init ( geometry_offset_t *this_, double dx, double dy )
9 {
10 (*this_).dx = dx;
11 (*this_).dy = dy;
12 }
13
14 static inline geometry_offset_t geometry_offset_new ( double dx, double dy )
15 {
16 geometry_offset_t result;
17 geometry_offset_init( &result, dx, dy );
18 return result;
19 }
20
21 static inline void geometry_offset_reinit ( geometry_offset_t *this_, double dx, double dy )
22 {
23 (*this_).dx = dx;
24 (*this_).dy = dy;
25 }
26
27 static inline void geometry_offset_copy ( geometry_offset_t *this_, const geometry_offset_t *original )
28 {
29 assert( NULL != original );
30 (*this_) = (*original);
31 }
32
33 static inline void geometry_offset_replace ( geometry_offset_t *this_, const geometry_offset_t *original )
34 {
35 assert( NULL != original );
36 (*this_) = (*original);
37 }
38
39 static inline void geometry_offset_destroy ( geometry_offset_t *this_ )
40 {
41 }
42
43 static inline double geometry_offset_get_dx ( const geometry_offset_t *this_ )
44 {
45 return (*this_).dx;
46 }
47
48 static inline double geometry_offset_get_dy ( const geometry_offset_t *this_ )
49 {
50 return (*this_).dy;
51 }
52
53 static inline bool geometry_offset_equals ( const geometry_offset_t *this_, const geometry_offset_t *that )
54 {
55 assert( NULL != that );
56 return ( ( fabs( (*this_).dx - (*that).dx ) + fabs( (*this_).dy - (*that).dy ) ) < 0.000000001 );
57 }
58
59 static inline geometry_direction_t geometry_offset_get_direction ( const geometry_offset_t *this_ )
60 {
61 geometry_direction_t result;
62 if ( (*this_).dx > 0.000000001 )
63 {
64 if ( (*this_).dy > 0.000000001 )
65 {
66 result = GEOMETRY_DIRECTION_DOWN_RIGHT;
67 }
68 else if ( (*this_).dy < -0.000000001 )
69 {
70 result = GEOMETRY_DIRECTION_UP_RIGHT;
71 }
72 else
73 {
74 result = GEOMETRY_DIRECTION_RIGHT;
75 }
76 }
77 else if ( (*this_).dx < -0.000000001 )
78 {
79 if ( (*this_).dy > 0.000000001 )
80 {
81 result = GEOMETRY_DIRECTION_DOWN_LEFT;
82 }
83 else if ( (*this_).dy < -0.000000001 )
84 {
85 result = GEOMETRY_DIRECTION_UP_LEFT;
86 }
87 else
88 {
89 result = GEOMETRY_DIRECTION_LEFT;
90 }
91 }
92 else
93 {
94 if ( (*this_).dy > 0.000000001 )
95 {
96 result = GEOMETRY_DIRECTION_DOWN;
97 }
98 else if ( (*this_).dy < -0.000000001 )
99 {
100 result = GEOMETRY_DIRECTION_UP;
101 }
102 else
103 {
104 result = GEOMETRY_DIRECTION_CENTER;
105 }
106 }
107 return result;
108 }
109
110 static inline void geometry_offset_trace ( const geometry_offset_t *this_ )
111 {
112 U8_TRACE_INFO( "geometry_offset_t" );
113 U8_TRACE_INFO_INT( "- dx:", (*this_).dx );
114 U8_TRACE_INFO_INT( "- dy:", (*this_).dy );
115 }
116
117
118 /*
119 Copyright 2025-2026 Andreas Warnke
120
121 Licensed under the Apache License, Version 2.0 (the "License");
122 you may not use this file except in compliance with the License.
123 You may obtain a copy of the License at
124
125 http://www.apache.org/licenses/LICENSE-2.0
126
127 Unless required by applicable law or agreed to in writing, software
128 distributed under the License is distributed on an "AS IS" BASIS,
129 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130 See the License for the specific language governing permissions and
131 limitations under the License.
132 */