Make Vector2D's default constructor initialize to the invalid value rather than a seemingly valid value. Fixes a few cases where uninitialized vectors were used as if they were initialized.

Originally committed to SVN as r5987.
This commit is contained in:
Thomas Goyne 2011-12-06 23:13:06 +00:00
parent f48c2a444d
commit c0cfe8afce
9 changed files with 18 additions and 20 deletions

View file

@ -98,7 +98,7 @@ void Spline::DecodeFromASS(wxString str) {
// Prepare
char command = 'm';
Vector2D pt;
Vector2D pt(0, 0);
// Tokenize the string
wxStringTokenizer tkn(str, " ");

View file

@ -62,7 +62,7 @@ public:
/// DOCME
CurveType type;
SplineCurve(Vector2D p1 = Vector2D());
SplineCurve(Vector2D p1 = Vector2D(0, 0));
SplineCurve(Vector2D p1, Vector2D p2);
SplineCurve(Vector2D p1, Vector2D p2, Vector2D p3, Vector2D p4);

View file

@ -31,6 +31,12 @@
#include <wx/numformatter.h>
#endif
Vector2D::Vector2D()
: x(std::numeric_limits<float>::min())
, y(std::numeric_limits<float>::min())
{
}
Vector2D operator *(float f, Vector2D v) {
return Vector2D(v.X() * f, v.Y() * f);
}
@ -74,11 +80,7 @@ Vector2D Vector2D::Round(float step) const {
}
Vector2D::operator unspecified_bool_type() const {
return *this == Bad() ? 0 : &Vector2D::x;
}
Vector2D Vector2D::Bad() {
return Vector2D(std::numeric_limits<float>::min(), std::numeric_limits<float>::min());
return *this == Vector2D() ? 0 : &Vector2D::x;
}
wxString Vector2D::PStr(char sep) const {

View file

@ -42,7 +42,7 @@ public:
float X() const { return x; }
float Y() const { return y; }
Vector2D() : x(0), y(0) { }
Vector2D();
Vector2D(float x, float y) : x(x), y(y) { }
Vector2D(wxPoint pt) : x(pt.x), y(pt.y) { }
Vector2D(Vector2D x, Vector2D y) : x(x.x), y(y.y) { }
@ -87,7 +87,6 @@ public:
wxString DStr(char sep = ',') const;
static Vector2D FromAngle(float angle) { return Vector2D(cos(-angle), sin(-angle)); }
static Vector2D Bad();
};
Vector2D operator * (float f, Vector2D v);

View file

@ -98,7 +98,6 @@ VideoDisplay::VideoDisplay(
, con(c)
, w(8)
, h(8)
, mouse_pos(Vector2D::Bad())
, viewport_left(0)
, viewport_width(0)
, viewport_bottom(0)
@ -353,7 +352,7 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
}
void VideoDisplay::OnMouseLeave(wxMouseEvent& event) {
mouse_pos = Vector2D::Bad();
mouse_pos = Vector2D();
tool->OnMouseEvent(event);
}

View file

@ -40,9 +40,7 @@
#include "visual_feature.h"
VisualDraggableFeature::VisualDraggableFeature()
: start(Vector2D::Bad())
, type(DRAG_NONE)
, pos(Vector2D::Bad())
: type(DRAG_NONE)
, layer(0)
, line(0)
{

View file

@ -192,7 +192,7 @@ void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
bool need_render = false;
if (event.Leaving()) {
mouse_pos = Vector2D::Bad();
mouse_pos = Vector2D();
parent->Render();
return;
}
@ -392,7 +392,7 @@ static Vector2D vec_or_bad(param_vec tag, size_t x_idx, size_t y_idx) {
(*tag)[x_idx]->omitted || (*tag)[y_idx]->omitted ||
(*tag)[x_idx]->GetType() == VARDATA_NONE || (*tag)[y_idx]->GetType() == VARDATA_NONE)
{
return Vector2D::Bad();
return Vector2D();
}
return Vector2D((*tag)[x_idx]->Get<float>(), (*tag)[y_idx]->Get<float>());
}
@ -525,7 +525,7 @@ void VisualToolBase::GetLineClip(AssDialogue *diag, Vector2D &p1, Vector2D &p2,
p2 = vec_or_bad(tag, 2, 3);
}
else {
p1 = Vector2D();
p1 = Vector2D(0, 0);
p2 = script_res - 1;
}
}

View file

@ -59,7 +59,7 @@ void VisualToolRotateZ::Draw() {
// Draw the circle
gl.SetLineColour(colour[0]);
gl.SetFillColour(colour[1], 0.3f);
gl.DrawRing(Vector2D(), radius + 4, radius - 4);
gl.DrawRing(Vector2D(0, 0), radius + 4, radius - 4);
// Draw markers around circle
int markers = 6;
@ -67,7 +67,7 @@ void VisualToolRotateZ::Draw() {
float markEnd = markStart + (180.f / markers);
for (int i = 0; i < markers; ++i) {
float angle = i * (360.f / markers);
gl.DrawRing(Vector2D(), radius+30, radius+12, 1.0, angle+markStart, angle+markEnd);
gl.DrawRing(Vector2D(0, 0), radius+30, radius+12, 1.0, angle+markStart, angle+markEnd);
}
// Draw the baseline through the origin showing current rotation

View file

@ -100,7 +100,7 @@ void VisualToolScale::UpdateHold() {
if (shift_down)
delta = delta.SingleAxis();
scale = Vector2D().Max(delta * 1.25f + initial_scale);
scale = Vector2D(0, 0).Max(delta * 1.25f + initial_scale);
if (ctrl_down)
scale = scale.Round(25.f);