| Line 1... |
Line 1... |
| 1 |
/*
|
1 |
/*
|
| 2 |
* R : A Computer Language for Statistical Data Analysis
|
2 |
* R : A Computer Language for Statistical Data Analysis
|
| 3 |
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
|
- |
|
| 4 |
* Copyright (C) 1997--2014 The R Core Team
|
3 |
* Copyright (C) 1997--2018 The R Core Team
|
| 5 |
* Copyright (C) 2002--2011 The R Foundation
|
4 |
* Copyright (C) 2002--2011 The R Foundation
|
| - |
|
5 |
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
|
| 6 |
*
|
6 |
*
|
| 7 |
* This program is free software; you can redistribute it and/or modify
|
7 |
* This program is free software; you can redistribute it and/or modify
|
| 8 |
* it under the terms of the GNU General Public License as published by
|
8 |
* it under the terms of the GNU General Public License as published by
|
| 9 |
* the Free Software Foundation; either version 2 of the License, or
|
9 |
* the Free Software Foundation; either version 2 of the License, or
|
| 10 |
* (at your option) any later version.
|
10 |
* (at your option) any later version.
|
| Line 34... |
Line 34... |
| 34 |
// --> R_ext/GraphicsEngine.h + Rgraphics.h
|
34 |
// --> R_ext/GraphicsEngine.h + Rgraphics.h
|
| 35 |
#include <Rmath.h> /* eg. fmax2() */
|
35 |
#include <Rmath.h> /* eg. fmax2() */
|
| 36 |
|
36 |
|
| 37 |
static void GLPretty(double *ul, double *uh, int *n);
|
37 |
static void GLPretty(double *ul, double *uh, int *n);
|
| 38 |
|
38 |
|
| - |
|
39 |
/* used in GScale() (../library/graphics/src/graphics.c), but also in
|
| 39 |
// used in GScale(), but also grDevices/src/axis_scales.c :
|
40 |
../library/grDevices/src/axis_scales.c : */
|
| 40 |
// (usr, log, n_inp) |--> (axp, n_out) :
|
41 |
// (usr, log, n_inp) |--> (axp = (min, max), n_out) :
|
| 41 |
void GAxisPars(double *min, double *max, int *n, Rboolean log, int axis)
|
42 |
void GAxisPars(double *min, double *max, int *n, Rboolean log, int axis)
|
| 42 |
{
|
43 |
{
|
| 43 |
#define EPS_FAC_2 100
|
44 |
#define EPS_FAC_2 100
|
| 44 |
Rboolean swap = *min > *max;
|
45 |
Rboolean swap = *min > *max;
|
| 45 |
double t_, min_o, max_o;
|
46 |
double t_, min_o, max_o;
|
| Line 50... |
Line 51... |
| 50 |
/* save only for the extreme case (EPS_FAC_2): */
|
51 |
/* save only for the extreme case (EPS_FAC_2): */
|
| 51 |
min_o = *min; max_o = *max;
|
52 |
min_o = *min; max_o = *max;
|
| 52 |
|
53 |
|
| 53 |
if(log) {
|
54 |
if(log) {
|
| 54 |
/* Avoid infinities */
|
55 |
/* Avoid infinities */
|
| 55 |
if(*max > 308) *max = 308;
|
56 |
if(*max > 308) { *max = 308; if(*min > *max) *min = *max; }
|
| 56 |
if(*min < -307) *min = -307;
|
57 |
if(*min < -307) { *min = -307; if(*max < *min) *max = *min; }
|
| 57 |
*min = Rexp10(*min);
|
58 |
*min = Rexp10(*min);
|
| 58 |
*max = Rexp10(*max);
|
59 |
*max = Rexp10(*max);
|
| 59 |
GLPretty(min, max, n);
|
60 |
GLPretty(min, max, n);
|
| 60 |
}
|
61 |
}
|
| 61 |
else GEPretty(min, max, n);
|
62 |
else GEPretty(min, max, n);
|
| 62 |
|
63 |
|
| 63 |
double tmp2 = EPS_FAC_2 * DBL_EPSILON;/* << prevent overflow in product below */
|
64 |
double tmp2 = EPS_FAC_2 * DBL_EPSILON;/* << prevent overflow in product below */
|
| 64 |
if(fabs(*max - *min) < (t_ = fmax2(fabs(*max), fabs(*min)))* tmp2) {
|
65 |
if(fabs(*max - *min) < (t_ = fmax2(fabs(*max), fabs(*min)))* tmp2) {
|
| 65 |
/* Treat this case somewhat similar to the (min ~= max) case above */
|
66 |
/* Treat this case somewhat similar to the (min ~= max) case above */
|
| 66 |
/* Too much accuracy here just shows machine differences */
|
67 |
/* Too much accuracy here just shows machine differences */
|
| 67 |
warning(_("relative range of values =%4.0f * EPS, is small (axis %d)")
|
68 |
warning(_("relative range of values (%4.0f * EPS) is small (axis %d)")
|
| 68 |
/*"to compute accurately"*/,
|
69 |
/*"to compute accurately"*/,
|
| 69 |
fabs(*max - *min) / (t_*DBL_EPSILON), axis);
|
70 |
fabs(*max - *min) / (t_*DBL_EPSILON), axis);
|
| 70 |
|
71 |
|
| 71 |
/* No pretty()ing anymore */
|
72 |
/* No pretty()ing anymore */
|
| 72 |
*min = min_o;
|
73 |
*min = min_o;
|
| Line 94... |
Line 95... |
| 94 |
* __ ul < uh __
|
95 |
* __ ul < uh __
|
| 95 |
* This only does a very simple setup.
|
96 |
* This only does a very simple setup.
|
| 96 |
* The real work happens when the axis is drawn. */
|
97 |
* The real work happens when the axis is drawn. */
|
| 97 |
int p1, p2;
|
98 |
int p1, p2;
|
| 98 |
double dl = *ul, dh = *uh;
|
99 |
double dl = *ul, dh = *uh;
|
| 99 |
p1 = (int) ceil(log10(dl));
|
100 |
p1 = (int) ceil (log10(dl));
|
| 100 |
p2 = (int) floor(log10(dh));
|
101 |
p2 = (int) floor(log10(dh));
|
| 101 |
if(p2 <= p1 && dh/dl > 10.0) {
|
102 |
if(p2 <= p1 && dh/dl > 10.0) {
|
| 102 |
p1 = (int) ceil(log10(dl) - 0.5);
|
103 |
p1 = (int) ceil (log10(dl) - 0.5);
|
| 103 |
p2 = (int) floor(log10(dh) + 0.5);
|
104 |
p2 = (int) floor(log10(dh) + 0.5);
|
| 104 |
}
|
105 |
}
|
| 105 |
|
106 |
|
| 106 |
if (p2 <= p1) { /* floor(log10(uh)) <= ceil(log10(ul))
|
107 |
if (p2 <= p1) { /* floor(log10(uh)) <= ceil(log10(ul))
|
| 107 |
* <==> log10(uh) - log10(ul) < 2
|
108 |
* <==> log10(uh) - log10(ul) < 2
|