Commit 4b2119d4 authored by Ole Streicher's avatar Ole Streicher

New upstream version 3.2.17

parent 6c3a3773
......@@ -5152,7 +5152,7 @@ tkbltVector.C
fi
PKG_SOURCES="$PKG_SOURCES $i"
# this assumes it is in a VPATH dir
# i=`basename $i`
i=`basename $i`
# handle user calling this before or after TEA_SETUP_COMPILER
if test x"${OBJEXT}" != x ; then
j="`echo $i | sed -e 's/\.[^.]*$//'`.${OBJEXT}"
......
......@@ -1129,7 +1129,7 @@ double Axis::invVMap(double y)
double Axis::hMap(double x)
{
AxisOptions* ops = (AxisOptions*)ops_;
if (ops->logScale) {
if ((ops->logScale) && (x != 0.0)) {
x = log10(fabs(x));
}
/* Map graph coordinate to normalized coordinates [0..1] */
......@@ -1143,7 +1143,7 @@ double Axis::hMap(double x)
double Axis::vMap(double y)
{
AxisOptions* ops = (AxisOptions*)ops_;
if (ops->logScale) {
if ((ops->logScale) && (y != 0.0)) {
y = log10(fabs(y));
}
/* Map graph coordinate to normalized coordinates [0..1] */
......
......@@ -588,6 +588,8 @@ int AxisTypeOp(Axis* axisPtr, Tcl_Interp* interp,
case CID_AXIS_Y:
typeName = "y";
break;
default:
return TCL_OK;
}
}
......
......@@ -1427,6 +1427,71 @@ void LineElement::mergePens(LineStyle **styleMap)
}
}
#define CLIP_TOP (1<<0)
#define CLIP_BOTTOM (1<<1)
#define CLIP_RIGHT (1<<2)
#define CLIP_LEFT (1<<3)
int LineElement::outCode(Region2d *extsPtr, Point2d *p)
{
int code =0;
if (p->x > extsPtr->right)
code |= CLIP_RIGHT;
else if (p->x < extsPtr->left)
code |= CLIP_LEFT;
if (p->y > extsPtr->bottom)
code |= CLIP_BOTTOM;
else if (p->y < extsPtr->top)
code |= CLIP_TOP;
return code;
}
int LineElement::clipSegment(Region2d *extsPtr, int code1, int code2,
Point2d *p, Point2d *q)
{
int inside = ((code1 | code2) == 0);
int outside = ((code1 & code2) != 0);
/*
* In the worst case, we'll clip the line segment against each of the four
* sides of the bounding rectangle.
*/
while ((!outside) && (!inside)) {
if (code1 == 0) {
Point2d *tmp;
int code;
/* Swap pointers and out codes */
tmp = p, p = q, q = tmp;
code = code1, code1 = code2, code2 = code;
}
if (code1 & CLIP_LEFT) {
p->y += (q->y - p->y) *
(extsPtr->left - p->x) / (q->x - p->x);
p->x = extsPtr->left;
} else if (code1 & CLIP_RIGHT) {
p->y += (q->y - p->y) *
(extsPtr->right - p->x) / (q->x - p->x);
p->x = extsPtr->right;
} else if (code1 & CLIP_BOTTOM) {
p->x += (q->x - p->x) *
(extsPtr->bottom - p->y) / (q->y - p->y);
p->y = extsPtr->bottom;
} else if (code1 & CLIP_TOP) {
p->x += (q->x - p->x) *
(extsPtr->top - p->y) / (q->y - p->y);
p->y = extsPtr->top;
}
code1 = outCode(extsPtr, p);
inside = ((code1 | code2) == 0);
outside = ((code1 & code2) != 0);
}
return (!inside);
}
void LineElement::saveTrace(int start, int length, MapInfo* mapPtr)
{
bltTrace* tracePtr = new bltTrace;
......@@ -1479,18 +1544,24 @@ void LineElement::mapTraces(MapInfo *mapPtr)
graphPtr_->extents(&exts);
int count = 1;
int code1 = outCode(&exts, mapPtr->screenPts);
Point2d* p = mapPtr->screenPts;
Point2d* q = p + 1;
int start;
int ii;
for (ii=1; ii<mapPtr->nScreenPts; ii++, p++, q++) {
// Save the coordinates of the last point before clipping.
Point2d originalq = *q;
int broken = BROKEN_TRACE(ops->penDir, p->x, q->x);
LineRectClipResult clipresult = lineRectClip(&exts, p, q);
Point2d s;
s.x = 0;
s.y = 0;
int code2 = outCode(&exts, q);
// Save the coordinates of the last point, before clipping
if (code2 != 0)
s = *q;
if (broken || clipresult == CLIP_OUTSIDE) {
int broken = BROKEN_TRACE(ops->penDir, p->x, q->x);
int offscreen = clipSegment(&exts, code1, code2, p, q);
if (broken || offscreen) {
// The last line segment is either totally clipped by the plotting
// area or the x-direction is wrong, breaking the trace. Either
// way, save information about the last trace (if one exists),
......@@ -1508,13 +1579,14 @@ void LineElement::mapTraces(MapInfo *mapPtr)
// If the last point is clipped, this means that the trace is
// broken after this point. Restore the original coordinate
// (before clipping) after saving the trace.
if (clipresult & CLIP_Q) {
if (code2 != 0) {
start = ii - (count - 1);
saveTrace(start, count, mapPtr);
mapPtr->screenPts[ii] = originalq;
mapPtr->screenPts[ii] = s;
count = 1;
}
}
code1 = code2;
}
if (count > 1) {
start = ii - count;
......
......@@ -275,7 +275,7 @@ static int DeleteOp(ClientData clientData, Tcl_Interp* interp,
Tcl_AppendResult(interp, "can't find markers in \"",
Tk_PathName(graphPtr->tkwin_), "\":", NULL);
}
Tcl_AppendResult(interp, " ", Tcl_GetString(objv[ii]));
Tcl_AppendResult(interp, " ", Tcl_GetString(objv[ii]), NULL);
res = TCL_ERROR;
} else {
markerPtr = (Marker*)Tcl_GetHashValue(hPtr);
......
......@@ -39,7 +39,6 @@
#include "tkbltGraph.h"
#include "tkbltGrMisc.h"
#include "tkbltInt.h"
using namespace Blt;
......@@ -71,63 +70,6 @@ int Blt::pointInPolygon(Point2d *s, Point2d *points, int nPoints)
return (count & 0x01);
}
/*
*---------------------------------------------------------------------------
* Clips a rectangle in one direction where some of the coordinates are
* infinite.
*---------------------------------------------------------------------------
*/
static LineRectClipResult ClipInfinity (double *pa, double *pb, double *qa, double *qb, double region_min, double region_max)
{
int finitepa = isfinite(*pa);
int finiteqa = isfinite(*qa);
if (!finitepa) {
if (finiteqa) {
if (*pa > 0) { // +Inf
*pa = region_max;
} else if (*pa < 0) { // -Inf
*pa = region_min;
} else { // NaN
return CLIP_OUTSIDE;
}
// *qa is finite, simplify to zero slope at *pb.
*pb = *qb;
return CLIP_P;
} else { // Both infinite.
int positivepa = *pa > 0;
int positiveqa = *qa > 0;
if (positivepa < positiveqa) { // (p,q) ~ (-Inf,Inf)
*pa = region_min;
*qa = region_max;
} else if (positivepa > positiveqa) { // (p,q) ~ (Inf,-Inf)
*pa = region_max;
*qa = region_min;
} else { // (Inf,Inf), (-Inf,-Inf) or NaN.
return CLIP_OUTSIDE;
}
// At opposite infinities; simplify to zero slope in the middle.
*pb = *qb = (*pb + *qb) / 2.0;
return CLIP_P | CLIP_Q;
}
} else if (!finiteqa) {
// *pa is finite.
if (*qa > 0) { // +Inf
*qa = region_max;
} else if (*qa < 0) { // -Inf
*qa = region_min;
} else { // NaN
return CLIP_OUTSIDE;
}
// *pa is finite, simplify to zero slope at *qb.
*qb = *pb;
return CLIP_Q;
}
return CLIP_OUTSIDE;
}
static int ClipTest (double ds, double dr, double *t1, double *t2)
{
double t;
......@@ -135,7 +77,7 @@ static int ClipTest (double ds, double dr, double *t1, double *t2)
if (ds < 0.0) {
t = dr / ds;
if (t > *t2) {
return 0; /* Line is outside clipping edge */
return 0;
}
if (t > *t1) {
*t1 = t;
......@@ -143,7 +85,7 @@ static int ClipTest (double ds, double dr, double *t1, double *t2)
} else if (ds > 0.0) {
t = dr / ds;
if (t < *t1) {
return 0; /* Line is outside clipping edge */
return 0;
}
if (t < *t2) {
*t2 = t;
......@@ -163,47 +105,35 @@ static int ClipTest (double ds, double dr, double *t1, double *t2)
* of the clipped line segment are returned. The original coordinates
* are overwritten.
*
* The return value indicates whether the line was completely outside of
* the region, returning CLIP_OUTSIDE; or at least partly inside, returning
* CLIP_INSIDE. In the latter case, the result might be or'ed with CLIP_P
* if p coordinates were clipped, or CLIP_Q if q coordinates were.
*
* Reference:
* Liang, Y-D., and B. Barsky, A new concept and method for
* Line Clipping, ACM, TOG,3(1), 1984, pp.1-22.
*---------------------------------------------------------------------------
*/
LineRectClipResult Blt::lineRectClip(Region2d* regionPtr, Point2d *p, Point2d *q)
int Blt::lineRectClip(Region2d* regionPtr, Point2d *p, Point2d *q)
{
double t1, t2;
double dx, dy;
LineRectClipResult res = CLIP_OUTSIDE;
res |= ClipInfinity(&p->x, &p->y, &q->x, &q->y, regionPtr->bottom, regionPtr->top);
t1 = 0.0, t2 = 1.0;
dx = q->x - p->x;
if ((ClipTest (-dx, p->x - regionPtr->left, &t1, &t2)) &&
(ClipTest (dx, regionPtr->right - p->x, &t1, &t2))) {
res |= ClipInfinity(&p->y, &p->x, &q->y, &q->x, regionPtr->top, regionPtr->bottom);
dy = q->y - p->y;
if ((ClipTest (-dy, p->y - regionPtr->top, &t1, &t2)) &&
(ClipTest (dy, regionPtr->bottom - p->y, &t1, &t2))) {
if (t2 < 1.0) {
q->x = p->x + t2 * dx;
q->y = p->y + t2 * dy;
res |= CLIP_Q;
}
if (t1 > 0.0) {
p->x += t1 * dx;
p->y += t1 * dy;
res |= CLIP_P;
}
return res | CLIP_INSIDE;
return 1;
}
}
return CLIP_OUTSIDE;
return 0;
}
/*
......
......@@ -104,26 +104,6 @@ namespace Blt {
int offset;
} Dashes;
typedef enum {
CLIP_OUTSIDE = 0,
CLIP_INSIDE = 1 << 0,
CLIP_P = 1 << 1,
CLIP_Q = 1 << 2
} LineRectClipResult;
inline LineRectClipResult operator|(LineRectClipResult a, LineRectClipResult b) {
return static_cast<LineRectClipResult>(static_cast<int>(a) | static_cast<int>(b));
}
inline LineRectClipResult operator&(LineRectClipResult a, LineRectClipResult b) {
return static_cast<LineRectClipResult>(static_cast<int>(a) & static_cast<int>(b));
}
inline LineRectClipResult & operator|=(LineRectClipResult & rhs, LineRectClipResult v) {
rhs = rhs | v;
return rhs;
}
extern char* dupstr(const char*);
extern Graph* getGraphFromWindowData(Tk_Window tkwin);
......@@ -131,7 +111,7 @@ namespace Blt {
int nScreenPts);
extern int polyRectClip(Region2d *extsPtr, Point2d *inputPts,
int nInputPts, Point2d *outputPts);
extern LineRectClipResult lineRectClip(Region2d *regionPtr, Point2d *p, Point2d *q);
extern int lineRectClip(Region2d *regionPtr, Point2d *p, Point2d *q);
extern Point2d getProjection (int x, int y, Point2d *p, Point2d *q);
};
......
......@@ -161,10 +161,10 @@ void PSOutput::computeBBox(int width, int height)
vSize + vBorder;
// Scale the plot size if it's bigger than the paper
double hScale = (hSize+hBorder) > paperWidth ? 1.0 :
paperWidth - hBorder / hSize;
double vScale = (vSize + vBorder) > paperHeight ? 1.0 :
paperHeight - vBorder / vSize;
double hScale = (hSize+hBorder)>paperWidth ? (paperWidth-hBorder)/hSize
: 1.0;
double vScale = (vSize+vBorder)>paperHeight ? (paperHeight-vBorder)/vSize
: 1.0;
double scale = MIN(hScale, vScale);
if (scale != 1.0) {
......
......@@ -2836,7 +2836,7 @@ AC_DEFUN([TEA_ADD_SOURCES], [
fi
PKG_SOURCES="$PKG_SOURCES $i"
# this assumes it is in a VPATH dir
# i=`basename $i`
i=`basename $i`
# handle user calling this before or after TEA_SETUP_COMPILER
if test x"${OBJEXT}" != x ; then
j="`echo $i | sed -e 's/\.[[^.]]*$//'`.${OBJEXT}"
......
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