TwiceAsNice  2019-02-18
Public Member Functions | Friends | Related Functions | List of all members
Nice::Size Class Reference

The Nice::Size class defines the size of a two-dimensional object using floating point precision. More...

#include <Size.h>

Inheritance diagram for Nice::Size:
Inheritance graph
Collaboration diagram for Nice::Size:
Collaboration graph

Public Member Functions

 Size ()
 
 Size (double w, double h)
 
 Size (const Size &_size)
 
 Size (const Nice::SizeVar &sz)
 
bool isNull () const
 
bool isEmpty () const
 
bool isValid () const
 
double width () const
 
double height () const
 
void setWidth (double w)
 
void setHeight (double h)
 
void transpose ()
 
double size () const
 
void scale (double w, double h, Nice::AspectRatioMode mode)
 
void scale (const Size &s, Nice::AspectRatioMode mode)
 
Size expandedTo (const Size &) const
 
Size boundedTo (const Size &) const
 
double & rwidth ()
 
double & rheight ()
 
Sizeoperator= (const Size &)
 
Sizeoperator+= (const Size &)
 
Sizeoperator-= (const Size &)
 
Sizeoperator*= (double c)
 
Sizeoperator/= (double c)
 
 Size ()
 
 Size (double w, double h)
 
 Size (const Size &_size)
 
 Size (const Nice::SizeVar &sz)
 
bool isNull () const
 
bool isEmpty () const
 
bool isValid () const
 
double width () const
 
double height () const
 
void setWidth (double w)
 
void setHeight (double h)
 
void transpose ()
 
double size () const
 
void scale (double w, double h, Nice::AspectRatioMode mode)
 
void scale (const Size &s, Nice::AspectRatioMode mode)
 
Size expandedTo (const Size &) const
 
Size boundedTo (const Size &) const
 
double & rwidth ()
 
double & rheight ()
 
Sizeoperator= (const Size &)
 
Sizeoperator+= (const Size &)
 
Sizeoperator-= (const Size &)
 
Sizeoperator*= (double c)
 
Sizeoperator/= (double c)
 
- Public Member Functions inherited from Nice::SizeVar
bool operator== (const SizeVar &__rhs) const
 
bool operator< (const SizeVar &__rhs) const
 
bool operator!= (const SizeVar &__rhs) const
 
bool operator<= (const SizeVar &__rhs) const
 
bool operator> (const SizeVar &__rhs) const
 
bool operator>= (const SizeVar &__rhs) const
 
bool operator== (const SizeVar &__rhs) const
 
bool operator< (const SizeVar &__rhs) const
 
bool operator!= (const SizeVar &__rhs) const
 
bool operator<= (const SizeVar &__rhs) const
 
bool operator> (const SizeVar &__rhs) const
 
bool operator>= (const SizeVar &__rhs) const
 

Friends

bool operator== (const Size &, const Size &)
 
bool operator!= (const Size &, const Size &)
 
const Size operator+ (const Size &, const Size &)
 
const Size operator- (const Size &, const Size &)
 
const Size operator* (const Size &, double)
 
const Size operator* (double, const Size &)
 
const Size operator/ (const Size &, double)
 
bool operator== (const Size &, const Size &)
 
bool operator!= (const Size &, const Size &)
 
const Size operator+ (const Size &, const Size &)
 
const Size operator- (const Size &, const Size &)
 
const Size operator* (const Size &, double)
 
const Size operator* (double, const Size &)
 
const Size operator/ (const Size &, double)
 

Related Functions

(Note that these are not member functions.)

bool operator== (const Nice::Size &s1, const Nice::Size &s2)
 
bool operator!= (const Nice::Size &s1, const Nice::Size &s2)
 
const Nice::Size operator+ (const Nice::Size &s1, const Nice::Size &s2)
 
const Nice::Size operator- (const Nice::Size &s1, const Nice::Size &s2)
 
const Nice::Size operator* (const Nice::Size &size, double factor)
 
const Nice::Size operator* (double factor, const Nice::Size &size)
 
const Nice::Size operator/ (const Nice::Size &size, double divisor)
 
QDataStream & operator<< (QDataStream &stream, const Nice::Size &size)
 
QDataStream & operator>> (QDataStream &stream, Nice::Size &size)
 

Additional Inherited Members

- Public Attributes inherited from Nice::SizeVar
::Ice::Double wd
 
::Ice::Double ht
 

Detailed Description

The Nice::Size class defines the size of a two-dimensional object using floating point precision.

A size is specified by a width() and a height(). It can be set in the constructor and changed using the setWidth(), setHeight(), or scale() functions, or using arithmetic operators. A size can also be manipulated directly by retrieving references to the width and height using the rwidth() and rheight() functions. Finally, the width and height can be swapped using the transpose() function.

The isValid() function determines if a size is valid. A valid size has both width and height greater than or equal to zero. The isEmpty() function returns true if either of the width and height is less than (or equal to) zero, while the isNull() function returns true only if both the width and the height is zero.

Use the expandedTo() function to retrieve a size which holds the maximum height and width of this size and a given size. Similarly, the boundedTo() function returns a size which holds the minimum height and width of this size and a given size.

The Nice::Size class also provides the toSizeVar() function returning a niceSize copy of this size, constructed by rounding the width and height to the nearest integers.

Nice::Size objects can be streamed as well as compared.

See also
niceSize , nicePointI F, niceRectI F

Constructor & Destructor Documentation

◆ Size() [1/8]

Nice::Size::Size ( )
inline

◆ Size() [2/8]

Nice::Size::Size ( double  w,
double  h 
)
inline

◆ Size() [3/8]

Nice::Size::Size ( const Size _size)
inline

◆ Size() [4/8]

Nice::Size::Size ( const Nice::SizeVar sz)
inline

◆ Size() [5/8]

Nice::Size::Size ( )

◆ Size() [6/8]

Nice::Size::Size ( double  w,
double  h 
)

◆ Size() [7/8]

Nice::Size::Size ( const Size _size)

◆ Size() [8/8]

Nice::Size::Size ( const Nice::SizeVar sz)

Member Function Documentation

◆ boundedTo() [1/2]

Size Nice::Size::boundedTo ( const Size otherSizeVar) const
inline

Returns a size holding the minimum width and height of this size and the given otherSizeVar.

See also
expandedTo(), scale()

◆ boundedTo() [2/2]

Size Nice::Size::boundedTo ( const Size ) const

◆ expandedTo() [1/2]

Size Nice::Size::expandedTo ( const Size ) const

◆ expandedTo() [2/2]

Size Nice::Size::expandedTo ( const Size otherSizeVar) const
inline

Returns a size holding the maximum width and height of this size and the given otherSizeVar.

See also
boundedTo(), scale()

◆ height() [1/2]

double Nice::Size::height ( ) const
inline

Returns the height.

See also
width(), setHeight()

◆ height() [2/2]

double Nice::Size::height ( ) const

◆ isEmpty() [1/2]

bool Nice::Size::isEmpty ( ) const
inline

Returns true if either of the width and height is less than or equal to 0; otherwise returns false.

See also
isNull(), isValid()

◆ isEmpty() [2/2]

bool Nice::Size::isEmpty ( ) const

◆ isNull() [1/2]

bool Nice::Size::isNull ( ) const

◆ isNull() [2/2]

bool Nice::Size::isNull ( ) const
inline

Returns true if both the width and height is 0; otherwise returns false.

See also
isValid(), isEmpty()

◆ isValid() [1/2]

bool Nice::Size::isValid ( ) const

◆ isValid() [2/2]

bool Nice::Size::isValid ( ) const
inline

Returns true if both the width and height is equal to or greater than 0; otherwise returns false.

See also
isNull(), isEmpty()

◆ operator*=() [1/2]

Size & Nice::Size::operator*= ( double  factor)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Multiplies both the width and height by the given factor and returns a reference to the size.

See also
scale()

◆ operator*=() [2/2]

Size& Nice::Size::operator*= ( double  c)

◆ operator+=() [1/2]

Size& Nice::Size::operator+= ( const Size )

◆ operator+=() [2/2]

Size & Nice::Size::operator+= ( const Size s)
inline

Adds the given size to this size and returns a reference to this size. For example:

Nice::Size s( 3, 7);
Nice::Size r(-1, 4);
s += r;
// s becomes (2,11)

◆ operator-=() [1/2]

Size & Nice::Size::operator-= ( const Size s)
inline

Subtracts the given size from this size and returns a reference to this size. For example:

Nice::Size s( 3, 7);
Nice::Size r(-1, 4);
s -= r;
// s becomes (4,3)

◆ operator-=() [2/2]

Size& Nice::Size::operator-= ( const Size )

◆ operator/=() [1/2]

Size& Nice::Size::operator/= ( double  c)

◆ operator/=() [2/2]

Size & Nice::Size::operator/= ( double  divisor)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Divides both the width and height by the given divisor and returns a reference to the size.

See also
scale()

◆ operator=() [1/2]

Size & Nice::Size::operator= ( const Size s)
inline

◆ operator=() [2/2]

Size& Nice::Size::operator= ( const Size )

◆ rheight() [1/2]

double& Nice::Size::rheight ( )

◆ rheight() [2/2]

double & Nice::Size::rheight ( )
inline

Returns a reference to the height.

Using a reference makes it possible to manipulate the height directly. For example:

Nice::Size size(100, 10.2);
size.rheight() += 5.5;
// size becomes (100,15.7)
See also
rwidth(), setHeight()

◆ rwidth() [1/2]

double& Nice::Size::rwidth ( )

◆ rwidth() [2/2]

double & Nice::Size::rwidth ( )
inline

Returns a reference to the width.

Using a reference makes it possible to manipulate the width directly. For example:

Nice::Size size(100.3, 10);
size.rwidth() += 20.5;
// size becomes (120.8,10)
See also
rheight(), setWidth()

◆ scale() [1/4]

void Nice::Size::scale ( double  width,
double  height,
Nice::AspectRatioMode  mode 
)
inline

Scales the size to a rectangle with the given width and height, according to the specified mode.

If mode is Nice::IgnoreAspectRatio, the size is set to (width, height). If mode is Nice::KeepAspectRatio, the current size is scaled to a rectangle as large as possible inside (width, height), preserving the aspect ratio. If mode is Nice::KeepAspectRatioByExpanding, the current size is scaled to a rectangle as small as possible outside (width, height), preserving the aspect ratio.

Example:

Nice::Size t1(10, 12);
t1.scale(60, 60, Nice::IgnoreAspectRatio);
// t1 is (60, 60)
Nice::Size t2(10, 12);
t2.scale(60, 60, Nice::KeepAspectRatio);
// t2 is (50, 60)
Nice::Size t3(10, 12);
// t3 is (60, 72)
See also
setWidth(), setHeight()

◆ scale() [2/4]

void Nice::Size::scale ( double  w,
double  h,
Nice::AspectRatioMode  mode 
)

◆ scale() [3/4]

void Nice::Size::scale ( const Size s,
Nice::AspectRatioMode  mode 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Scales the size to a rectangle with the given size, according to the specified mode.

◆ scale() [4/4]

void Nice::Size::scale ( const Size s,
Nice::AspectRatioMode  mode 
)

◆ setHeight() [1/2]

void Nice::Size::setHeight ( double  h)

◆ setHeight() [2/2]

void Nice::Size::setHeight ( double  height)
inline

Sets the height to the given height.

See also
height(), rheight(), setWidth()

◆ setWidth() [1/2]

void Nice::Size::setWidth ( double  w)

◆ setWidth() [2/2]

void Nice::Size::setWidth ( double  width)
inline

Sets the width to the given width.

See also
width(), rwidth(), setHeight()

◆ size() [1/2]

double Nice::Size::size ( ) const

◆ size() [2/2]

double Nice::Size::size ( ) const
inline

◆ transpose() [1/2]

void Nice::Size::transpose ( )

◆ transpose() [2/2]

void Nice::Size::transpose ( )

Swaps the width and height values.

See also
setWidth(), setHeight()

◆ width() [1/2]

double Nice::Size::width ( ) const

◆ width() [2/2]

double Nice::Size::width ( ) const
inline

Returns the width.

See also
height(), setWidth()

Friends And Related Function Documentation

◆ operator!= [1/3]

bool operator!= ( const Size s1,
const Size s2 
)
friend

◆ operator!= [2/3]

bool operator!= ( const Size s1,
const Size s2 
)
friend

◆ operator!=() [3/3]

bool operator!= ( const Nice::Size s1,
const Nice::Size s2 
)
related

Returns true if s1 and s2 are different; otherwise returns false.

◆ operator* [1/6]

const Size operator* ( const Size s,
double  c 
)
friend

◆ operator* [2/6]

const Size operator* ( const Size s,
double  c 
)
friend

◆ operator* [3/6]

const Size operator* ( double  c,
const Size s 
)
friend

◆ operator* [4/6]

const Size operator* ( double  c,
const Size s 
)
friend

◆ operator*() [5/6]

const Nice::Size operator* ( const Nice::Size size,
double  factor 
)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Multiplies the given size by the given factor and returns the result.

See also
Nice::Size::scale()

◆ operator*() [6/6]

const Nice::Size operator* ( double  factor,
const Nice::Size size 
)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Multiplies the given size by the given factor and returns the result.

◆ operator+ [1/3]

const Size operator+ ( const Size s1,
const Size s2 
)
friend

◆ operator+ [2/3]

const Size operator+ ( const Size s1,
const Size s2 
)
friend

◆ operator+() [3/3]

const Nice::Size operator+ ( const Nice::Size s1,
const Nice::Size s2 
)
related

Returns the sum of s1 and s2; each component is added separately.

◆ operator- [1/3]

const Size operator- ( const Size s1,
const Size s2 
)
friend

◆ operator- [2/3]

const Size operator- ( const Size s1,
const Size s2 
)
friend

◆ operator-() [3/3]

const Nice::Size operator- ( const Nice::Size s1,
const Nice::Size s2 
)
related

Returns s2 subtracted from s1; each component is subtracted separately.

◆ operator/ [1/3]

const Size operator/ ( const Size s,
double  c 
)
friend

◆ operator/ [2/3]

const Size operator/ ( const Size s,
double  c 
)
friend

◆ operator/() [3/3]

const Nice::Size operator/ ( const Nice::Size size,
double  divisor 
)
related

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Divides the given size by the given divisor and returns the result.

See also
Nice::Size::scale()

◆ operator<<()

QDataStream & operator<< ( QDataStream &  stream,
const Nice::Size size 
)
related

Writes the the given size to the given stream and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

◆ operator== [1/3]

bool operator== ( const Size s1,
const Size s2 
)
friend

◆ operator== [2/3]

bool operator== ( const Size s1,
const Size s2 
)
friend

◆ operator==() [3/3]

bool operator== ( const Nice::Size s1,
const Nice::Size s2 
)
related

Returns true if s1 and s2 are equal; otherwise returns false.

◆ operator>>()

QDataStream & operator>> ( QDataStream &  stream,
Nice::Size size 
)
related

Reads a size from the given stream into the given size and returns a reference to the stream.

See also
{Format of the QDataStream Operators}

The documentation for this class was generated from the following files: