Debian Codegraph @

texk/web2c/mfluadir/otfcc/lib/vf/region.c

raw
1 #include "otfcc/vf/axis.h"
2 #include "support/util.h"
3
4 vq_Region *vq_createRegion(shapeid_t dimensions) {
5 vq_Region *r;
6 NEW_CLEAN_S(r, (VQ_REGION_SIZE(dimensions)));
7 r->dimensions = dimensions;
8 return r;
9 }
10
11 void vq_deleteRegion(MOVE vq_Region *region) {
12 FREE(region);
13 }
14
15 vq_Region *vq_copyRegion(const vq_Region *region) {
16 vq_Region *dst = vq_createRegion(region->dimensions);
17 memcpy(dst, region, VQ_REGION_SIZE(region->dimensions));
18 return dst;
19 }
20
21 int vq_compareRegion(const vq_Region *a, const vq_Region *b) {
22 if (a->dimensions < b->dimensions) return -1;
23 if (a->dimensions > b->dimensions) return 1;
24 return strncmp((const char *)a, (const char *)b, VQ_REGION_SIZE(a->dimensions));
25 }
26
27 bool vq_AxisSpanIsOne(const vq_AxisSpan *s) {
28 const pos_t a = s->start;
29 const pos_t p = s->peak;
30 const pos_t z = s->end;
31 return a > p || p > z || (a < 0 && z > 0 && p != 0) || (p == 0);
32 }
33
34 static pos_t INLINE weightAxisRegion(const vq_AxisSpan *as, const pos_t x) {
35 const pos_t a = as->start;
36 const pos_t p = as->peak;
37 const pos_t z = as->end;
38 if (a > p || p > z) {
39 return 1;
40 } else if (a < 0 && z > 0 && p != 0) {
41 return 1;
42 } else if (p == 0) {
43 return 1;
44 } else if (x < a || x > z) {
45 return 0;
46 } else if (x == p) {
47 return 1;
48 } else if (x < p) {
49 return (x - a) / (p - a);
50 } else {
51 return (z - x) / (z - p);
52 }
53 }
54 //static pos_t vqRegionGetWeight(const vq_Region *r, const VV *v) {
55 // pos_t w = 1;
56 // for (size_t j = 0; j < r->dimensions && v->length; j++) {
57 // w *= weightAxisRegion(&r->spans[j], v->items[j]);
58 // }
59 // return w;
60 //}
61
62 void vq_showRegion(const vq_Region *r) {}