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

feat: annulus bounds with path (instead of vertices) #84

Merged
merged 1 commit into from
Aug 16, 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
68 changes: 37 additions & 31 deletions meta/include/actsvg/display/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ svg::object surface(const std::string& id_, const surface_type& s_,

// Surface directly
if (s_._type == surface_type::type::e_annulus) {

// Special annulus bounds code
scalar min_r = s_._measures[0];
scalar max_r = s_._measures[1];
Expand All @@ -98,28 +97,50 @@ svg::object surface(const std::string& id_, const surface_type& s_,
annulusCircleIx(origin_x, origin_y, max_r, min_phi_rel);
auto out_left_s_xy =
annulusCircleIx(origin_x, origin_y, max_r, max_phi_rel);

point2 translation = {0., 0.};
if (s_._surface_transform.has_value()) {
const auto& srot = s_._surface_transform.value()._rotation;
scalar alpha = std::acos(srot[0][0]);
if (srot[1][0] < 0) {
alpha = -alpha;
}
in_left_s_xy = utils::rotate(in_left_s_xy, alpha);
in_right_s_xy = utils::rotate(in_right_s_xy, alpha);
out_right_s_xy = utils::rotate(out_right_s_xy, alpha);
out_left_s_xy = utils::rotate(out_left_s_xy, alpha);

const auto& str = s_._surface_transform.value()._translation;
translation = {str[0], str[1]};
in_left_s_xy = utils::add<point2, 2u>(in_left_s_xy, translation);
in_right_s_xy = utils::add<point2, 2u>(in_right_s_xy, translation);
out_right_s_xy =
utils::add<point2, 2u>(out_right_s_xy, translation);
out_left_s_xy = utils::add<point2, 2u>(out_left_s_xy, translation);
}

// For drawing, this needs a shift
scalar irx = in_right_s_xy[0] - origin_x;
scalar iry = in_right_s_xy[1] - origin_y;
scalar ilx = in_left_s_xy[0] - origin_x;
scalar ily = in_left_s_xy[1] - origin_y;
scalar orx = out_right_s_xy[0] - origin_x;
scalar ory = out_right_s_xy[1] - origin_y;
scalar olx = out_left_s_xy[0] - origin_x;
scalar oly = out_left_s_xy[1] - origin_y;
scalar irx = in_right_s_xy[0];
scalar iry = in_right_s_xy[1];
scalar ilx = in_left_s_xy[0];
scalar ily = in_left_s_xy[1];
scalar orx = out_right_s_xy[0];
scalar ory = out_right_s_xy[1];
scalar olx = out_left_s_xy[0];
scalar oly = out_left_s_xy[1];
// Dedicated path drawing of the annulus bounds
s._tag = "path";
s._id = id_;
std::string path =
"M " + std::to_string(irx) + " " + std::to_string(-iry);
"M " + std::to_string(irx) + " " + std::to_string(iry);
path += " A " + std::to_string(min_r) + " " + std::to_string(min_r);
path += " 0 0 0 ";
path += std::to_string(ilx) + " " + std::to_string(-ily);
path += " L " + std::to_string(olx) + " " + std::to_string(-oly);
path += " A " + std::to_string(max_r) + " " + std::to_string(max_r);
path += " 0 0 1 ";
path += std::to_string(orx) + " " + std::to_string(-ory);
path += " L " + std::to_string(irx) + " " + std::to_string(-iry);
path += std::to_string(ilx) + " " + std::to_string(ily);
path += " L " + std::to_string(olx) + " " + std::to_string(oly);
path += " A " + std::to_string(max_r) + " " + std::to_string(max_r);
path += " 0 0 0 ";
path += std::to_string(orx) + " " + std::to_string(ory);
path += " L " + std::to_string(irx) + " " + std::to_string(iry);
s._attribute_map["d"] = path;
s._fill = s_._fill;
s._stroke = s_._stroke;
Expand All @@ -130,7 +151,6 @@ svg::object surface(const std::string& id_, const surface_type& s_,
}

if (o_._label_measures) {

// make a copy & a group out of the object
auto sc = s;
s = svg::object{};
Expand Down Expand Up @@ -164,20 +184,6 @@ svg::object surface(const std::string& id_, const surface_type& s_,
s.add_object(line);
}
}

// Package into a translated group if we have a surfade transform
if (s_._surface_transform.has_value()) {
const auto& sfg = s_._surface_transform.value();
if (sfg._translation[0] != 0. || sfg._translation[1] != 0.) {
auto tg = s;
s = svg::object{};
s._id = id_ + "_translated";
s._tag = "g";
s._transform._tr = {-sfg._translation[0], sfg._translation[1]};
s.add_object(tg);
}
}

} else if (s_._type == surface_type::type::e_disc) {

// x-y view for discs
Expand Down
9 changes: 0 additions & 9 deletions python/src/proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,6 @@ void add_proto_module(context& ctx) {
// Set the predefined transform
sf._surface_transform =
surface::transform3{translation, rotation};
// Only x, y view will be transformed correctly
point3 sfx = rotation[0];
// Force the translation of the transofrm to 0
sf._transform._tr = {0., 0.};
scalar alpha = std::acos(sfx[0]) / M_PI * 180;
if (sfx[1] < 0.) {
alpha += 180.;
}
sf._transform._rot = {alpha, 0., 0.};
}
sf._fill = f;
sf._stroke = s;
Expand Down
Loading