TwiceAsNice
2019-02-18
|
The Nice::Size class defines the size of a two-dimensional object using floating point precision. More...
#include <Size.h>
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 | |
![]() | |
::Ice::Double | wd |
::Ice::Double | ht |
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.
|
inline |
|
inline |
|
inline |
Nice::Size::Size | ( | ) |
Nice::Size::Size | ( | double | w, |
double | h | ||
) |
Nice::Size::Size | ( | const Nice::SizeVar & | sz | ) |
Returns a size holding the minimum width and height of this size and the given otherSizeVar.
Returns a size holding the maximum width and height of this size and the given otherSizeVar.
|
inline |
Returns the height.
double Nice::Size::height | ( | ) | const |
|
inline |
bool Nice::Size::isEmpty | ( | ) | const |
bool Nice::Size::isNull | ( | ) | const |
|
inline |
bool Nice::Size::isValid | ( | ) | const |
|
inline |
|
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.
Size& Nice::Size::operator*= | ( | double | c | ) |
Adds the given size to this size and returns a reference to this size. For example:
Subtracts the given size from this size and returns a reference to this size. For example:
Size& Nice::Size::operator/= | ( | double | c | ) |
|
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.
double& Nice::Size::rheight | ( | ) |
|
inline |
Returns a reference to the height.
Using a reference makes it possible to manipulate the height directly. For example:
double& Nice::Size::rwidth | ( | ) |
|
inline |
Returns a reference to the width.
Using a reference makes it possible to manipulate the width directly. For example:
|
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:
void Nice::Size::scale | ( | double | w, |
double | h, | ||
Nice::AspectRatioMode | mode | ||
) |
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.
void Nice::Size::scale | ( | const Size & | s, |
Nice::AspectRatioMode | mode | ||
) |
void Nice::Size::setHeight | ( | double | h | ) |
|
inline |
Sets the height to the given height.
void Nice::Size::setWidth | ( | double | w | ) |
|
inline |
Sets the width to the given width.
double Nice::Size::size | ( | ) | const |
|
inline |
void Nice::Size::transpose | ( | ) |
void Nice::Size::transpose | ( | ) |
Swaps the width and height values.
double Nice::Size::width | ( | ) | const |
|
inline |
Returns the width.
|
related |
Returns true if s1 and s2 are different; otherwise returns false.
|
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.
|
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.
|
related |
Returns the sum of s1 and s2; each component is added separately.
|
related |
Returns s2 subtracted from s1; each component is subtracted separately.
|
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.
|
related |
Writes the the given size to the given stream and returns a reference to the stream.
|
related |
Returns true if s1 and s2 are equal; otherwise returns false.
|
related |
Reads a size from the given stream into the given size and returns a reference to the stream.