From 53486852f4e9a70a30f15a990486e24077e9579e Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 9 Nov 2009 16:49:55 +0000 Subject: [PATCH] compare_to --- panda/src/pnmimage/pnmImageHeader.I | 43 +++++++++++++++++++++++++---- panda/src/pnmimage/pnmImageHeader.h | 3 ++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/panda/src/pnmimage/pnmImageHeader.I b/panda/src/pnmimage/pnmImageHeader.I index 68eac94a87..8494ac0cc9 100644 --- a/panda/src/pnmimage/pnmImageHeader.I +++ b/panda/src/pnmimage/pnmImageHeader.I @@ -365,22 +365,55 @@ operator = (const PixelSpec ©) { } //////////////////////////////////////////////////////////////////// -// Function: PNMImageHeader::PixelSpec::Comparison Operator +// Function: PNMImageHeader::PixelSpec::operator < // Access: Published // Description: //////////////////////////////////////////////////////////////////// INLINE bool PNMImageHeader::PixelSpec:: operator < (const PixelSpec &other) const { + return compare_to(other) < 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMImageHeader::PixelSpec::operator == +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool PNMImageHeader::PixelSpec:: +operator == (const PixelSpec &other) const { + return compare_to(other) == 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMImageHeader::PixelSpec::operator != +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool PNMImageHeader::PixelSpec:: +operator != (const PixelSpec &other) const { + return compare_to(other) != 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: PNMImageHeader::PixelSpec::compare_to +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE int PNMImageHeader::PixelSpec:: +compare_to(const PixelSpec &other) const { if (_red != other._red) { - return _red < other._red; + return _red < other._red ? -1 : 1; } if (_green != other._green) { - return _green < other._green; + return _green < other._green ? -1 : 1; } if (_blue != other._blue) { - return _blue < other._blue; + return _blue < other._blue ? -1 : 1; } - return _alpha < other._alpha; + if (_alpha != other._alpha) { + return _alpha < other._alpha ? -1 : 1; + } + return 0; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pnmimage/pnmImageHeader.h b/panda/src/pnmimage/pnmImageHeader.h index 5cae08c68c..77e5b7c433 100644 --- a/panda/src/pnmimage/pnmImageHeader.h +++ b/panda/src/pnmimage/pnmImageHeader.h @@ -118,6 +118,9 @@ PUBLISHED: INLINE void operator = (const PixelSpec ©); INLINE bool operator < (const PixelSpec &other) const; + INLINE bool operator == (const PixelSpec &other) const; + INLINE bool operator != (const PixelSpec &other) const; + INLINE int compare_to(const PixelSpec &other) const; INLINE xelval get_red() const; INLINE xelval get_green() const;