Coverage Report

Created: 2026-04-29 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libmspub/src/lib/ShapeGroupElement.cpp
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/*
3
 * This file is part of the libmspub project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 */
9
10
#include "ShapeGroupElement.h"
11
12
#include <algorithm>
13
14
#include "Coordinate.h"
15
#include "MSPUBConstants.h"
16
17
namespace libmspub
18
{
19
20
84.9k
ShapeGroupElement::ShapeGroupElement(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum) : m_shapeInfo(), m_parent(parent), m_children(), m_seqNum(seqNum), m_transform()
21
84.9k
{
22
84.9k
}
23
24
ShapeGroupElement::~ShapeGroupElement()
25
84.9k
{
26
84.9k
}
27
28
std::shared_ptr<ShapeGroupElement> ShapeGroupElement::create(const std::shared_ptr<ShapeGroupElement> &parent, unsigned seqNum)
29
84.9k
{
30
84.9k
  auto that = std::shared_ptr<ShapeGroupElement>(new ShapeGroupElement(parent, seqNum));
31
84.9k
  if (parent)
32
52.6k
    parent->m_children.push_back(that);
33
84.9k
  return that;
34
84.9k
}
35
36
void ShapeGroupElement::setShapeInfo(const ShapeInfo &shapeInfo)
37
81.4k
{
38
81.4k
  m_shapeInfo = shapeInfo;
39
81.4k
}
40
41
void ShapeGroupElement::setTransform(const VectorTransformation2D &transform)
42
81.4k
{
43
81.4k
  m_transform = transform;
44
81.4k
}
45
46
void ShapeGroupElement::setup(std::function<void(ShapeGroupElement &self)> visitor)
47
81.8k
{
48
81.8k
  visitor(*this);
49
81.8k
  for (auto &i : m_children)
50
50.9k
  {
51
50.9k
    i->setup(visitor);
52
50.9k
  }
53
81.8k
}
54
55
void ShapeGroupElement::visit(std::function<
56
                              std::function<void(void)>
57
                              (const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform)
58
                              > visitor, const Coordinate &relativeTo, const VectorTransformation2D &parentFoldedTransform) const
59
78.8k
{
60
78.8k
  const ShapeInfo info = m_shapeInfo.get_value_or(ShapeInfo());
61
78.8k
  Coordinate coord = info.m_coordinates.get_value_or(Coordinate());
62
78.8k
  double centerX = ((double)coord.m_xs + (double)coord.m_xe) / (2 * EMUS_IN_INCH);
63
78.8k
  double centerY = ((double)coord.m_ys + (double)coord.m_ye) / (2 * EMUS_IN_INCH);
64
78.8k
  double relativeCenterX = ((double)relativeTo.m_xs + (double)relativeTo.m_xe) / (2 * EMUS_IN_INCH);
65
78.8k
  double relativeCenterY = ((double)relativeTo.m_ys + (double)relativeTo.m_ye) / (2 * EMUS_IN_INCH);
66
78.8k
  double offsetX = centerX - relativeCenterX;
67
78.8k
  double offsetY = centerY - relativeCenterY;
68
78.8k
  VectorTransformation2D foldedTransform = VectorTransformation2D::fromTranslate(-offsetX, -offsetY)
69
78.8k
                                           * parentFoldedTransform * VectorTransformation2D::fromTranslate(offsetX, offsetY) * m_transform;
70
78.8k
  std::function<void(void)> afterOp = visitor(info, relativeTo, foldedTransform, isGroup(), m_transform);
71
78.8k
  for (const auto &i : m_children)
72
50.5k
  {
73
50.5k
    i->visit(visitor, coord, foldedTransform);
74
50.5k
  }
75
78.8k
  afterOp();
76
78.8k
}
77
78
void ShapeGroupElement::visit(std::function<
79
                              std::function<void(void)>
80
                              (const ShapeInfo &info, const Coordinate &relativeTo, const VectorTransformation2D &foldedTransform, bool isGroup, const VectorTransformation2D &thisTransform)
81
                              > visitor) const
82
28.3k
{
83
28.3k
  Coordinate origin;
84
28.3k
  VectorTransformation2D identity;
85
28.3k
  visit(visitor, origin, identity);
86
28.3k
}
87
88
bool ShapeGroupElement::isGroup() const
89
78.8k
{
90
78.8k
  return !m_children.empty();
91
78.8k
}
92
93
std::shared_ptr<ShapeGroupElement> ShapeGroupElement::getParent() const
94
21.9k
{
95
21.9k
  return m_parent.lock();
96
21.9k
}
97
98
void ShapeGroupElement::setSeqNum(unsigned seqNum)
99
21.5k
{
100
21.5k
  m_seqNum = seqNum;
101
21.5k
}
102
103
unsigned ShapeGroupElement::getSeqNum() const
104
112k
{
105
112k
  return m_seqNum;
106
112k
}
107
108
}
109
110
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */