| 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 |
static inline void geometry_dimensions_init ( geometry_dimensions_t *this_, double width, double height ) |
| 9 |
{ |
| 10 |
(*this_).width = width; |
| 11 |
(*this_).height = height; |
| 12 |
} |
| 13 |
|
| 14 |
static inline void geometry_dimensions_reinit ( geometry_dimensions_t *this_, double width, double height ) |
| 15 |
{ |
| 16 |
(*this_).width = width; |
| 17 |
(*this_).height = height; |
| 18 |
} |
| 19 |
|
| 20 |
static inline void geometry_dimensions_copy ( geometry_dimensions_t *this_, const geometry_dimensions_t *original ) |
| 21 |
{ |
| 22 |
assert( NULL != original ); |
| 23 |
(*this_) = (*original); |
| 24 |
} |
| 25 |
|
| 26 |
static inline void geometry_dimensions_replace ( geometry_dimensions_t *this_, const geometry_dimensions_t *original ) |
| 27 |
{ |
| 28 |
assert( NULL != original ); |
| 29 |
(*this_) = (*original); |
| 30 |
} |
| 31 |
|
| 32 |
static inline void geometry_dimensions_init_empty ( geometry_dimensions_t *this_ ) |
| 33 |
{ |
| 34 |
(*this_).width = 0.0; |
| 35 |
(*this_).height = 0.0; |
| 36 |
} |
| 37 |
|
| 38 |
static inline void geometry_dimensions_reinit_empty ( geometry_dimensions_t *this_ ) |
| 39 |
{ |
| 40 |
(*this_).width = 0.0; |
| 41 |
(*this_).height = 0.0; |
| 42 |
} |
| 43 |
|
| 44 |
static inline void geometry_dimensions_destroy ( geometry_dimensions_t *this_ ) |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
static inline double geometry_dimensions_get_width ( const geometry_dimensions_t *this_ ) |
| 49 |
{ |
| 50 |
return (*this_).width; |
| 51 |
} |
| 52 |
|
| 53 |
static inline double geometry_dimensions_get_height ( const geometry_dimensions_t *this_ ) |
| 54 |
{ |
| 55 |
return (*this_).height; |
| 56 |
} |
| 57 |
|
| 58 |
static inline double geometry_dimensions_get_area ( const geometry_dimensions_t *this_ ) |
| 59 |
{ |
| 60 |
return (*this_).width * (*this_).height; |
| 61 |
} |
| 62 |
|
| 63 |
static inline bool geometry_dimensions_is_empty ( const geometry_dimensions_t *this_ ) |
| 64 |
{ |
| 65 |
return ( ( (*this_).width < 0.000000001 )||( (*this_).height < 0.000000001 ) ); |
| 66 |
} |
| 67 |
|
| 68 |
static inline bool geometry_dimensions_can_contain ( const geometry_dimensions_t *this_, const geometry_dimensions_t *that ) |
| 69 |
{ |
| 70 |
assert( NULL != that ); |
| 71 |
|
| 72 |
const bool result |
| 73 |
= ( (*this_).width + 0.000000001 > (*that).width )&&( (*this_).height + 0.000000001 > (*that).height ); |
| 74 |
|
| 75 |
return result; |
| 76 |
} |
| 77 |
|
| 78 |
static inline void geometry_dimensions_expand ( geometry_dimensions_t *this_, double delta_width, double delta_height ) |
| 79 |
{ |
| 80 |
(*this_).width += delta_width; |
| 81 |
if ( (*this_).width < 0.0 ) |
| 82 |
{ |
| 83 |
(*this_).width = 0.0; |
| 84 |
} |
| 85 |
|
| 86 |
(*this_).height += delta_height; |
| 87 |
if ( (*this_).height < 0.0 ) |
| 88 |
{ |
| 89 |
(*this_).height = 0.0; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
static inline void geometry_dimensions_trace ( const geometry_dimensions_t *this_ ) |
| 94 |
{ |
| 95 |
U8_TRACE_INFO( "geometry_dimensions_t" ); |
| 96 |
U8_TRACE_INFO_INT( "- width:", (*this_).width ); |
| 97 |
U8_TRACE_INFO_INT( "- height:", (*this_).height ); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
/* |
| 102 |
Copyright 2019-2026 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 |
*/ |