| 1 |
/* File: geometry_anchor.h; Copyright and License: see below */ |
| 2 |
|
| 3 |
#ifndef GEOMETRY_ANCHOR_H |
| 4 |
#define GEOMETRY_ANCHOR_H |
| 5 |
|
| 6 |
/* public file for the doxygen documentation: */ |
| 7 |
/*! |
| 8 |
* \file |
| 9 |
* \brief Stores the coordinates of a reference point and an x/y alignment instruction |
| 10 |
* |
| 11 |
* This structure allows to layout a geometric object |
| 12 |
* by providing an anchor point and the information how the object |
| 13 |
* shall be aligned relative to this anchor point |
| 14 |
*/ |
| 15 |
|
| 16 |
#include "geometry/geometry_rectangle.h" |
| 17 |
#include "geometry/geometry_dimensions.h" |
| 18 |
#include "geometry/geometry_point.h" |
| 19 |
#include "geometry/geometry_h_align.h" |
| 20 |
#include "geometry/geometry_v_align.h" |
| 21 |
#include <stdbool.h> |
| 22 |
|
| 23 |
/*! |
| 24 |
* \brief attributes of an anchor |
| 25 |
*/ |
| 26 |
struct geometry_anchor_struct { |
| 27 |
geometry_point_t reference_point; |
| 28 |
geometry_h_align_t x_align; /*!< align the objects left or right to the reference point */ |
| 29 |
geometry_v_align_t y_align; /*!< align the objects top or bottmo to the reference point */ |
| 30 |
}; |
| 31 |
|
| 32 |
typedef struct geometry_anchor_struct geometry_anchor_t; |
| 33 |
|
| 34 |
/*! |
| 35 |
* \brief initializes the geometry_anchor_t struct |
| 36 |
* |
| 37 |
* \param this_ pointer to own object attributes |
| 38 |
* \param x x coordinate of the reference point |
| 39 |
* \param y y coordinate of the reference point |
| 40 |
* \param x_align horizontal alignment relative to the reference point |
| 41 |
* \param y_align vertical alignment relative to the reference point |
| 42 |
*/ |
| 43 |
static inline void geometry_anchor_init ( geometry_anchor_t *this_, |
| 44 |
double x, |
| 45 |
double y, |
| 46 |
geometry_h_align_t x_align, |
| 47 |
geometry_v_align_t y_align |
| 48 |
); |
| 49 |
|
| 50 |
/*! |
| 51 |
* \brief copies original to this uninitialized geometry_anchor_t struct |
| 52 |
* |
| 53 |
* \param this_ pointer to own object attributes |
| 54 |
* \param original pointer to object attributes that shall be copied |
| 55 |
*/ |
| 56 |
static inline void geometry_anchor_copy ( geometry_anchor_t *this_, const geometry_anchor_t *original ); |
| 57 |
|
| 58 |
/*! |
| 59 |
* \brief replaces the already initialized geometry_anchor_t struct by other data |
| 60 |
* |
| 61 |
* \param this_ pointer to own object attributes |
| 62 |
* \param original pointer to object attributes that shall be copied |
| 63 |
*/ |
| 64 |
static inline void geometry_anchor_replace ( geometry_anchor_t *this_, const geometry_anchor_t *original ); |
| 65 |
|
| 66 |
/*! |
| 67 |
* \brief destroys the geometry_anchor_t struct |
| 68 |
* |
| 69 |
* \param this_ pointer to own object attributes |
| 70 |
*/ |
| 71 |
static inline void geometry_anchor_destroy ( geometry_anchor_t *this_ ); |
| 72 |
|
| 73 |
/*! |
| 74 |
* \brief gets the x coordinate of geometry_anchor_t |
| 75 |
* |
| 76 |
* \param this_ pointer to own object attributes |
| 77 |
*/ |
| 78 |
static inline double geometry_anchor_get_x ( const geometry_anchor_t *this_ ); |
| 79 |
|
| 80 |
/*! |
| 81 |
* \brief gets the y coordinate of geometry_anchor_t |
| 82 |
* |
| 83 |
* \param this_ pointer to own object attributes |
| 84 |
*/ |
| 85 |
static inline double geometry_anchor_get_y ( const geometry_anchor_t *this_ ); |
| 86 |
|
| 87 |
/*! |
| 88 |
* \brief gets the reference point of geometry_anchor_t |
| 89 |
* |
| 90 |
* \param this_ pointer to own object attributes |
| 91 |
* \return the reference point |
| 92 |
*/ |
| 93 |
static inline const geometry_point_t * geometry_anchor_get_point_const ( const geometry_anchor_t *this_ ); |
| 94 |
|
| 95 |
/*! |
| 96 |
* \brief gets the horizontal alignment of geometry_anchor_t |
| 97 |
* |
| 98 |
* \param this_ pointer to own object attributes |
| 99 |
*/ |
| 100 |
static inline geometry_h_align_t geometry_anchor_get_x_align ( const geometry_anchor_t *this_ ); |
| 101 |
|
| 102 |
/*! |
| 103 |
* \brief gets the vertical alignment coordinate of geometry_anchor_t |
| 104 |
* |
| 105 |
* \param this_ pointer to own object attributes |
| 106 |
*/ |
| 107 |
static inline geometry_v_align_t geometry_anchor_get_y_align ( const geometry_anchor_t *this_ ); |
| 108 |
|
| 109 |
/*! |
| 110 |
* \brief aligns a rectangle to geometry_anchor_t |
| 111 |
* |
| 112 |
* \param this_ pointer to own object attributes |
| 113 |
* \param unaligned geometry_rectangle to be aligned to this_ anchor |
| 114 |
* \return geometry_rectangle aligned to anchor |
| 115 |
*/ |
| 116 |
static inline geometry_rectangle_t geometry_anchor_align_rect ( const geometry_anchor_t *this_, |
| 117 |
const geometry_rectangle_t *unaligned |
| 118 |
); |
| 119 |
|
| 120 |
/*! |
| 121 |
* \brief aligns a dimension to coordinate of geometry_anchor_t |
| 122 |
* |
| 123 |
* \param this_ pointer to own object attributes |
| 124 |
* \param unaligned geometry_dimensions to be aligned to this_ anchor |
| 125 |
* \return geometry_rectangle aligned to anchor |
| 126 |
*/ |
| 127 |
static inline geometry_rectangle_t geometry_anchor_align_dim ( const geometry_anchor_t *this_, |
| 128 |
const geometry_dimensions_t *unaligned |
| 129 |
); |
| 130 |
|
| 131 |
/*! |
| 132 |
* \brief aligns a dimension to coordinate of geometry_anchor_t but biased by preferred_location if centering |
| 133 |
* |
| 134 |
* \param this_ pointer to own object attributes |
| 135 |
* \param unaligned geometry_dimensions to be aligned to this_ anchor |
| 136 |
* \param preferred_location geometry_rectangle within which the result may be located if possible |
| 137 |
* \return geometry_rectangle aligned to anchor |
| 138 |
*/ |
| 139 |
static inline geometry_rectangle_t geometry_anchor_align_biased_dim ( const geometry_anchor_t *this_, |
| 140 |
const geometry_dimensions_t *unaligned, |
| 141 |
const geometry_rectangle_t *preferred_location |
| 142 |
); |
| 143 |
|
| 144 |
/*! |
| 145 |
* \brief prints the geometry_anchor_t struct to the trace output |
| 146 |
* |
| 147 |
* \param this_ pointer to own object attributes |
| 148 |
*/ |
| 149 |
static inline void geometry_anchor_trace ( const geometry_anchor_t *this_ ); |
| 150 |
|
| 151 |
#include "geometry/geometry_anchor.inl" |
| 152 |
|
| 153 |
#endif /* GEOMETRY_ANCHOR_H */ |
| 154 |
|
| 155 |
|
| 156 |
/* |
| 157 |
Copyright 2021-2026 Andreas Warnke |
| 158 |
|
| 159 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 160 |
you may not use this file except in compliance with the License. |
| 161 |
You may obtain a copy of the License at |
| 162 |
|
| 163 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 164 |
|
| 165 |
Unless required by applicable law or agreed to in writing, software |
| 166 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 167 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 168 |
See the License for the specific language governing permissions and |
| 169 |
limitations under the License. |
| 170 |
*/ |