Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: group transform for arrow heads #66

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions core/include/actsvg/core/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct stroke {
/// Nothing is written out
bool _sterile = false;

/// @brief Contructor for stroke
/// @brief Contructor for stroke
/// @param c_ the color of the stroke
/// @param w_ the with of the stroke
/// @param d_ the dashed harray of the stroke
Expand Down Expand Up @@ -258,6 +258,14 @@ struct transform {

bool _sterile = false;

/** Test if it is a identity/sterile transform */
bool is_identity() const {
return _sterile or
(_tr[0] == 0. and _tr[1] == 0. and _rot[0] == 0. and
_rot[1] == 0. and _rot[2] == 0. and _skew[0] == 0. and
_skew[1] == 0. and _scale[0] == 1. and _scale[1] == 1.);
}

/** Apply to a point
*
* @param p_ the point to be transformed
Expand Down Expand Up @@ -347,7 +355,6 @@ struct marker {
fill _fill = fill{{{0, 0, 0}}};

stroke _stroke = stroke();

};

// The axis marker types
Expand Down
10 changes: 6 additions & 4 deletions core/include/actsvg/core/svg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,12 @@ inline std::ostream &operator<<(std::ostream &os_, const object &o_) {
}

// Attach the styles: fill, stroke, transform
if (not o_._sterile and o_._tag != "g") {
if (not o_._sterile) {
o_._fill.attach_attributes(o_copy);
o_._stroke.attach_attributes(o_copy);
o_._transform.attach_attributes(o_copy);
if (not o_._transform.is_identity()) {
o_._transform.attach_attributes(o_copy);
}
}

// The attribute map
Expand Down Expand Up @@ -273,8 +275,8 @@ struct file {
* @param os_ is the vector of objects
**/
void add_objects(const std::vector<svg::object> &os_) {
// Add the objects one by one
for (const auto& o_ : os_)
// Add the objects one by one
for (const auto &o_ : os_)
if (o_._active) {
_objects.push_back(o_);
}
Expand Down
7 changes: 6 additions & 1 deletion meta/include/actsvg/display/datamodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,12 @@ static inline svg::object trajectory(const std::string& id,
for (const auto& [pos, dir] : trajectory_._path) {
points.push_back(view_.point(pos));
if (dir.has_value()) {
directions.push_back(view_.point(dir.value()));
point2 dir2 = view_.point(dir.value());
// normalize the direction
scalar norm = std::sqrt(dir2[0] * dir2[0] + dir2[1] * dir2[1]);
dir2[0] /= norm;
dir2[1] /= norm;
directions.push_back(view_.point(dir2));
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/common/helix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ inline static proto::trajectory<point3_type> generate_helix(
// Create the current position
point3_type p{x, y, z};
// Create the direction
point3_type d{-std::sin(phi), std::cos(phi), direction_[2]};
point3_type d{-std::sin(phi + phi0), std::cos(phi + phi0),
direction_[2]};
trj._path.push_back({p, d});
}
// Return the trajectory
Expand Down
1 change: 1 addition & 0 deletions tests/meta/seeds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ TEST(proto, seeds_single_xy) {
trj._origin_fill = defaults::__g_fill;
trj._origin_stroke = style::stroke{style::color{{0, 0, 0}}, 0.5};
trj._path_stroke = style::stroke{style::color{{0, 255, 0}}, 0.5};
trj._path_arrow = style::marker{"<<", 3., style::color{{0, 255, 0}}};

proto::seed<point3> seed;
scalar s0x = 30. * std::cos(0.3 * M_PI);
Expand Down
Loading