Debian Codegraph @

pencil/include/geometry/geometry_point.inl

raw
1 /* File: geometry_point.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_point_init ( geometry_point_t *this_, double x, double y )
9 {
10 (*this_).x = x;
11 (*this_).y = y;
12 }
13
14 static inline geometry_point_t geometry_point_new ( double x, double y )
15 {
16 geometry_point_t result;
17 geometry_point_init( &result, x, y );
18 return result;
19 }
20
21 static inline void geometry_point_reinit ( geometry_point_t *this_, double x, double y )
22 {
23 (*this_).x = x;
24 (*this_).y = y;
25 }
26
27 static inline void geometry_point_copy ( geometry_point_t *this_, const geometry_point_t *original )
28 {
29 assert( NULL != original );
30 (*this_) = (*original);
31 }
32
33 static inline void geometry_point_replace ( geometry_point_t *this_, const geometry_point_t *original )
34 {
35 assert( NULL != original );
36 (*this_) = (*original);
37 }
38
39 static inline void geometry_point_destroy ( geometry_point_t *this_ )
40 {
41 }
42
43 static inline double geometry_point_get_x ( const geometry_point_t *this_ )
44 {
45 return (*this_).x;
46 }
47
48 static inline double geometry_point_get_y ( const geometry_point_t *this_ )
49 {
50 return (*this_).y;
51 }
52
53 static inline double geometry_point_calc_chess_distance ( const geometry_point_t *this_, const geometry_point_t *that )
54 {
55 assert( NULL != that );
56 return ( fabs( (*this_).x - (*that).x ) + fabs( (*this_).y - (*that).y ) );
57 }
58
59 static inline bool geometry_point_equals ( const geometry_point_t *this_, const geometry_point_t *that )
60 {
61 assert( NULL != that );
62 return ( ( fabs( (*this_).x - (*that).x ) + fabs( (*this_).y - (*that).y ) ) < 0.000000001 );
63 }
64
65 static inline void geometry_point_shift ( geometry_point_t *this_, double delta_x, double delta_y )
66 {
67 (*this_).x += delta_x;
68 (*this_).y += delta_y;
69 }
70
71 static inline void geometry_point_trace ( const geometry_point_t *this_ )
72 {
73 U8_TRACE_INFO( "geometry_point_t" );
74 U8_TRACE_INFO_INT( "- x:", (*this_).x );
75 U8_TRACE_INFO_INT( "- y:", (*this_).y );
76 }
77
78
79 /*
80 Copyright 2019-2026 Andreas Warnke
81
82 Licensed under the Apache License, Version 2.0 (the "License");
83 you may not use this file except in compliance with the License.
84 You may obtain a copy of the License at
85
86 http://www.apache.org/licenses/LICENSE-2.0
87
88 Unless required by applicable law or agreed to in writing, software
89 distributed under the License is distributed on an "AS IS" BASIS,
90 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
91 See the License for the specific language governing permissions and
92 limitations under the License.
93 */