Commit d6b062f3 authored by Tavmjong Bah's avatar Tavmjong Bah
Browse files

Remove remaining uses of sp_round.

parent 72aba43e
Pipeline #84068526 passed with stages
in 134 minutes and 56 seconds
......@@ -14,12 +14,10 @@
*/
// I'm of the opinion that this file should be removed, so I will in the future take the necessary steps to wipe it out.
// Macros are not in general bad, but these particular ones are rather ugly. Especially that sp_round one. --Liam
// Macros are not in general bad, but these particular ones are rather ugly. --Liam
#define sp_signal_disconnect_by_data(o,d) g_signal_handlers_disconnect_matched(o, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, d)
#define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
// "primary" modifier: Ctrl on Linux/Windows and Cmd on macOS.
// note: Could query this at runtime with
// `gdk_keymap_get_modifier_mask(..., GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR)`
......
......@@ -25,12 +25,12 @@
#include "snap.h"
#include "style.h"
#include "include/macros.h"
#include "object/sp-hatch.h"
#include "object/sp-item.h"
#include "object/sp-namedview.h"
#include "object/sp-pattern.h"
int KnotHolderEntity::counter = 0;
void KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, Inkscape::ControlType type,
......@@ -221,7 +221,9 @@ PatternKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point const &
gdouble theta_old = atan2(knot_get() - transform_origin);
if ( state & GDK_CONTROL_MASK ) {
theta = sp_round(theta, M_PI/snaps);
/* Snap theta */
double snaps_radian = M_PI/snaps;
theta = std::round(theta/snaps_radian) * snaps_radian;
}
Geom::Affine rot = Geom::Translate(-transform_origin)
......@@ -329,7 +331,9 @@ void HatchKnotHolderEntityAngle::knot_set(Geom::Point const &p, Geom::Point cons
gdouble theta_old = atan2(knot_get() - transform_origin);
if (state & GDK_CONTROL_MASK) {
theta = sp_round(theta, M_PI / snaps);
/* Snap theta */
double snaps_radian = M_PI/snaps;
theta = std::round(theta/snaps_radian) * snaps_radian;
}
Geom::Affine rot =
......
......@@ -18,6 +18,7 @@
#include "desktop.h"
#include "knotholder.h"
#include "knot-holder-entity.h"
#include "style.h"
#include "live_effects/effect.h"
......@@ -32,9 +33,6 @@
#include "object/sp-spiral.h"
#include "object/sp-star.h"
#include "object/sp-text.h"
#include "style.h"
#include "include/macros.h"
class RectKnotHolder : public KnotHolder {
public:
......@@ -955,7 +953,8 @@ ArcKnotHolderEntityStart::knot_set(Geom::Point const &p, Geom::Point const &/*or
arc->start -= offset;
if ((state & GDK_CONTROL_MASK) && snaps) {
arc->start = sp_round(arc->start, M_PI / snaps);
double snaps_radian = M_PI/snaps;
arc->start = std::round(arc->start/snaps_radian) * snaps_radian;
}
if (state & GDK_SHIFT_MASK) {
arc->end -= offset;
......@@ -1006,7 +1005,8 @@ ArcKnotHolderEntityEnd::knot_set(Geom::Point const &p, Geom::Point const &/*orig
arc->end -= offset;
if ((state & GDK_CONTROL_MASK) && snaps) {
arc->end = sp_round(arc->end, M_PI/snaps);
double snaps_radian = M_PI/snaps;
arc->end = std::round(arc->end/snaps_radian) * snaps_radian;
}
if (state & GDK_SHIFT_MASK) {
arc->start -= offset;
......@@ -1437,7 +1437,8 @@ SpiralKnotHolderEntityInner::knot_set(Geom::Point const &p, Geom::Point const &o
&& ( fabs(spiral->revo) > SP_EPSILON_2 )
&& ( snaps != 0 ) ) {
gdouble arg = 2.0*M_PI*spiral->revo*spiral->t0 + spiral->arg;
spiral->t0 = (sp_round(arg, M_PI/snaps) - spiral->arg)/(2.0*M_PI*spiral->revo);
double snaps_radian = M_PI/snaps;
spiral->t0 = (std::round(arg/snaps_radian)*snaps_radian - spiral->arg)/(2.0*M_PI*spiral->revo);
}
spiral->t0 = CLAMP(spiral->t0, 0.0, 0.999);
......@@ -1469,9 +1470,9 @@ SpiralKnotHolderEntityOuter::knot_set(Geom::Point const &p, Geom::Point const &/
// if alt not pressed, change also rad; otherwise it is locked
spiral->rad = MAX(hypot(dx, dy), 0.001);
}
if ( ( state & GDK_CONTROL_MASK )
&& snaps ) {
spiral->arg = sp_round(spiral->arg, M_PI/snaps);
if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
double snaps_radian = M_PI/snaps;
spiral->arg = std::round(spiral->arg/snaps_radian) * snaps_radian;
}
} else { // roll/unroll
// arg of the spiral outer end
......@@ -1479,28 +1480,30 @@ SpiralKnotHolderEntityOuter::knot_set(Geom::Point const &p, Geom::Point const &/
spiral->getPolar(1, nullptr, &arg_1);
// its fractional part after the whole turns are subtracted
double arg_r = arg_1 - sp_round(arg_1, 2.0*M_PI);
static double _2PI = 2.0 * M_PI;
double arg_r = arg_1 - std::round(arg_1/_2PI) * _2PI;
// arg of the mouse point relative to spiral center
double mouse_angle = atan2(dy, dx);
if (mouse_angle < 0)
mouse_angle += 2*M_PI;
mouse_angle += _2PI;
// snap if ctrl
if ( ( state & GDK_CONTROL_MASK ) && snaps ) {
mouse_angle = sp_round(mouse_angle, M_PI/snaps);
double snaps_radian = M_PI/snaps;
mouse_angle = std::round(mouse_angle/snaps_radian) * snaps_radian;
}
// by how much we want to rotate the outer point
double diff = mouse_angle - arg_r;
if (diff > M_PI)
diff -= 2*M_PI;
diff -= _2PI;
else if (diff < -M_PI)
diff += 2*M_PI;
diff += _2PI;
// calculate the new rad;
// the value of t corresponding to the angle arg_1 + diff:
double t_temp = ((arg_1 + diff) - spiral->arg)/(2*M_PI*spiral->revo);
double t_temp = ((arg_1 + diff) - spiral->arg)/(_2PI*spiral->revo);
// the rad at that t:
double rad_new = 0;
if (t_temp > spiral->t0)
......
......@@ -33,7 +33,6 @@
#include "display/sp-canvas-item.h"
#include "display/sp-canvas.h"
#include "include/sp-round.h"
#include "include/macros.h"
#include "object/sp-namedview.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment