Mercurial > hg > octave-max
comparison src/graphics.h.in @ 13756:6dfebfa334cb
allow negative data log plots with OpenGL+FLTK graphics (bug #34232)
* mx-inlines.cc (mx_inline_any_positive): New function.
* lo-mappers.h (xpositive_sign (double), xpositive_sign (float)):
New functions.
* fNDArray.h, fNDArray.cc (FloatNDArray::any_element_is_positive):
New function.
* fMatrix.h, fMatrix.cc (FloatMatrix::any_element_is_positive):
New function.
* dNDArray.h, dNDArray.cc (NDArray::any_element_is_positive):
New function.
* dMatrix.h, dMatrix.cc (Matrix::any_element_is_positive):
New function.
* graphics.h.in (log_scaler::do_neg_scale): New function.
(log_scaler::scale (const Matrix&) const,
log_scaler::scale (const NDArray&) const): Call do_neg_scale if no
array elements are positive.
* graphics.cc (axes::properties::get_axis_limits): Omit zero from
positive values for log plots. Correctly widen range for all negative
log plots.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 26 Oct 2011 14:19:54 -0400 |
parents | ecff4c684b89 |
children | 760e4e88dba3 |
comparison
equal
deleted
inserted
replaced
13755:8cd08124cb59 | 13756:6dfebfa334cb |
---|---|
219 | 219 |
220 Matrix scale (const Matrix& m) const | 220 Matrix scale (const Matrix& m) const |
221 { | 221 { |
222 Matrix retval (m.rows (), m.cols ()); | 222 Matrix retval (m.rows (), m.cols ()); |
223 | 223 |
224 do_scale (m.data (), retval.fortran_vec (), m.numel ()); | 224 if (m.any_element_is_positive ()) |
225 do_scale (m.data (), retval.fortran_vec (), m.numel ()); | |
226 else | |
227 do_neg_scale (m.data (), retval.fortran_vec (), m.numel ()); | |
228 | |
225 return retval; | 229 return retval; |
226 } | 230 } |
227 | 231 |
228 NDArray scale (const NDArray& m) const | 232 NDArray scale (const NDArray& m) const |
229 { | 233 { |
230 NDArray retval (m.dims ()); | 234 NDArray retval (m.dims ()); |
231 | 235 |
232 do_scale (m.data (), retval.fortran_vec (), m.numel ()); | 236 if (m.any_element_is_positive ()) |
237 do_scale (m.data (), retval.fortran_vec (), m.numel ()); | |
238 else | |
239 do_neg_scale (m.data (), retval.fortran_vec (), m.numel ()); | |
240 | |
233 return retval; | 241 return retval; |
234 } | 242 } |
235 | 243 |
236 double scale (double d) const | 244 double scale (double d) const |
237 { return log10 (d); } | 245 { return log10 (d); } |
245 private: | 253 private: |
246 void do_scale (const double *src, double *dest, int n) const | 254 void do_scale (const double *src, double *dest, int n) const |
247 { | 255 { |
248 for (int i = 0; i < n; i++) | 256 for (int i = 0; i < n; i++) |
249 dest[i] = log10(src[i]); | 257 dest[i] = log10(src[i]); |
258 } | |
259 | |
260 void do_neg_scale (const double *src, double *dest, int n) const | |
261 { | |
262 for (int i = 0; i < n; i++) | |
263 dest[i] = -log10(-src[i]); | |
250 } | 264 } |
251 }; | 265 }; |
252 | 266 |
253 class scaler | 267 class scaler |
254 { | 268 { |