Debian Codegraph @

pencil/test/test_data/test_data_evaluation.c

raw
1 /* File: test_data_evaluation.c; Copyright and License: see below */
2
3 #include "test_data/test_data_evaluation.h"
4 #include "filter/pencil_rules.h"
5 #include "u8/u8_trace.h"
6 #include "u8/u8_log.h"
7 #include <assert.h>
8
9 void test_data_evaluation_init( test_data_evaluation_t *this_ )
10 {
11 U8_TRACE_BEGIN();
12
13 data_rules_init ( &((*this_).filter_rules) );
14
15 U8_TRACE_END();
16 }
17
18 void test_data_evaluation_destroy( test_data_evaluation_t *this_ )
19 {
20 U8_TRACE_BEGIN();
21 U8_TRACE_END();
22 }
23
24 void test_data_evaluation_analyze( const test_data_evaluation_t *this_,
25 const layout_visible_set_t *input_layout,
26 data_stat_t *io_layout_stat,
27 void (*overlap_callback)(void *data, const geometry_rectangle_t *a, const geometry_rectangle_t *b),
28 void *data )
29 {
30 U8_TRACE_BEGIN();
31 assert( input_layout != NULL );
32 assert( (*input_layout).visible_classifier_count <= LAYOUT_VISIBLE_SET_MAX_CLASSIFIERS );
33 assert( (*input_layout).feature_count <= LAYOUT_VISIBLE_SET_MAX_FEATURES );
34 assert( (*input_layout).relationship_count <= LAYOUT_VISIBLE_SET_MAX_RELATIONSHIPS );
35 assert( io_layout_stat != NULL );
36 pencil_rules_t pencil_rules;
37 pencil_rules_init( &pencil_rules );
38
39 /* check if diagram is valid */
40
41 if ( (*input_layout).diagram_valid )
42 {
43 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAM, DATA_STAT_SERIES_EXPORTED );
44
45 const geometry_rectangle_t *const diag_bounds = layout_diagram_get_bounds_const( &((*input_layout).diagram_layout) );
46 const geometry_rectangle_t *const diag_space = layout_diagram_get_draw_area_const( &((*input_layout).diagram_layout) );
47 const data_diagram_t *const diag_data = layout_diagram_get_data_const ( &((*input_layout).diagram_layout) );
48 const data_diagram_type_t diag_type = data_diagram_get_diagram_type ( diag_data );
49
50 /* check classifiers against diagram */
51
52 for ( uint_fast32_t c_idx = 0; c_idx < (*input_layout).visible_classifier_count; c_idx ++ )
53 {
54 const layout_visible_classifier_t *const classifier = &((*input_layout).visible_classifier_layout[c_idx]);
55
56 const geometry_rectangle_t *const c_symbox = layout_visible_classifier_get_symbol_box_const( classifier );
57 const geometry_rectangle_t *const c_label = layout_visible_classifier_get_label_box_const( classifier );
58 const geometry_rectangle_t *const c_space = layout_visible_classifier_get_space_const( classifier );
59 const geometry_rectangle_t *const c_icon = layout_visible_classifier_get_icon_box_const( classifier );
60
61 if ( geometry_rectangle_is_containing( diag_space, c_symbox )
62 && geometry_rectangle_is_containing( diag_space, c_label )
63 && geometry_rectangle_is_containing( diag_space, c_icon ) )
64 {
65 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAMELEMENT, DATA_STAT_SERIES_EXPORTED );
66
67 /* check current classifier against already processed classifiers */
68
69 for ( uint_fast32_t probe_idx = 0; probe_idx < c_idx; probe_idx ++ )
70 {
71 const layout_visible_classifier_t *const probe
72 = &((*input_layout).visible_classifier_layout[probe_idx]);
73
74 const geometry_rectangle_t *const probe_symbox
75 = layout_visible_classifier_get_symbol_box_const( probe );
76 const geometry_rectangle_t *const probe_label
77 = layout_visible_classifier_get_label_box_const( probe );
78 const geometry_rectangle_t *const probe_space
79 = layout_visible_classifier_get_space_const( probe );
80 const geometry_rectangle_t *const probe_icon
81 = layout_visible_classifier_get_icon_box_const( probe );
82
83 const bool symbox_overlaps
84 = geometry_rectangle_is_intersecting( c_symbox, probe_symbox );
85 const bool label_or_icon_overlaps
86 = geometry_rectangle_is_intersecting( c_label, probe_label )
87 || geometry_rectangle_is_intersecting( c_icon, probe_label )
88 || geometry_rectangle_is_intersecting( c_label, probe_icon )
89 || geometry_rectangle_is_intersecting( c_icon, probe_icon );
90 const bool mixed_overlaps
91 = ( geometry_rectangle_is_intersecting( c_symbox, probe_label )
92 || geometry_rectangle_is_intersecting( c_symbox, probe_icon )
93 || geometry_rectangle_is_intersecting( c_label, probe_symbox )
94 || geometry_rectangle_is_intersecting( c_icon, probe_symbox ) );
95
96 if ( symbox_overlaps || mixed_overlaps || label_or_icon_overlaps )
97 {
98 const bool probe_is_ancestor
99 = layout_visible_set_is_ancestor( input_layout,
100 probe, /* ancestor */
101 classifier /* descendant */
102 );
103 const bool probe_is_descendant
104 = layout_visible_set_is_ancestor( input_layout,
105 classifier, /* ancestor */
106 probe /* descendant */
107 );
108 const bool probe_contains_c
109 = ( geometry_rectangle_is_containing( probe_space, c_symbox )
110 && geometry_rectangle_is_containing( probe_space, c_label )
111 && geometry_rectangle_is_containing( probe_space, c_icon ) );
112 const bool c_contains_probe
113 = ( geometry_rectangle_is_containing( c_space, probe_symbox )
114 && geometry_rectangle_is_containing( c_space, probe_label )
115 && geometry_rectangle_is_containing( c_space, probe_icon ) );
116 if ( probe_is_ancestor && probe_contains_c )
117 {
118 /* ok */
119 }
120 else if ( probe_is_descendant && c_contains_probe )
121 {
122 /* ok */
123 }
124 else
125 {
126 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAMELEMENT, DATA_STAT_SERIES_WARNING );
127 (*overlap_callback)( data, probe_symbox, c_symbox );
128 (*overlap_callback)( data, probe_symbox, c_label );
129 (*overlap_callback)( data, probe_symbox, c_icon );
130 (*overlap_callback)( data, probe_label, c_symbox );
131 (*overlap_callback)( data, probe_label, c_label );
132 (*overlap_callback)( data, probe_label, c_icon );
133 (*overlap_callback)( data, probe_icon, c_symbox );
134 (*overlap_callback)( data, probe_icon, c_label );
135 (*overlap_callback)( data, probe_icon, c_icon );
136 }
137 }
138 }
139
140 }
141 else if ( geometry_rectangle_is_containing( diag_bounds, c_symbox )
142 && geometry_rectangle_is_containing( diag_bounds, c_label ) )
143 {
144 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAMELEMENT, DATA_STAT_SERIES_EXPORTED );
145 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAMELEMENT, DATA_STAT_SERIES_WARNING );
146 (*overlap_callback)( data, diag_bounds, c_symbox );
147 (*overlap_callback)( data, diag_bounds, c_label );
148 (*overlap_callback)( data, diag_bounds, c_icon );
149 }
150 else
151 {
152 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAMELEMENT, DATA_STAT_SERIES_ERROR );
153 (*overlap_callback)( data, diag_space, diag_space );
154 }
155
156 }
157
158 /* check features against diagram */
159
160 for ( uint_fast32_t f_idx = 0; f_idx < (*input_layout).feature_count; f_idx ++ )
161 {
162 const layout_feature_t *const feature = &((*input_layout).feature_layout[f_idx]);
163 const data_feature_t *const feature_data = layout_feature_get_data_const( feature );
164 const data_feature_type_t feature_type = data_feature_get_main_type( feature_data );
165 const data_row_t feature_id = layout_feature_get_feature_id( feature );
166 const bool feature_visible
167 = data_rules_diagram_shows_feature( &((*input_layout).filter_rules),
168 (*input_layout).input_data,
169 feature_id
170 );
171 const data_stat_table_t feat_or_lifeline
172 = ( feature_type == DATA_FEATURE_TYPE_LIFELINE ) ? DATA_STAT_TABLE_LIFELINE : DATA_STAT_TABLE_FEATURE;
173
174 const geometry_rectangle_t *const f_symbox = layout_feature_get_symbol_box_const( feature );
175 const geometry_rectangle_t *const f_label = layout_feature_get_label_box_const( feature );
176
177 if ( ! feature_visible )
178 {
179 /* nothing to do, feature is not visible in this diagram */
180 }
181 else if ( ( geometry_rectangle_is_empty( f_symbox )
182 || geometry_rectangle_is_containing( diag_space, f_symbox ))
183 && geometry_rectangle_is_containing( diag_space, f_label ) )
184 {
185 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_EXPORTED );
186
187 /* check features against classifiers */
188
189 for ( uint_fast32_t probe_idx = 0; probe_idx < (*input_layout).visible_classifier_count; probe_idx ++ )
190 {
191 const layout_visible_classifier_t *const probe = &((*input_layout).visible_classifier_layout[probe_idx]);
192 const data_classifier_t *const probe_data = layout_visible_classifier_get_classifier_const( probe );
193 const data_classifier_type_t probe_type = data_classifier_get_main_type( probe_data );
194 /* determine if this probe classifier shall be drawn in the same rectangle as the lifeline */
195 const bool feature_is_proxy_for_probe
196 = pencil_rules_feature_is_implicit_proxy( &pencil_rules, feature_type, probe_type, diag_type );
197
198 const geometry_rectangle_t *const probe_symbox
199 = layout_visible_classifier_get_symbol_box_const( probe );
200 const geometry_rectangle_t *const probe_label
201 = layout_visible_classifier_get_label_box_const( probe );
202 const geometry_rectangle_t *const probe_space
203 = layout_visible_classifier_get_space_const( probe );
204 const geometry_rectangle_t *const probe_icon
205 = layout_visible_classifier_get_icon_box_const( probe );
206
207 const bool symbox_overlaps
208 = geometry_rectangle_is_intersecting( f_symbox, probe_symbox )
209 && ( ! geometry_rectangle_is_containing( probe_space, f_symbox ) );
210 const bool f_sym_overlaps_c_label
211 = geometry_rectangle_is_intersecting( f_symbox, probe_label )
212 || geometry_rectangle_is_intersecting( f_symbox, probe_icon );
213 const bool f_label_overlaps_c_sym
214 = geometry_rectangle_is_intersecting( f_label, probe_symbox )
215 && ( ! geometry_rectangle_is_containing( probe_space, f_label ) );
216 const bool label_overlaps
217 = geometry_rectangle_is_intersecting( f_label, probe_label )
218 || geometry_rectangle_is_intersecting( f_label, probe_icon );
219
220 if ( ! feature_is_proxy_for_probe )
221 {
222 if ( f_sym_overlaps_c_label || f_label_overlaps_c_sym || label_overlaps )
223 {
224 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_WARNING );
225 (*overlap_callback)( data, f_symbox, probe_label );
226 (*overlap_callback)( data, f_symbox, probe_icon );
227 (*overlap_callback)( data, f_label, probe_symbox );
228 (*overlap_callback)( data, f_label, probe_label );
229 (*overlap_callback)( data, f_label, probe_icon );
230 }
231 else if ( symbox_overlaps )
232 {
233 const layout_visible_classifier_t *const f_parent
234 = layout_feature_get_classifier_const ( feature );
235 const bool probe_is_parent
236 = layout_visible_classifier_is_equal_diagramelement_id( f_parent, probe );
237 if ( probe_is_parent )
238 {
239 /* ok: a feature may overlap its own parent classifier */
240 }
241 else
242 {
243 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_WARNING );
244 (*overlap_callback)( data, f_symbox, probe_symbox );
245 }
246 }
247 }
248 }
249
250 /* check current feature against already processed features */
251
252 for ( uint_fast32_t probe_idx = 0; probe_idx < f_idx; probe_idx ++ )
253 {
254 const layout_feature_t *const probe = &((*input_layout).feature_layout[probe_idx]);
255 const data_row_t probe_id = layout_feature_get_feature_id( probe );
256 const bool probe_visible
257 = data_rules_diagram_shows_feature( &((*input_layout).filter_rules),
258 (*input_layout).input_data,
259 probe_id
260 );
261 const geometry_rectangle_t *const probe_symbox
262 = layout_feature_get_symbol_box_const( probe );
263 const geometry_rectangle_t *const probe_label
264 = layout_feature_get_label_box_const( probe );
265
266 if ( probe_visible )
267 {
268 const bool symbox_overlaps
269 = geometry_rectangle_is_intersecting( f_symbox, probe_symbox );
270 const bool mixed_overlaps
271 = ( geometry_rectangle_is_intersecting( f_symbox, probe_label )
272 || geometry_rectangle_is_intersecting( f_label, probe_symbox ) );
273 const bool label_overlaps
274 = geometry_rectangle_is_intersecting( f_label, probe_label );
275
276 if ( mixed_overlaps || label_overlaps )
277 {
278 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_WARNING );
279 (*overlap_callback)( data, f_symbox, probe_label );
280 (*overlap_callback)( data, f_label, probe_symbox );
281 (*overlap_callback)( data, f_label, probe_label );
282 }
283 else if ( symbox_overlaps )
284 {
285 const layout_visible_classifier_t *const f_parent
286 = layout_feature_get_classifier_const ( feature );
287 const layout_visible_classifier_t *const probe_parent
288 = layout_feature_get_classifier_const ( probe );
289
290 const bool same_parent
291 = layout_visible_classifier_is_equal_diagramelement_id( f_parent, probe_parent );
292 if ( same_parent )
293 {
294 /* ok, not a layouting issue */
295 }
296 else
297 {
298 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_WARNING );
299 (*overlap_callback)( data, f_symbox, probe_symbox );
300 }
301 }
302 }
303 }
304 }
305 else if ( geometry_rectangle_is_containing( diag_bounds, f_symbox )
306 && geometry_rectangle_is_containing( diag_bounds, f_label ) )
307 {
308 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_EXPORTED );
309 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_WARNING );
310 (*overlap_callback)( data, diag_bounds, f_symbox );
311 (*overlap_callback)( data, diag_bounds, f_label );
312 }
313 else
314 {
315 data_stat_inc_count( io_layout_stat, feat_or_lifeline, DATA_STAT_SERIES_ERROR );
316 (*overlap_callback)( data, diag_space, diag_space );
317 }
318 }
319
320 /* check relationships against diagram */
321
322 for ( uint_fast32_t r_idx = 0; r_idx < (*input_layout).relationship_count; r_idx ++ )
323 {
324 const layout_relationship_t *const relationship = &((*input_layout).relationship_layout[r_idx]);
325 const data_row_t relationship_id = layout_relationship_get_relationship_id( relationship );
326 const bool relationship_visible
327 = data_rules_diagram_shows_relationship( &((*input_layout).filter_rules),
328 (*input_layout).input_data,
329 relationship_id
330 );
331 const geometry_rectangle_t *const r_label = layout_relationship_get_label_box_const( relationship );
332 const geometry_connector_t *const r_shape = layout_relationship_get_shape_const( relationship );
333 const geometry_rectangle_t r_bounds = geometry_connector_get_bounding_rectangle( r_shape );
334
335 if ( ! relationship_visible )
336 {
337 /* nothing to do, relationship is not visible in this diagram */
338 }
339 else if ( geometry_rectangle_is_containing( diag_space, &r_bounds )
340 && geometry_rectangle_is_containing( diag_space, r_label ) )
341 {
342 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_EXPORTED );
343
344 /* check relationships against classifiers */
345
346 for ( uint_fast32_t probe_idx = 0; probe_idx < (*input_layout).visible_classifier_count; probe_idx ++ )
347 {
348 const layout_visible_classifier_t *const probe
349 = &((*input_layout).visible_classifier_layout[probe_idx]);
350
351 const geometry_rectangle_t *const probe_symbox
352 = layout_visible_classifier_get_symbol_box_const( probe );
353 const geometry_rectangle_t *const probe_label
354 = layout_visible_classifier_get_label_box_const( probe );
355 const geometry_rectangle_t *const probe_space
356 = layout_visible_classifier_get_space_const( probe );
357 const geometry_rectangle_t *const probe_icon
358 = layout_visible_classifier_get_icon_box_const( probe );
359
360 const bool label_overlaps_label
361 = geometry_rectangle_is_intersecting( r_label, probe_label )
362 || geometry_rectangle_is_intersecting( r_label, probe_icon );
363 const bool label_overlaps_symbox
364 = ( geometry_rectangle_is_intersecting( r_label, probe_symbox )
365 && ! geometry_rectangle_is_containing( probe_space, r_label ) );
366 const bool shape_overlaps_label
367 = geometry_connector_is_intersecting_rectangle( r_shape, probe_label )
368 || geometry_connector_is_intersecting_rectangle( r_shape, probe_icon );
369
370 if ( label_overlaps_label || label_overlaps_symbox || shape_overlaps_label )
371 {
372 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_WARNING );
373 (*overlap_callback)( data, r_label, probe_label );
374 (*overlap_callback)( data, r_label, probe_icon );
375 (*overlap_callback)( data, r_label, probe_symbox );
376 (*overlap_callback)( data, &r_bounds, probe_label );
377 (*overlap_callback)( data, &r_bounds, probe_icon );
378 }
379 }
380
381 /* check relationships against features */
382
383 for ( uint_fast32_t probe_idx = 0; probe_idx < (*input_layout).feature_count; probe_idx ++ )
384 {
385 const layout_feature_t *const probe = &((*input_layout).feature_layout[probe_idx]);
386 const data_feature_t *const probe_data = layout_feature_get_data_const( probe );
387 const data_feature_type_t probe_type = data_feature_get_main_type( probe_data );
388 const data_row_t probe_id = layout_feature_get_feature_id( probe );
389 const bool probe_visible
390 = data_rules_diagram_shows_feature( &((*input_layout).filter_rules),
391 (*input_layout).input_data,
392 probe_id
393 );
394 const geometry_rectangle_t *const probe_symbox
395 = layout_feature_get_symbol_box_const( probe );
396 const geometry_rectangle_t *const probe_label
397 = layout_feature_get_label_box_const( probe );
398
399 if ( probe_visible && ( DATA_FEATURE_TYPE_LIFELINE != probe_type ) )
400 {
401 const bool label_overlaps_label
402 = geometry_rectangle_is_intersecting( r_label, probe_label );
403 const bool label_overlaps_symbox
404 = geometry_rectangle_is_intersecting( r_label, probe_symbox );
405 const bool shape_overlaps_label
406 = geometry_connector_is_intersecting_rectangle( r_shape, probe_label );
407
408 if ( label_overlaps_label || label_overlaps_symbox || shape_overlaps_label )
409 {
410 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_WARNING );
411 (*overlap_callback)( data, r_label, probe_label );
412 (*overlap_callback)( data, r_label, probe_symbox );
413 (*overlap_callback)( data, &r_bounds, probe_label );
414 }
415 }
416 }
417
418 /* check current relationship against already processed relationships */
419
420 for ( uint_fast32_t probe_idx = 0; probe_idx < r_idx; probe_idx ++ )
421 {
422 const layout_relationship_t *const probe = &((*input_layout).relationship_layout[probe_idx]);
423 const data_row_t probe_id = layout_relationship_get_relationship_id( probe );
424 const bool probe_visible
425 = data_rules_diagram_shows_relationship( &((*input_layout).filter_rules),
426 (*input_layout).input_data,
427 probe_id
428 );
429 const geometry_rectangle_t *const probe_label
430 = layout_relationship_get_label_box_const( probe );
431 const geometry_connector_t *const probe_shape
432 = layout_relationship_get_shape_const( probe );
433
434 if ( probe_visible )
435 {
436 const bool label_overlaps
437 = geometry_rectangle_is_intersecting( r_label, probe_label );
438 const bool mixed_overlaps
439 = ( geometry_connector_is_intersecting_rectangle( r_shape, probe_label )
440 || geometry_connector_is_intersecting_rectangle( probe_shape, r_label ) );
441
442 if ( label_overlaps || mixed_overlaps )
443 {
444 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_WARNING );
445 (*overlap_callback)( data, r_label, probe_label );
446 (*overlap_callback)( data, &r_bounds, probe_label );
447 const geometry_rectangle_t probe_bounds
448 = geometry_connector_get_bounding_rectangle( probe_shape );
449 (*overlap_callback)( data, &probe_bounds, r_label );
450 }
451 }
452 }
453
454 }
455 else if ( geometry_rectangle_is_containing( diag_bounds, &r_bounds )
456 && geometry_rectangle_is_containing( diag_bounds, r_label ) )
457 {
458 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_EXPORTED );
459 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_WARNING );
460 (*overlap_callback)( data, diag_bounds, &r_bounds );
461 (*overlap_callback)( data, diag_bounds, r_label );
462 }
463 else
464 {
465 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_RELATIONSHIP, DATA_STAT_SERIES_ERROR );
466 (*overlap_callback)( data, diag_space, diag_space );
467 }
468 }
469 }
470 else
471 {
472 data_stat_inc_count( io_layout_stat, DATA_STAT_TABLE_DIAGRAM, DATA_STAT_SERIES_ERROR );
473 }
474
475 pencil_rules_destroy( &pencil_rules );
476 U8_TRACE_END();
477 }
478
479
480 /*
481 Copyright 2017-2026 Andreas Warnke
482
483 Licensed under the Apache License, Version 2.0 (the "License");
484 you may not use this file except in compliance with the License.
485 You may obtain a copy of the License at
486
487 http://www.apache.org/licenses/LICENSE-2.0
488
489 Unless required by applicable law or agreed to in writing, software
490 distributed under the License is distributed on an "AS IS" BASIS,
491 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
492 See the License for the specific language governing permissions and
493 limitations under the License.
494 */