mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
common/array: code refactoring
easy access to a specific data with a operator.
This commit is contained in:
parent
24711e485c
commit
5a73bcaa8f
11 changed files with 57 additions and 32 deletions
|
@ -74,11 +74,36 @@ struct Array
|
|||
return reserve(count + size);
|
||||
}
|
||||
|
||||
T* end() const
|
||||
const T& operator[](size_t idx) const
|
||||
{
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
T& operator[](size_t idx)
|
||||
{
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
T* end()
|
||||
{
|
||||
return data + count;
|
||||
}
|
||||
|
||||
const T* end() const
|
||||
{
|
||||
return data + count;
|
||||
}
|
||||
|
||||
const T& last() const
|
||||
{
|
||||
return data[count - 1];
|
||||
}
|
||||
|
||||
const T& first() const
|
||||
{
|
||||
return data[0];
|
||||
}
|
||||
|
||||
T& last()
|
||||
{
|
||||
return data[count - 1];
|
||||
|
|
|
@ -174,7 +174,7 @@ struct LottieProperty
|
|||
|
||||
LottieScalarFrame<T>& nextFrame()
|
||||
{
|
||||
return frames->data[frames->count];
|
||||
return (*frames)[frames->count];
|
||||
}
|
||||
|
||||
T operator()(int32_t frameNo)
|
||||
|
@ -242,7 +242,7 @@ struct LottiePathSet
|
|||
|
||||
LottieScalarFrame<PathSet>& nextFrame()
|
||||
{
|
||||
return frames->data[frames->count];
|
||||
return (*frames)[frames->count];
|
||||
}
|
||||
|
||||
bool operator()(int32_t frameNo, Array<PathCommand>& cmds, Array<Point>& pts)
|
||||
|
@ -336,7 +336,7 @@ struct LottieColorStop
|
|||
|
||||
LottieScalarFrame<ColorStop>& nextFrame()
|
||||
{
|
||||
return frames->data[frames->count];
|
||||
return (*frames)[frames->count];
|
||||
}
|
||||
|
||||
void operator()(int32_t frameNo, Fill* fill)
|
||||
|
@ -425,7 +425,7 @@ struct LottiePosition
|
|||
|
||||
LottieVectorFrame<Point>& nextFrame()
|
||||
{
|
||||
return frames->data[frames->count];
|
||||
return (*frames)[frames->count];
|
||||
}
|
||||
|
||||
Point operator()(int32_t frameNo)
|
||||
|
|
|
@ -123,7 +123,7 @@ static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
|
|||
to->stroke.dash.array.clear();
|
||||
to->stroke.dash.array.reserve(from->stroke.dash.array.count);
|
||||
for (uint32_t i = 0; i < from->stroke.dash.array.count; ++i) {
|
||||
to->stroke.dash.array.push(from->stroke.dash.array.data[i]);
|
||||
to->stroke.dash.array.push(from->stroke.dash.array[i]);
|
||||
}
|
||||
to->stroke.flags = (to->stroke.flags | SvgStrokeFlags::Dash);
|
||||
to->flags = (to->flags | SvgStyleFlags::StrokeDashArray);
|
||||
|
@ -236,7 +236,7 @@ void cssUpdateStyle(SvgNode* doc, SvgNode* style)
|
|||
void cssApplyStyleToPostponeds(Array<SvgNodeIdPair>& postponeds, SvgNode* style)
|
||||
{
|
||||
for (uint32_t i = 0; i < postponeds.count; ++i) {
|
||||
auto nodeIdPair = postponeds.data[i];
|
||||
auto nodeIdPair = postponeds[i];
|
||||
|
||||
//css styling: tag.name has higher priority than .name
|
||||
if (auto cssNode = cssFindStyleNode(style, nodeIdPair.id, nodeIdPair.node->type)) {
|
||||
|
|
|
@ -371,7 +371,7 @@ static void _parseDashArray(SvgLoaderData* loader, const char *str, SvgDash* das
|
|||
str = end;
|
||||
}
|
||||
//If dash array size is 1, it means that dash and gap size are the same.
|
||||
if ((*dash).array.count == 1) (*dash).array.push((*dash).array.data[0]);
|
||||
if ((*dash).array.count == 1) (*dash).array.push((*dash).array[0]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2622,7 +2622,7 @@ static GradientFactoryMethod _findGradientFactory(const char* name)
|
|||
static void _cloneGradStops(Array<Fill::ColorStop>& dst, const Array<Fill::ColorStop>& src)
|
||||
{
|
||||
for (uint32_t i = 0; i < src.count; ++i) {
|
||||
dst.push(src.data[i]);
|
||||
dst.push(src[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2776,7 +2776,7 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren
|
|||
child->stroke.dash.array.clear();
|
||||
child->stroke.dash.array.reserve(parent->stroke.dash.array.count);
|
||||
for (uint32_t i = 0; i < parent->stroke.dash.array.count; ++i) {
|
||||
child->stroke.dash.array.push(parent->stroke.dash.array.data[i]);
|
||||
child->stroke.dash.array.push(parent->stroke.dash.array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2845,7 +2845,7 @@ static void _styleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
|
|||
to->stroke.dash.array.clear();
|
||||
to->stroke.dash.array.reserve(from->stroke.dash.array.count);
|
||||
for (uint32_t i = 0; i < from->stroke.dash.array.count; ++i) {
|
||||
to->stroke.dash.array.push(from->stroke.dash.array.data[i]);
|
||||
to->stroke.dash.array.push(from->stroke.dash.array[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2991,7 +2991,7 @@ static void _cloneNode(SvgNode* from, SvgNode* parent, int depth)
|
|||
static void _clonePostponedNodes(Array<SvgNodeIdPair>* cloneNodes, SvgNode* doc)
|
||||
{
|
||||
for (uint32_t i = 0; i < cloneNodes->count; ++i) {
|
||||
auto nodeIdPair = cloneNodes->data[i];
|
||||
auto nodeIdPair = (*cloneNodes)[i];
|
||||
auto defs = _getDefsNode(nodeIdPair.node);
|
||||
auto nodeFrom = _findNodeById(defs, nodeIdPair.id);
|
||||
if (!nodeFrom) nodeFrom = _findNodeById(doc, nodeIdPair.id);
|
||||
|
@ -3072,7 +3072,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
|
|||
loader->doc = node;
|
||||
} else {
|
||||
if (!strcmp(tagName, "svg")) return; //Already loaded <svg>(SvgNodeType::Doc) tag
|
||||
if (loader->stack.count > 0) parent = loader->stack.data[loader->stack.count - 1];
|
||||
if (loader->stack.count > 0) parent = loader->stack.last();
|
||||
else parent = loader->doc;
|
||||
if (!strcmp(tagName, "style")) {
|
||||
// TODO: For now only the first style node is saved. After the css id selector
|
||||
|
@ -3093,7 +3093,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
|
|||
loader->stack.push(node);
|
||||
}
|
||||
} else if ((method = _findGraphicsFactory(tagName))) {
|
||||
if (loader->stack.count > 0) parent = loader->stack.data[loader->stack.count - 1];
|
||||
if (loader->stack.count > 0) parent = loader->stack.last();
|
||||
else parent = loader->doc;
|
||||
node = method(loader, parent, attrs, attrsLength, simpleXmlParseAttributes);
|
||||
} else if ((gradientMethod = _findGradientFactory(tagName))) {
|
||||
|
|
|
@ -382,7 +382,7 @@ static bool _processCommand(Array<PathCommand>* cmds, Array<Point>* pts, char cm
|
|||
case 's':
|
||||
case 'S': {
|
||||
Point p[3], ctrl;
|
||||
if ((cmds->count > 1) && (cmds->data[cmds->count - 1] == PathCommand::CubicTo) &&
|
||||
if ((cmds->count > 1) && (cmds->last() == PathCommand::CubicTo) &&
|
||||
!(*isQuadratic)) {
|
||||
ctrl.x = 2 * cur->x - curCtl->x;
|
||||
ctrl.y = 2 * cur->y - curCtl->y;
|
||||
|
@ -423,7 +423,7 @@ static bool _processCommand(Array<PathCommand>* cmds, Array<Point>* pts, char cm
|
|||
case 't':
|
||||
case 'T': {
|
||||
Point p[3], ctrl;
|
||||
if ((cmds->count > 1) && (cmds->data[cmds->count - 1] == PathCommand::CubicTo) &&
|
||||
if ((cmds->count > 1) && (cmds->last() == PathCommand::CubicTo) &&
|
||||
*isQuadratic) {
|
||||
ctrl.x = 2 * cur->x - curCtl->x;
|
||||
ctrl.y = 2 * cur->y - curCtl->y;
|
||||
|
|
|
@ -114,7 +114,7 @@ static unique_ptr<LinearGradient> _applyLinearGradientProperty(SvgStyleGradient*
|
|||
if (!stops) return fillGrad;
|
||||
auto prevOffset = 0.0f;
|
||||
for (uint32_t i = 0; i < g->stops.count; ++i) {
|
||||
auto colorStop = &g->stops.data[i];
|
||||
auto colorStop = &g->stops[i];
|
||||
//Use premultiplied color
|
||||
stops[i].r = colorStop->r;
|
||||
stops[i].g = colorStop->g;
|
||||
|
@ -176,7 +176,7 @@ static unique_ptr<RadialGradient> _applyRadialGradientProperty(SvgStyleGradient*
|
|||
if (!stops) return fillGrad;
|
||||
auto prevOffset = 0.0f;
|
||||
for (uint32_t i = 0; i < g->stops.count; ++i) {
|
||||
auto colorStop = &g->stops.data[i];
|
||||
auto colorStop = &g->stops[i];
|
||||
//Use premultiplied color
|
||||
stops[i].r = colorStop->r;
|
||||
stops[i].g = colorStop->g;
|
||||
|
|
|
@ -108,7 +108,7 @@ struct Vertex : public Object
|
|||
|
||||
Vertex() = default;
|
||||
|
||||
Vertex(const GlPoint &p) : point(std::ceilf(p.x * 100.f) / 100.f, std::ceilf(p.y * 100.f) / 100.f)
|
||||
Vertex(const GlPoint &p) : point(ceilf(p.x * 100.f) / 100.f, ceilf(p.y * 100.f) / 100.f)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -888,7 +888,7 @@ Tessellator::~Tessellator()
|
|||
auto count = outlines.count;
|
||||
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
delete outlines.data[i];
|
||||
delete outlines[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -942,10 +942,10 @@ void Tessellator::tessellate(const Array<const RenderShape *> &shapes)
|
|||
this->fillRule = FillRule::Winding;
|
||||
|
||||
for (uint32_t i = 0; i < shapes.count; i++) {
|
||||
auto cmds = shapes.data[i]->path.cmds.data;
|
||||
auto cmdCnt = shapes.data[i]->path.cmds.count;
|
||||
auto pts = shapes.data[i]->path.pts.data;
|
||||
auto ptsCnt = shapes.data[i]->path.pts.count;
|
||||
auto cmds = shapes[i]->path.cmds.data;
|
||||
auto cmdCnt = shapes[i]->path.cmds.count;
|
||||
auto pts = shapes[i]->path.pts.data;
|
||||
auto ptsCnt = shapes[i]->path.pts.count;
|
||||
|
||||
this->visitShape(cmds, cmdCnt, pts, ptsCnt);
|
||||
}
|
||||
|
@ -1047,7 +1047,7 @@ void Tessellator::buildMesh()
|
|||
Array<detail::Vertex *> temp{};
|
||||
|
||||
for (uint32_t i = 0; i < outlines.count; i++) {
|
||||
auto list = outlines.data[i];
|
||||
auto list = outlines[i];
|
||||
|
||||
auto prev = list->tail;
|
||||
auto v = list->head;
|
||||
|
@ -1072,7 +1072,7 @@ void Tessellator::buildMesh()
|
|||
temp.sort<detail::VertexCompare>();
|
||||
|
||||
for (uint32_t i = 0; i < temp.count; i++) {
|
||||
this->pMesh->append(temp.data[i]);
|
||||
this->pMesh->append(temp[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1643,7 +1643,7 @@ void Stroker::stroke(const RenderShape *rshape)
|
|||
auto ptsCnt = rshape->path.pts.count;
|
||||
|
||||
const float *dash_pattern = nullptr;
|
||||
auto dash_count = rshape->strokeDash(&dash_pattern);
|
||||
auto dash_count = rshape->strokeDash(&dash_pattern, nullptr);
|
||||
|
||||
if (dash_count == 0) {
|
||||
doStroke(cmds, cmdCnt, pts, ptsCnt);
|
||||
|
|
|
@ -93,7 +93,7 @@ static bool _genOutline(SwImage* image, const RenderMesh* mesh, const Matrix* tr
|
|||
outline->types.push(SW_CURVE_TYPE_POINT);
|
||||
}
|
||||
|
||||
outline->pts.push(outline->pts.data[0]);
|
||||
outline->pts.push(outline->pts[0]);
|
||||
outline->types.push(SW_CURVE_TYPE_POINT);
|
||||
outline->cntrs.push(outline->pts.count - 1);
|
||||
outline->closed.push(true);
|
||||
|
|
|
@ -716,11 +716,11 @@ static void _decomposeOutline(RleWorker& rw)
|
|||
for (auto cntr = outline->cntrs.data; cntr < outline->cntrs.end(); ++cntr) {
|
||||
auto last = *cntr;
|
||||
auto limit = outline->pts.data + last;
|
||||
auto start = UPSCALE(outline->pts.data[first]);
|
||||
auto start = UPSCALE(outline->pts[first]);
|
||||
auto pt = outline->pts.data + first;
|
||||
auto types = outline->types.data + first;
|
||||
|
||||
_moveTo(rw, UPSCALE(outline->pts.data[first]));
|
||||
_moveTo(rw, UPSCALE(outline->pts[first]));
|
||||
|
||||
while (pt < limit) {
|
||||
++pt;
|
||||
|
|
|
@ -108,7 +108,7 @@ static void _outlineClose(SwOutline& outline)
|
|||
if (outline.pts.count == i) return;
|
||||
|
||||
//Close the path
|
||||
outline.pts.push(outline.pts.data[i]);
|
||||
outline.pts.push(outline.pts[i]);
|
||||
outline.types.push(SW_CURVE_TYPE_POINT);
|
||||
outline.closed.push(true);
|
||||
}
|
||||
|
|
|
@ -852,7 +852,7 @@ bool strokeParseOutline(SwStroke* stroke, const SwOutline& outline)
|
|||
continue;
|
||||
}
|
||||
|
||||
auto start = outline.pts.data[first];
|
||||
auto start = outline.pts[first];
|
||||
auto pt = outline.pts.data + first;
|
||||
auto types = outline.types.data + first;
|
||||
auto type = types[0];
|
||||
|
|
Loading…
Add table
Reference in a new issue