@@ -45,7 +45,10 @@ MeasureAxis::MeasureAxis(Math::Range<double> interval,
4545 origMeasureName (std::string{measName}),
4646 step (step ? *step : Math::Renard::R5().ceil(range.size() / 5.0 ))
4747{
48- if (std::signbit (this ->step ->value ) != std::signbit (range.size ()))
48+ if (Math::Floating::is_zero (range.size ()))
49+ this ->step ->value = 0 ;
50+ else if (std::signbit (this ->step ->value )
51+ != std::signbit (range.size ()))
4952 this ->step ->value *= -1 ;
5053}
5154
@@ -79,46 +82,59 @@ MeasureAxis interpolate(const MeasureAxis &op0,
7982 const auto s0 = op0.range .size ();
8083 const auto s1 = op1.range .size ();
8184
82- const auto s0Inv = is_zero (s0) ? MAX : 1 / s0;
83- const auto s1Inv = is_zero (s1) ? MAX : 1 / s1;
84-
85- const auto interp = Math::interpolate (s0Inv, s1Inv, factor);
86-
87- const auto s = is_zero (interp) ? MAX : 1 / interp;
88-
89- res.range = Math::Range<double >::Raw (
90- Math::interpolate (op0.range .getMin () * s0Inv,
91- op1.range .getMin () * s1Inv,
92- factor)
93- * s,
94- Math::interpolate (op0.range .getMax () * s0Inv,
95- op1.range .getMax () * s1Inv,
96- factor)
97- * s);
98-
99- auto step = Math::interpolate (op0.step .get () * s0Inv,
100- op1.step .get () * s1Inv,
101- factor)
102- * s;
103-
104- if (auto op0sign = std::signbit (op0.step .get ());
105- op0sign == std::signbit (op1.step .get ()))
106- res.step = interpolate (op0.step ,
107- op1.step ,
108- Math::Range<double >::Raw (op0.step .get (),
109- op1.step .get ())
110- .rescale (step));
111- else if (auto max = std::copysign (MAX, step);
112- op0sign == std::signbit (step))
113- res.step = interpolate (op0.step ,
114- Anim::Interpolated{max},
115- Math::Range<double >::Raw (op0.step .get (), max)
116- .rescale (step));
117- else
118- res.step = interpolate (op1.step ,
119- Anim::Interpolated{max},
120- Math::Range<double >::Raw (op1.step .get (), max)
121- .rescale (step));
85+ if (auto s0Zero = is_zero (s0); s0Zero || is_zero (s1)) {
86+ res.range = Math::Range<double >::Raw (
87+ Math::interpolate (op0.range .getMin (),
88+ op1.range .getMin (),
89+ factor),
90+ Math::interpolate (op0.range .getMax (),
91+ op1.range .getMax (),
92+ factor));
93+ res.step = s0Zero ? op1.step : op0.step ;
94+ }
95+ else {
96+ auto s0Inv = 1 / s0;
97+ auto s1Inv = 1 / s1;
98+
99+ const auto interp =
100+ Math::interpolate (s0Inv, s1Inv, factor);
101+
102+ const auto s = is_zero (interp) ? MAX : 1 / interp;
103+
104+ res.range = Math::Range<double >::Raw (
105+ Math::interpolate (op0.range .getMin () * s0Inv,
106+ op1.range .getMin () * s1Inv,
107+ factor)
108+ * s,
109+ Math::interpolate (op0.range .getMax () * s0Inv,
110+ op1.range .getMax () * s1Inv,
111+ factor)
112+ * s);
113+
114+ auto step = Math::interpolate (op0.step .get () * s0Inv,
115+ op1.step .get () * s1Inv,
116+ factor)
117+ * s;
118+
119+ if (auto op0sign = std::signbit (op0.step .get ());
120+ op0sign == std::signbit (op1.step .get ()))
121+ res.step = interpolate (op0.step ,
122+ op1.step ,
123+ Math::Range<double >::Raw (op0.step .get (),
124+ op1.step .get ())
125+ .rescale (step));
126+ else if (auto max = std::copysign (MAX, step);
127+ op0sign == std::signbit (step))
128+ res.step = interpolate (op0.step ,
129+ Anim::Interpolated{max},
130+ Math::Range<double >::Raw (op0.step .get (), max)
131+ .rescale (step));
132+ else
133+ res.step = interpolate (op1.step ,
134+ Anim::Interpolated{max},
135+ Math::Range<double >::Raw (op1.step .get (), max)
136+ .rescale (step));
137+ }
122138
123139 res.unit = interpolate (op0.unit , op1.unit , factor);
124140 }
0 commit comments