| 1 |
/* File: layout_quality.h; Copyright and License: see below */ |
| 2 |
|
| 3 |
#ifndef LAYOUT_QUALITY_H |
| 4 |
#define LAYOUT_QUALITY_H |
| 5 |
|
| 6 |
/* public file for the doxygen documentation: */ |
| 7 |
/*! |
| 8 |
* \file |
| 9 |
* \brief Defines functions to measure the layouting quality of a diagram. |
| 10 |
* |
| 11 |
* This measurement can be performed during layouting to select the best option |
| 12 |
* or afterwards to determine the overall layouting quality. |
| 13 |
*/ |
| 14 |
|
| 15 |
#include "pencil_size.h" |
| 16 |
#include "geometry/geometry_offset.h" |
| 17 |
#include <stdint.h> |
| 18 |
|
| 19 |
/*! |
| 20 |
* \brief attributes of the layout_quality |
| 21 |
* |
| 22 |
* These attributes are needed to determine the layout quality. |
| 23 |
* |
| 24 |
* The methods of layout_quality_t return a debt value that is zero if the layout is perfect, |
| 25 |
* positive if there are unwanted overlaps of objects or other suboptimal characteristics. |
| 26 |
* |
| 27 |
* A debt value is roughly linear to the 2-dimensional area ( width * height ) that is affected. |
| 28 |
* In some less important cases, it is linear to a distance ( which equals a width of 1.0 ). |
| 29 |
* A weight factor ( LAYOUT_QUALITY_WEIGHT_* ) reflects the severity of the layouting defect. |
| 30 |
*/ |
| 31 |
struct layout_quality_struct { |
| 32 |
const pencil_size_t *pencil_size; /*!< the pencil size proposes preferred distances */ |
| 33 |
}; |
| 34 |
|
| 35 |
typedef struct layout_quality_struct layout_quality_t; |
| 36 |
|
| 37 |
/*! |
| 38 |
* \brief initializes the layout_quality_t struct |
| 39 |
* |
| 40 |
* \param this_ pointer to own object attributes |
| 41 |
* \param pencil_size proposal for preferred distances |
| 42 |
*/ |
| 43 |
static inline void layout_quality_init ( layout_quality_t *this_, const pencil_size_t *pencil_size ); |
| 44 |
|
| 45 |
/*! |
| 46 |
* \brief initializes a layout_quality_t struct |
| 47 |
* |
| 48 |
* \param pencil_size proposal for preferred distances |
| 49 |
* \return own object attributes, may be used to initialize a const layout_quality_t |
| 50 |
*/ |
| 51 |
static inline layout_quality_t layout_quality_new ( const pencil_size_t *pencil_size ); |
| 52 |
|
| 53 |
/*! |
| 54 |
* \brief destroys the layout_quality_t struct |
| 55 |
* |
| 56 |
* \param this_ pointer to own object attributes |
| 57 |
*/ |
| 58 |
static inline void layout_quality_destroy ( layout_quality_t *this_ ); |
| 59 |
|
| 60 |
/*! |
| 61 |
* \brief determines the quality debts for drawing the visible classifier to the diagram |
| 62 |
* |
| 63 |
* \param this_ pointer to own object attributes |
| 64 |
* \param probe a completely layouted visible classifier |
| 65 |
* \param order_target the delta from order-based location to the current classifiers location |
| 66 |
* \param other the diagram to which to draw to |
| 67 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 68 |
*/ |
| 69 |
static inline double layout_quality_debts_class_diag ( const layout_quality_t *this_, |
| 70 |
const layout_visible_classifier_t *probe, |
| 71 |
const geometry_offset_t *order_target, |
| 72 |
const layout_diagram_t *other |
| 73 |
); |
| 74 |
|
| 75 |
/*! |
| 76 |
* \brief determines the quality debts for drawing both visible classifiers |
| 77 |
* |
| 78 |
* \param this_ pointer to own object attributes |
| 79 |
* \param probe a completely layouted visible classifier |
| 80 |
* \param other another completely layouted visible classifier |
| 81 |
* \param layout_data the visible set allows to determine if probe is parent or child of other |
| 82 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 83 |
*/ |
| 84 |
static inline double layout_quality_debts_class_class ( const layout_quality_t *this_, |
| 85 |
const layout_visible_classifier_t *probe, |
| 86 |
const layout_visible_classifier_t *other, |
| 87 |
const layout_visible_set_t *layout_data |
| 88 |
); |
| 89 |
|
| 90 |
/*! |
| 91 |
* \brief determines the quality debts for drawing the connector of a relationship to the diagram |
| 92 |
* |
| 93 |
* This function considers the coordinates of the diagram and the ones of the relationship. |
| 94 |
* |
| 95 |
* \param this_ pointer to own object attributes |
| 96 |
* \param probe a partly layouted relationship |
| 97 |
* \param source_rect the rectangle from which the connector shall start |
| 98 |
* \param dest_rect the rectangle at which the connector shall end |
| 99 |
* \param other the diagram to which to draw to |
| 100 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 101 |
*/ |
| 102 |
static inline double layout_quality_debts_conn_diag ( const layout_quality_t *this_, |
| 103 |
const geometry_connector_t *probe, |
| 104 |
const geometry_rectangle_t *source_rect, |
| 105 |
const geometry_rectangle_t *dest_rect, |
| 106 |
const layout_diagram_t *other |
| 107 |
); |
| 108 |
|
| 109 |
/*! |
| 110 |
* \brief determines the quality debts for drawing the connector of a relationship and the visible classifier |
| 111 |
* |
| 112 |
* \param this_ pointer to own object attributes |
| 113 |
* \param probe a partly layouted relationship |
| 114 |
* \param other a completely layouted visible classifier |
| 115 |
* \param is_source other is the probe's source end (from) |
| 116 |
* \param is_ancestor_of_source other is an ancestor of the probe's source end (from) |
| 117 |
* \param is_destination other is the probe's destination end (to) |
| 118 |
* \param is_ancestor_of_destination other is an ancestor of the probe's destination end (to) |
| 119 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 120 |
*/ |
| 121 |
static inline double layout_quality_debts_conn_class ( const layout_quality_t *this_, |
| 122 |
const geometry_connector_t *probe, |
| 123 |
const layout_visible_classifier_t *other, |
| 124 |
bool is_source, |
| 125 |
bool is_ancestor_of_source, |
| 126 |
bool is_destination, |
| 127 |
bool is_ancestor_of_destination |
| 128 |
); |
| 129 |
|
| 130 |
/*! |
| 131 |
* \brief determines the quality debts for drawing the connector of a relationship and the symbol box of a feature |
| 132 |
* |
| 133 |
* \param this_ pointer to own object attributes |
| 134 |
* \param probe a partly layouted relationship |
| 135 |
* \param other a partly layouted feature |
| 136 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 137 |
*/ |
| 138 |
static inline double layout_quality_debts_conn_sym ( const layout_quality_t *this_, |
| 139 |
const geometry_connector_t *probe, |
| 140 |
const geometry_rectangle_t *other |
| 141 |
); |
| 142 |
|
| 143 |
/*! |
| 144 |
* \brief determines the quality debts for drawing both connectors of relationships |
| 145 |
* |
| 146 |
* \param this_ pointer to own object attributes |
| 147 |
* \param probe a partly layouted relationship |
| 148 |
* \param other another partly layouted relationship |
| 149 |
* \param same_type true if probe and other have the same relationship type |
| 150 |
* \param same_source true if probe and other have the same source end (from) |
| 151 |
* \param same_destination true if probe and other have the same destination end (to) |
| 152 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 153 |
*/ |
| 154 |
static inline double layout_quality_debts_conn_conn ( const layout_quality_t *this_, |
| 155 |
const geometry_connector_t *probe, |
| 156 |
const geometry_connector_t *other, |
| 157 |
bool same_type, |
| 158 |
bool same_source, |
| 159 |
bool same_destination |
| 160 |
); |
| 161 |
|
| 162 |
/*! |
| 163 |
* \brief determines the quality debts for drawing the label to the diagram |
| 164 |
* |
| 165 |
* \param this_ pointer to own object attributes |
| 166 |
* \param probe a partly layouted feature or relationship |
| 167 |
* \param target_point the point where the object is located that the label refers to |
| 168 |
* \param other the diagram to which to draw to |
| 169 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 170 |
*/ |
| 171 |
static inline double layout_quality_debts_label_diag ( const layout_quality_t *this_, |
| 172 |
const geometry_rectangle_t *probe, |
| 173 |
const geometry_point_t *target_point, |
| 174 |
const layout_diagram_t *other |
| 175 |
); |
| 176 |
|
| 177 |
/*! |
| 178 |
* \brief determines the quality debts for drawing the label and the visible classifier |
| 179 |
* |
| 180 |
* \param this_ pointer to own object attributes |
| 181 |
* \param probe a partly layouted feature or relationship |
| 182 |
* \param other a completely layouted visible classifier |
| 183 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 184 |
*/ |
| 185 |
static inline double layout_quality_debts_label_class ( const layout_quality_t *this_, |
| 186 |
const geometry_rectangle_t *probe, |
| 187 |
const layout_visible_classifier_t *other |
| 188 |
); |
| 189 |
|
| 190 |
/*! |
| 191 |
* \brief determines the quality debts for drawing the label and the feature |
| 192 |
* |
| 193 |
* \param this_ pointer to own object attributes |
| 194 |
* \param probe a partly layouted feature or relationship |
| 195 |
* \param other a completely layouted feature |
| 196 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 197 |
*/ |
| 198 |
static inline double layout_quality_debts_label_feat ( const layout_quality_t *this_, |
| 199 |
const geometry_rectangle_t *probe, |
| 200 |
const layout_feature_t *other |
| 201 |
); |
| 202 |
|
| 203 |
/*! |
| 204 |
* \brief determines the quality debts for drawing the label and the relationship |
| 205 |
* |
| 206 |
* \param this_ pointer to own object attributes |
| 207 |
* \param probe a partly layouted feature or relationship |
| 208 |
* \param other a completely layouted relationship |
| 209 |
* \return 0.0 if there are no overlaps, a positive value otherwise |
| 210 |
*/ |
| 211 |
static inline double layout_quality_debts_label_rel ( const layout_quality_t *this_, |
| 212 |
const geometry_rectangle_t *probe, |
| 213 |
const layout_relationship_t *other |
| 214 |
); |
| 215 |
|
| 216 |
|
| 217 |
#include "layout_quality.inl" |
| 218 |
|
| 219 |
#endif /* LAYOUT_QUALITY_H */ |
| 220 |
|
| 221 |
|
| 222 |
/* |
| 223 |
Copyright 2025-2026 Andreas Warnke |
| 224 |
|
| 225 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 226 |
you may not use this file except in compliance with the License. |
| 227 |
You may obtain a copy of the License at |
| 228 |
|
| 229 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 230 |
|
| 231 |
Unless required by applicable law or agreed to in writing, software |
| 232 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 233 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 234 |
See the License for the specific language governing permissions and |
| 235 |
limitations under the License. |
| 236 |
*/ |