Line data Source code
1 : /* File: geometry_dimensions.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 260 : static inline void geometry_dimensions_init ( geometry_dimensions_t *this_, double width, double height )
9 : {
10 260 : (*this_).width = width;
11 260 : (*this_).height = height;
12 260 : }
13 :
14 1 : static inline void geometry_dimensions_reinit ( geometry_dimensions_t *this_, double width, double height )
15 : {
16 1 : (*this_).width = width;
17 1 : (*this_).height = height;
18 1 : }
19 :
20 1 : static inline void geometry_dimensions_copy ( geometry_dimensions_t *this_, const geometry_dimensions_t *original )
21 : {
22 1 : assert( NULL != original );
23 1 : (*this_) = (*original);
24 1 : }
25 :
26 1 : static inline void geometry_dimensions_replace ( geometry_dimensions_t *this_, const geometry_dimensions_t *original )
27 : {
28 1 : assert( NULL != original );
29 1 : (*this_) = (*original);
30 1 : }
31 :
32 1 : static inline void geometry_dimensions_init_empty ( geometry_dimensions_t *this_ )
33 : {
34 1 : (*this_).width = 0.0;
35 1 : (*this_).height = 0.0;
36 1 : }
37 :
38 1 : static inline void geometry_dimensions_reinit_empty ( geometry_dimensions_t *this_ )
39 : {
40 1 : (*this_).width = 0.0;
41 1 : (*this_).height = 0.0;
42 1 : }
43 :
44 6 : static inline void geometry_dimensions_destroy ( geometry_dimensions_t *this_ )
45 : {
46 6 : }
47 :
48 1763 : static inline double geometry_dimensions_get_width ( const geometry_dimensions_t *this_ )
49 : {
50 1763 : return (*this_).width;
51 : }
52 :
53 595 : static inline double geometry_dimensions_get_height ( const geometry_dimensions_t *this_ )
54 : {
55 595 : return (*this_).height;
56 : }
57 :
58 1 : static inline double geometry_dimensions_get_area ( const geometry_dimensions_t *this_ )
59 : {
60 1 : return (*this_).width * (*this_).height;
61 : }
62 :
63 2 : static inline bool geometry_dimensions_is_empty ( const geometry_dimensions_t *this_ )
64 : {
65 2 : return ( ( (*this_).width < 0.000000001 )||( (*this_).height < 0.000000001 ) );
66 : }
67 :
68 2 : static inline bool geometry_dimensions_can_contain ( const geometry_dimensions_t *this_, const geometry_dimensions_t *that )
69 : {
70 2 : assert( NULL != that );
71 :
72 2 : const bool result
73 2 : = ( (*this_).width + 0.000000001 > (*that).width )&&( (*this_).height + 0.000000001 > (*that).height );
74 :
75 2 : return result;
76 : }
77 :
78 2 : static inline void geometry_dimensions_expand ( geometry_dimensions_t *this_, double delta_width, double delta_height )
79 : {
80 2 : (*this_).width += delta_width;
81 2 : if ( (*this_).width < 0.0 )
82 : {
83 1 : (*this_).width = 0.0;
84 : }
85 :
86 2 : (*this_).height += delta_height;
87 2 : if ( (*this_).height < 0.0 )
88 : {
89 1 : (*this_).height = 0.0;
90 : }
91 2 : }
92 :
93 1 : static inline void geometry_dimensions_trace ( const geometry_dimensions_t *this_ )
94 : {
95 1 : U8_TRACE_INFO( "geometry_dimensions_t" );
96 1 : U8_TRACE_INFO_INT( "- width:", (*this_).width );
97 1 : U8_TRACE_INFO_INT( "- height:", (*this_).height );
98 1 : }
99 :
100 :
101 : /*
102 : Copyright 2019-2025 Andreas Warnke
103 :
104 : Licensed under the Apache License, Version 2.0 (the "License");
105 : you may not use this file except in compliance with the License.
106 : You may obtain a copy of the License at
107 :
108 : http://www.apache.org/licenses/LICENSE-2.0
109 :
110 : Unless required by applicable law or agreed to in writing, software
111 : distributed under the License is distributed on an "AS IS" BASIS,
112 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
113 : See the License for the specific language governing permissions and
114 : limitations under the License.
115 : */
|