2022-11-20 03:45:42 +11:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 OR MIT OR Unlicense
|
2022-10-25 08:53:12 +11:00
|
|
|
|
|
|
|
struct TagMonoid {
|
|
|
|
trans_ix: u32,
|
2022-11-04 16:00:52 +11:00
|
|
|
// TODO: I don't think pathseg_ix is used.
|
2022-10-25 08:53:12 +11:00
|
|
|
pathseg_ix: u32,
|
|
|
|
pathseg_offset: u32,
|
2022-11-04 10:53:34 +11:00
|
|
|
#ifdef full
|
|
|
|
linewidth_ix: u32,
|
|
|
|
path_ix: u32,
|
|
|
|
#endif
|
2022-10-25 08:53:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
let PATH_TAG_SEG_TYPE = 3u;
|
|
|
|
let PATH_TAG_LINETO = 1u;
|
|
|
|
let PATH_TAG_QUADTO = 2u;
|
|
|
|
let PATH_TAG_CUBICTO = 3u;
|
|
|
|
let PATH_TAG_F32 = 8u;
|
|
|
|
let PATH_TAG_TRANSFORM = 0x20u;
|
2022-11-04 10:53:34 +11:00
|
|
|
#ifdef full
|
|
|
|
let PATH_TAG_PATH = 0x10u;
|
|
|
|
let PATH_TAG_LINEWIDTH = 0x40u;
|
|
|
|
#endif
|
2022-10-25 08:53:12 +11:00
|
|
|
|
|
|
|
fn tag_monoid_identity() -> TagMonoid {
|
2022-10-27 07:55:45 +11:00
|
|
|
return TagMonoid();
|
2022-10-25 08:53:12 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
fn combine_tag_monoid(a: TagMonoid, b: TagMonoid) -> TagMonoid {
|
|
|
|
var c: TagMonoid;
|
|
|
|
c.trans_ix = a.trans_ix + b.trans_ix;
|
|
|
|
c.pathseg_ix = a.pathseg_ix + b.pathseg_ix;
|
|
|
|
c.pathseg_offset = a.pathseg_offset + b.pathseg_offset;
|
2022-11-04 10:53:34 +11:00
|
|
|
#ifdef full
|
|
|
|
c.linewidth_ix = a.linewidth_ix + b.linewidth_ix;
|
|
|
|
c.path_ix = a.path_ix + b.path_ix;
|
|
|
|
#endif
|
2022-10-25 08:53:12 +11:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn reduce_tag(tag_word: u32) -> TagMonoid {
|
|
|
|
var c: TagMonoid;
|
|
|
|
let point_count = tag_word & 0x3030303u;
|
|
|
|
c.pathseg_ix = countOneBits((point_count * 7u) & 0x4040404u);
|
|
|
|
c.trans_ix = countOneBits(tag_word & (PATH_TAG_TRANSFORM * 0x1010101u));
|
|
|
|
let n_points = point_count + ((tag_word >> 2u) & 0x1010101u);
|
|
|
|
var a = n_points + (n_points & (((tag_word >> 3u) & 0x1010101u) * 15u));
|
|
|
|
a += a >> 8u;
|
|
|
|
a += a >> 16u;
|
|
|
|
c.pathseg_offset = a & 0xffu;
|
2022-11-04 10:53:34 +11:00
|
|
|
#ifdef full
|
2022-11-09 14:30:47 +11:00
|
|
|
c.path_ix = countOneBits(tag_word & (PATH_TAG_PATH * 0x1010101u));
|
2022-11-04 10:53:34 +11:00
|
|
|
c.linewidth_ix = countOneBits(tag_word & (PATH_TAG_LINEWIDTH * 0x1010101u));
|
|
|
|
#endif
|
2022-10-25 08:53:12 +11:00
|
|
|
return c;
|
|
|
|
}
|