%% options copyright owner = Dirk Krause copyright year = 2019-xxxx SPDX-License-Identifier: BSD-3-Clause %% header /** @file WxdkdrawComp.h Compare drawing objects. */ #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef WXDTYPES_H_INCLUDED #include "WxdkdrawTypes.h" #endif /** Comparison criteria for drawing objects. */ enum { /** Compare by layer number and object properties. */ WXD2LAT_OBJ_COMPARE_CR_PROPERTIES = 0 , /** Compare objects by name. */ WXD2LAT_OBJ_COMPARE_CR_BY_NAME , /** Compare object name against specified name. */ WXD2LAT_OBJ_COMPARE_CR_AGAINST_NAME }; #ifdef __cplusplus extern "C" { #endif /** Compare drawing objects. @param l Left object. @param r Right object or name. @param cr Comparison criteria: - WXD2LAT_OBJ_COMPARE_CR_PROPERTIES: Object/object by features, - WXD2LAT_OBJ_COMPARE_CR_BY_NAME: Object/object by name, - WXD2LAT_OBJ_COMPARE_CR_AGAINST_NAME: Object/name. @return Comparison result: -1: lr. */ int drawobj_compare_object(const void *l, const void *r, int cr); /** Find category for object type. @param ot Object type. @return Category for object type. */ int drawobj_object_category(int8_t ot); /** Compare stipple bitmaps. @param l Address of left structure. @param r Address of right structure. @param cr Comparison criteria (ignored). @return Comparison result. */ int drawobj_compare_stipples(const void *l, const void *r, int cr); /** Compare two layer structures. @param l Left layer structure. @param r Right layer structure or layer number. @param cr Comparison criteria (0=layer/layer, 1=layer/number). @return Comparison result. */ int drawobj_compare_layers(const void *l, const void *r, int cr); #ifdef __cplusplus } #endif %% module #include "wxdkdraw.h" $!trace-include int drawobj_object_category(int8_t ot) { int back = WXD_OC_CONTROL; $? "+ drawobj_object_category %d", (int)ot switch (ot) { case WXD_OT_TEXT : { back = WXD_OC_TEXT ; } break; case WXD_OT_POLYLINE : case WXD_OT_O_SPLINE : case WXD_OT_O_ARC : { back = WXD_OC_OPEN ; } break; case WXD_OT_POLYGON : case WXD_OT_C_SPLINE : case WXD_OT_C_ARC : case WXD_OT_CIRCLE : case WXD_OT_ELLIPSE : case WXD_OT_BOX : { back = WXD_OC_CLOSED ; } break; case WXD_OT_IMAGE : { back = WXD_OC_IMAGE ; } break; } $? "- drawobj_object_category %d", back return back; } static int cmp_u8(uint8_t a, uint8_t b) { return ((a > b) ? (1) : ((a < b) ? (-1) : (0))); } #if 0 static int cmp_i8(int8_t a, int8_t b) { return ((a > b) ? (1) : ((a < b) ? (-1) : (0))); } #endif #if 0 static int cmp_u16(uint16_t a, uint16_t b) { return ((a > b) ? (1) : ((a < b) ? (-1) : (0))); } #endif static int cmp_i16(int16_t a, int16_t b) { return ((a > b) ? (1) : ((a < b) ? (-1) : (0))); } #if 0 static int cmp_int(int a, int b) { return ((a > b) ? (1) : ((a < b) ? (-1) : (0))); } #endif int drawobj_compare_object(const void *l, const void *r, int DK4_ARG_UNUSED(cr)) { const Wxd_object_t *pl; /* Left object */ const Wxd_object_t *pr; /* Right object */ #if 0 int cal; /* Left object category */ int car; /* Right object category */ #endif int back = 0; /* Comparison result */ DK4_UNUSED_ARG(cr) $? "+ drawobj_compare_object %d", cr if (NULL != l) { if (NULL != r) { pl = (const Wxd_object_t *)l; pr = (const Wxd_object_t *)r; back = cmp_i16(pl->lay, pr->lay); /* 2019-05-10 Modification Objects in the flat storage are compared by layer number only. Otherwise we would need to change object order on each style modification. */ #if 0 if (0 == back) { cal = drawobj_object_category(pl->ot); car = drawobj_object_category(pr->ot); back = cmp_int(cal, car); if (0 == back) { back = cmp_u16(pl->lw, pr->lw); if (0 == back) { back = cmp_u8(pl->ls, pr->ls); if (0 == back) { back = cmp_u8(pl->sl, pr->sl); if (0 == back) { back = cmp_u8(pl->js, pr->js); if (0 == back) { back = cmp_u8(pl->cs, pr->cs); if (0 == back) { back = cmp_u8(pl->fs, pr->fs); if (0 == back) { back = cmp_u8(pl->ml, pr->ml); if (0 == back) { back = cmp_u8(pl->sc[0], pr->sc[0]); if (0 == back) { back = cmp_u8(pl->sc[1], pr->sc[1]); if (0 == back) { back = cmp_u8(pl->sc[2], pr->sc[2]); if (0 == back) { back = cmp_u8(pl->fc[0], pr->fc[0]); if (0 == back) { back = cmp_u8(pl->fc[1], pr->fc[1]); if (0 == back) { back = cmp_u8(pl->fc[2], pr->fc[2]); if (0 == back) { back = cmp_i8(pl->ot, pr->ot); } } } } } } } } } } } } } } } #endif } else { back = 1; } } else { if (NULL != r) { back = -1; } } $? "- drawobj_compare_object %d", back return back; } int drawobj_compare_stipples(const void *l, const void *r, int DK4_ARG_UNUSED(cr)) { Wxd_stipple_t const *pl; /* Left stipple */ Wxd_stipple_t const *pr; /* Right stipple */ int back = 0; /* Comparison result */ DK4_UNUSED_ARG(cr) if (NULL != l) { if (NULL != r) { pl = (Wxd_stipple_t const *)l; pr = (Wxd_stipple_t const *)r; for (size_t i = 0; ((0 == back) && (i < 7)); i++) { back = cmp_u8(pl->cd[i], pr->cd[i]); } } else { back = 1; } } else { if (NULL != r) { back = -1; } } return back; } int drawobj_compare_layers(const void *l, const void *r, int cr) { const Wxd_layer_t *pl; /* Left layer structure */ const Wxd_layer_t *pr; /* Right layer structure */ const int16_t *pnum; /* Address of layer number variable */ int back = 0; /* Comparison result */ if (NULL != l) { if (NULL != r) { pl = (const Wxd_layer_t *)l; switch (cr) { case 1: { pnum = (const int16_t *)r; if (pl->lay > *pnum) { back = 1; } else { if (pl->lay < *pnum) { back = -1; } } } break; default: { pr = (const Wxd_layer_t *)r; if (pl->lay > pr->lay) { back = 1; } else { if (pl->lay < pr->lay) { back = -1; } } } break; } } else { back = 1; } } else { if (NULL != r) { back = -1; } } return back; } /* vim: set ai sw=4 ts=4 : */