Project

General

Profile

Feature #4358 » 0003-Upgrade-precision-of-AbstractArea-subclasses.patch

Bruce Toll, 07/29/2015 01:42 AM

View differences:

src/Wt/Chart/WCartesianChart.C
p = t.map(hv(p));
WCircleArea *circleArea
= new WCircleArea(static_cast<int>(p.x()),
static_cast<int>(p.y()), 5);
WCircleArea *circleArea = new WCircleArea();
circleArea->setCenter(WPointF(p.x(), p.y()));
circleArea->setRadius(5);
circleArea->setToolTip(asString(toolTip));
const_cast<WCartesianChart&>(chart_)
src/Wt/WCircleArea
int radius() const { return r_; }
private:
int x_, y_, r_;
double x_, y_, r_;
protected:
virtual bool updateDom(DomElement& element, bool all);
src/Wt/WCircleArea.C
#include "Wt/WPointF"
#include "DomElement.h"
#include "WebUtils.h"
namespace Wt {
......
void WCircleArea::setCenter(const WPointF& point)
{
setCenter(static_cast<int>(point.x()),
static_cast<int>(point.y()));
x_ = point.x();
y_ = point.y();
repaint();
}
void WCircleArea::setCenter(int x, int y)
......
element.setAttribute("shape", "circle");
std::stringstream coords;
coords << x_ << ',' << y_ << ',' << r_;
coords << static_cast<int>(x_) << ','
<< static_cast<int>(y_) << ','
<< static_cast<int>(r_);
element.setAttribute("coords", coords.str());
return WAbstractArea::updateDom(element, all);
......
std::string WCircleArea::updateAreaCoordsJS()
{
std::stringstream coords;
char buf[30];
coords << "[" << jsRef() << ",["
<< x_ << ',' << y_ << ',' << r_ << "]]";
coords << "[" << jsRef() << ",[";
coords << Utils::round_js_str(x_, 2, buf) << ',';
coords << Utils::round_js_str(y_, 2, buf) << ',';
coords << Utils::round_js_str(r_, 2, buf) << "]]";
return coords.str();
}
src/Wt/WPolygonArea
/*! \brief Returns the polygon vertices.
*
* \sa setPoints()
* \sa setPoints(), points()
*/
const std::vector<WPoint>& points() const { return points_; }
const std::vector<WPointF>& pointFs() const { return points_; }
/*! \brief Returns the polygon vertices.
*
* \sa setPoints(), pointFs()
*/
const std::vector<WPoint>& points() const;
private:
std::vector<WPoint> points_;
std::vector<WPointF> points_;
mutable std::vector<WPoint> pointsIntCompatibility_;
protected:
virtual bool updateDom(DomElement& element, bool all);
src/Wt/WPolygonArea.C
#include "Wt/WPointF"
#include "DomElement.h"
#include "WebUtils.h"
namespace Wt {
......
{ }
WPolygonArea::WPolygonArea(const std::vector<WPoint>& points)
: points_(points)
{ }
#ifndef WT_TARGET_JAVA
WPolygonArea::WPolygonArea(const std::vector<WPointF>& points)
{
setPoints(points);
}
#ifndef WT_TARGET_JAVA
WPolygonArea::WPolygonArea(const std::vector<WPointF>& points)
: points_(points)
{ }
#endif // WT_TARGET_JAVA
void WPolygonArea::addPoint(int x, int y)
{
points_.push_back(WPoint(x, y));
points_.push_back(WPointF(x, y));
repaint();
}
void WPolygonArea::addPoint(double x, double y)
{
points_.push_back(WPoint(static_cast<int>(x), static_cast<int>(y)));
points_.push_back(WPointF(x, y));
repaint();
}
void WPolygonArea::addPoint(const WPoint& point)
{
points_.push_back(point);
points_.push_back(WPointF(point.x(), point.y()));
repaint();
}
void WPolygonArea::addPoint(const WPointF& point)
{
points_.push_back(WPoint(static_cast<int>(point.x()),
static_cast<int>(point.y())));
points_.push_back(point);
repaint();
}
void WPolygonArea::setPoints(const std::vector<WPoint>& points)
{
points_ = points;
points_.clear();
for (unsigned i = 0; i < points.size(); ++i)
addPoint(points[i]);
repaint();
}
......
#ifndef WT_TARGET_JAVA
void WPolygonArea::setPoints(const std::vector<WPointF>& points)
{
points_.clear();
for (unsigned i = 0; i < points.size(); ++i)
addPoint(points[i]);
points_ = points;
}
#endif // WT_TARGET_JAVA
......
for (unsigned i = 0; i < points_.size(); ++i) {
if (i != 0)
coords << ',';
coords << points_[i].x() << ',' << points_[i].y();
coords << static_cast<int>(points_[i].x()) << ','
<< static_cast<int>(points_[i].y());
}
element.setAttribute("coords", coords.str());
......
std::string WPolygonArea::updateAreaCoordsJS()
{
std::stringstream coords;
char buf[30];
coords << "[" << jsRef() << ",[";
for (unsigned i = 0; i < points_.size(); ++i) {
if (i != 0)
coords << ',';
coords << points_[i].x() << ',' << points_[i].y();
coords << Utils::round_js_str(points_[i].x(), 2, buf) << ',';
coords << Utils::round_js_str(points_[i].y(), 2, buf);
}
coords << "]]";
return coords.str();
}
/*
* NOTE: points() does not receive updates, unlike pointsF()
*/
const std::vector<WPoint>& WPolygonArea::points() const
{
pointsIntCompatibility_.clear();
for (unsigned i = 0; i < points_.size(); ++i)
pointsIntCompatibility_.push_back(WPoint(points_[i].x(), points_[i].y()));
return pointsIntCompatibility_;
}
}
src/Wt/WRectArea
int height() const { return height_; }
private:
int x_, y_, width_, height_;
double x_, y_, width_, height_;
protected:
virtual bool updateDom(DomElement& element, bool all);
src/Wt/WRectArea.C
#include "Wt/WRectArea"
#include "DomElement.h"
#include "WebUtils.h"
namespace Wt {
......
{ }
WRectArea::WRectArea(double x, double y, double width, double height)
: x_(static_cast<int>(x)),
y_(static_cast<int>(y)),
width_(static_cast<int>(width)),
height_(static_cast<int>(height))
: x_(x),
y_(y),
width_(width),
height_(height)
{ }
WRectArea::WRectArea(const WRectF& rect)
: x_(static_cast<int>(rect.x())),
y_(static_cast<int>(rect.y())),
width_(static_cast<int>(rect.width())),
height_(static_cast<int>(rect.height()))
: x_(rect.x()),
y_(rect.y()),
width_(rect.width()),
height_(rect.height())
{ }
void WRectArea::setX(int x)
......
std::stringstream coords;
if (x_ == 0 && y_ == 0 && width_ == 0 && height_ == 0)
int x = x_;
int y = y_;
int width = width_;
int height = height_;
if (x == 0 && y == 0 && width == 0 && height == 0)
coords << "0%,0%,100%,100%";
else
coords << x_ << ',' << y_ << ',' << (x_ + width_) << ',' << (y_ + height_);
coords << x << ',' << y << ',' << (x + width) << ',' << (y + height);
element.setAttribute("coords", coords.str());
return WAbstractArea::updateDom(element, all);
......
std::string WRectArea::updateAreaCoordsJS()
{
std::stringstream coords;
char buf[30];
coords << "[" << jsRef() << ",["
<< x_ << ',' << y_ << ',' << (x_ + width_) << ',' << (y_ + height_) << "]]";
coords << "[" << jsRef() << ",[";
coords << Utils::round_js_str(x_, 2, buf) << ',';
coords << Utils::round_js_str(y_, 2, buf) << ',';
coords << Utils::round_js_str((x_ + width_), 2, buf) << ',';
coords << Utils::round_js_str((y_ + height_), 2, buf) << "]]";
return coords.str();
}
(3-3/5)