app_server::Transforable: Cleanup
* No need to implement operator== and != * Fix operator=() to be efficent, declare agg::trans_affine version, too.
This commit is contained in:
@@ -13,37 +13,37 @@
|
|||||||
|
|
||||||
#include "Transformable.h"
|
#include "Transformable.h"
|
||||||
|
|
||||||
// min4
|
|
||||||
inline float
|
inline float
|
||||||
min4(float a, float b, float c, float d)
|
min4(float a, float b, float c, float d)
|
||||||
{
|
{
|
||||||
return min_c(a, min_c(b, min_c(c, d)));
|
return min_c(a, min_c(b, min_c(c, d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// max4
|
|
||||||
inline float
|
inline float
|
||||||
max4(float a, float b, float c, float d)
|
max4(float a, float b, float c, float d)
|
||||||
{
|
{
|
||||||
return max_c(a, max_c(b, max_c(c, d)));
|
return max_c(a, max_c(b, max_c(c, d)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
Transformable::Transformable()
|
Transformable::Transformable()
|
||||||
: agg::trans_affine()
|
: agg::trans_affine()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy constructor
|
|
||||||
Transformable::Transformable(const Transformable& other)
|
Transformable::Transformable(const Transformable& other)
|
||||||
: agg::trans_affine(other)
|
: agg::trans_affine(other)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
Transformable::Transformable(const BMessage* archive)
|
Transformable::Transformable(const BMessage* archive)
|
||||||
: agg::trans_affine()
|
: agg::trans_affine()
|
||||||
{
|
{
|
||||||
if (archive) {
|
if (archive != NULL) {
|
||||||
double storage[6];
|
double storage[6];
|
||||||
status_t ret = B_OK;
|
status_t ret = B_OK;
|
||||||
for (int32 i = 0; i < 6; i++) {
|
for (int32 i = 0; i < 6; i++) {
|
||||||
@@ -56,17 +56,17 @@ Transformable::Transformable(const BMessage* archive)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
Transformable::~Transformable()
|
Transformable::~Transformable()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Archive
|
|
||||||
status_t
|
status_t
|
||||||
Transformable::Archive(BMessage* into, bool deep) const
|
Transformable::Archive(BMessage* into, bool deep) const
|
||||||
{
|
{
|
||||||
status_t ret = BArchivable::Archive(into, deep);
|
status_t ret = BArchivable::Archive(into, deep);
|
||||||
if (ret >= B_OK) {
|
if (ret == B_OK) {
|
||||||
double storage[6];
|
double storage[6];
|
||||||
store_to(storage);
|
store_to(storage);
|
||||||
for (int32 i = 0; i < 6; i++) {
|
for (int32 i = 0; i < 6; i++) {
|
||||||
@@ -75,24 +75,24 @@ Transformable::Archive(BMessage* into, bool deep) const
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// finish off
|
// finish off
|
||||||
if (ret >= B_OK)
|
if (ret == B_OK)
|
||||||
ret = into->AddString("class", "Transformable");
|
ret = into->AddString("class", "Transformable");
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// StoreTo
|
|
||||||
void
|
void
|
||||||
Transformable::StoreTo(double matrix[6]) const
|
Transformable::StoreTo(double matrix[6]) const
|
||||||
{
|
{
|
||||||
store_to(matrix);
|
store_to(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadFrom
|
|
||||||
void
|
void
|
||||||
Transformable::LoadFrom(double matrix[6])
|
Transformable::LoadFrom(double matrix[6])
|
||||||
{
|
{
|
||||||
// before calling the potentially heavy TransformationChanged()
|
// Before calling the potentially heavy TransformationChanged()
|
||||||
// hook function, we make sure that it is actually true
|
// hook function, we make sure that it is actually true
|
||||||
Transformable t;
|
Transformable t;
|
||||||
t.load_from(matrix);
|
t.load_from(matrix);
|
||||||
@@ -102,7 +102,7 @@ Transformable::LoadFrom(double matrix[6])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTransformable
|
|
||||||
void
|
void
|
||||||
Transformable::SetTransformable(const Transformable& other)
|
Transformable::SetTransformable(const Transformable& other)
|
||||||
{
|
{
|
||||||
@@ -112,19 +112,29 @@ Transformable::SetTransformable(const Transformable& other)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator=
|
|
||||||
Transformable&
|
Transformable&
|
||||||
Transformable::operator=(const Transformable& other)
|
Transformable::operator=(const Transformable& other)
|
||||||
{
|
{
|
||||||
if (other != *this) {
|
if (other != *this) {
|
||||||
reset();
|
agg::trans_affine::operator=(other);
|
||||||
multiply(other);
|
|
||||||
TransformationChanged();
|
TransformationChanged();
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply
|
|
||||||
|
Transformable&
|
||||||
|
Transformable::operator=(const agg::trans_affine& other)
|
||||||
|
{
|
||||||
|
if (other != *this) {
|
||||||
|
agg::trans_affine::operator=(other);
|
||||||
|
TransformationChanged();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Transformable&
|
Transformable&
|
||||||
Transformable::Multiply(const Transformable& other)
|
Transformable::Multiply(const Transformable& other)
|
||||||
{
|
{
|
||||||
@@ -135,14 +145,14 @@ Transformable::Multiply(const Transformable& other)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset
|
|
||||||
void
|
void
|
||||||
Transformable::Reset()
|
Transformable::Reset()
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsIdentity
|
|
||||||
bool
|
bool
|
||||||
Transformable::IsIdentity() const
|
Transformable::IsIdentity() const
|
||||||
{
|
{
|
||||||
@@ -158,39 +168,14 @@ Transformable::IsIdentity() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// operator==
|
|
||||||
bool
|
|
||||||
Transformable::operator==(const Transformable& other) const
|
|
||||||
{
|
|
||||||
double m1[6];
|
|
||||||
other.store_to(m1);
|
|
||||||
double m2[6];
|
|
||||||
store_to(m2);
|
|
||||||
if (m1[0] == m2[0] &&
|
|
||||||
m1[1] == m2[1] &&
|
|
||||||
m1[2] == m2[2] &&
|
|
||||||
m1[3] == m2[3] &&
|
|
||||||
m1[4] == m2[4] &&
|
|
||||||
m1[5] == m2[5])
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// operator!=
|
|
||||||
bool
|
|
||||||
Transformable::operator!=(const Transformable& other) const
|
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Transform
|
|
||||||
void
|
void
|
||||||
Transformable::Transform(double* x, double* y) const
|
Transformable::Transform(double* x, double* y) const
|
||||||
{
|
{
|
||||||
transform(x, y);
|
transform(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform
|
|
||||||
void
|
void
|
||||||
Transformable::Transform(BPoint* point) const
|
Transformable::Transform(BPoint* point) const
|
||||||
{
|
{
|
||||||
@@ -205,7 +190,7 @@ Transformable::Transform(BPoint* point) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform
|
|
||||||
BPoint
|
BPoint
|
||||||
Transformable::Transform(const BPoint& point) const
|
Transformable::Transform(const BPoint& point) const
|
||||||
{
|
{
|
||||||
@@ -214,14 +199,14 @@ Transformable::Transform(const BPoint& point) const
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// InverseTransform
|
|
||||||
void
|
void
|
||||||
Transformable::InverseTransform(double* x, double* y) const
|
Transformable::InverseTransform(double* x, double* y) const
|
||||||
{
|
{
|
||||||
inverse_transform(x, y);
|
inverse_transform(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// InverseTransform
|
|
||||||
void
|
void
|
||||||
Transformable::InverseTransform(BPoint* point) const
|
Transformable::InverseTransform(BPoint* point) const
|
||||||
{
|
{
|
||||||
@@ -236,7 +221,7 @@ Transformable::InverseTransform(BPoint* point) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// InverseTransform
|
|
||||||
BPoint
|
BPoint
|
||||||
Transformable::InverseTransform(const BPoint& point) const
|
Transformable::InverseTransform(const BPoint& point) const
|
||||||
{
|
{
|
||||||
@@ -245,7 +230,7 @@ Transformable::InverseTransform(const BPoint& point) const
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransformBounds
|
|
||||||
BRect
|
BRect
|
||||||
Transformable::TransformBounds(const BRect& bounds) const
|
Transformable::TransformBounds(const BRect& bounds) const
|
||||||
{
|
{
|
||||||
@@ -279,7 +264,7 @@ Transformable::IsTranslationOnly() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TranslateBy
|
|
||||||
void
|
void
|
||||||
Transformable::TranslateBy(BPoint offset)
|
Transformable::TranslateBy(BPoint offset)
|
||||||
{
|
{
|
||||||
@@ -289,7 +274,7 @@ Transformable::TranslateBy(BPoint offset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RotateBy
|
|
||||||
void
|
void
|
||||||
Transformable::RotateBy(BPoint origin, double radians)
|
Transformable::RotateBy(BPoint origin, double radians)
|
||||||
{
|
{
|
||||||
@@ -301,7 +286,7 @@ Transformable::RotateBy(BPoint origin, double radians)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScaleBy
|
|
||||||
void
|
void
|
||||||
Transformable::ScaleBy(BPoint origin, double xScale, double yScale)
|
Transformable::ScaleBy(BPoint origin, double xScale, double yScale)
|
||||||
{
|
{
|
||||||
@@ -313,7 +298,7 @@ Transformable::ScaleBy(BPoint origin, double xScale, double yScale)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShearBy
|
|
||||||
void
|
void
|
||||||
Transformable::ShearBy(BPoint origin, double xShear, double yShear)
|
Transformable::ShearBy(BPoint origin, double xShear, double yShear)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ class Transformable : public BArchivable,
|
|||||||
|
|
||||||
// set to or combine with other matrix
|
// set to or combine with other matrix
|
||||||
void SetTransformable(const Transformable& other);
|
void SetTransformable(const Transformable& other);
|
||||||
|
Transformable& operator=(const agg::trans_affine& other);
|
||||||
Transformable& operator=(const Transformable& other);
|
Transformable& operator=(const Transformable& other);
|
||||||
Transformable& Multiply(const Transformable& other);
|
Transformable& Multiply(const Transformable& other);
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
bool IsIdentity() const;
|
bool IsIdentity() const;
|
||||||
bool operator==(const Transformable& other) const;
|
// bool operator==(const Transformable& other) const;
|
||||||
bool operator!=(const Transformable& other) const;
|
// bool operator!=(const Transformable& other) const;
|
||||||
|
|
||||||
// transforms coordiantes
|
// transforms coordiantes
|
||||||
void Transform(double* x, double* y) const;
|
void Transform(double* x, double* y) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user