public class WZSize extends Object implements Comparable<WZSize>, Serializable
WZSize
class represents a dimension with integer-based width and height values.
WZSize frameSize = WZSize(1280, 720);
float aspectRatio = frameSize.aspectRatio();
Modifier and Type | Class and Description |
---|---|
static class |
WZSize.ScaledDimensions
ScaledDimensions is a utility class representing common scaling operations when
placing one rectangular area (the source) within another (the destination) |
Modifier and Type | Field and Description |
---|---|
int |
height
The height value
|
int |
width
The width value
|
Constructor and Description |
---|
WZSize()
The default constructor
|
WZSize(int width,
int height)
Construct a new instance using the specified property values
|
WZSize(WZSize other)
Construct a new instance using the property values from the specified instance
|
Modifier and Type | Method and Description |
---|---|
static WZSize |
absOffset(int w1,
int h1,
int w2,
int h2)
Calculates the offset between two dimensions.
|
WZSize |
absOffsetFrom(WZSize other)
Calculates the offset between the width and height values from this instance and the specified instance.
|
double |
area()
Calculates the area of a rectangle with the width and height values of this instance
|
double |
area(int w,
int h) |
WZSize |
asLandscape()
Returns a new instance with the width and height values assigned in a manner that guarantees width >= height
|
static WZSize |
asLandscape(int width,
int height)
Returns an instance with the width and height values assigned in a manner that guarantees width >= height
|
float |
aspectRatio()
Calculates the aspect ratio (width / height) using the width and height values of this instance
|
static float |
aspectRatio(int width,
int height)
Calculates an aspect ratio (width / height)
|
String |
aspectRatioLabel()
Returns a string representation of the aspect ratio of this dimension
|
static String |
aspectRatioLabel(int width,
int height)
Returns an aspect ratio as a string (e.g.
|
WZSize |
asPortrait()
Returns a new instance with the width and height values assigned in a manner that guarantees width <= height
|
static WZSize |
asPortrait(int width,
int height)
Returns an instance with the width and height values assigned in a manner that guarantees width <= height
|
WZPoint |
center()
Calculates the center point of an zero-based rectangle with the width and height values of this instance
|
WZPoint |
center(int width,
int height)
Calculates the center point of the rectangular region with the specified dimensions
|
WZSize.ScaledDimensions |
center(WZSize other)
Calculate the offset of this instance from the destination after centering it within the destination.
|
static WZSize |
closestTo(int width,
int height,
WZSize[] others)
Returns the instance from the specified array that is greater to and closest in size to the specified dimension values
|
static WZSize |
closestTo(WZSize src,
WZSize[] others)
Returns the instance from the specified array that is greater to and closest in size to the specified instance
|
static int |
closestToIndex(int width,
int height,
WZSize[] others)
Returns the index of the instance from the specified array that is greater to and closest in size to the specified dimension values
|
static int |
closestToIndex(WZSize src,
WZSize[] others)
Returns the index of the instance from the specified array that is greater to and closest in size to the specified instance
|
int |
compareTo(int width,
int height)
Compare this property values of this instance with the specified values
|
int |
compareTo(WZSize other)
Compare this instance with the specified instance
|
boolean |
equals(int width,
int height)
Compare the property values of this instance with the specified values for equality
|
boolean |
equals(int w1,
int h1,
int w2,
int h2)
Compare two dimensions for equality.
|
boolean |
equals(Object other)
Compare this instance with the specified instance for equality
|
boolean |
equalsAspect(int width,
int height)
Compare the aspect ratio of this instance with the aspect ratio of the specified width and height
|
static boolean |
equalsAspect(int w1,
int h1,
int w2,
int h2)
Compare the aspect ratios of two dimensions for equality
|
boolean |
equalsAspect(WZSize other)
Compare the aspect ratio of this instance with another instance
|
static boolean |
equalsAspect(WZSize s1,
WZSize s2)
Compare the aspect ratios of two WZSize instances for equality
|
static WZSize[] |
filterByAspectRatio(WZSize[] sizes,
WZSize srcSize)
Filter an array of sizes by those that match the aspect ratio of a specified size
|
static WZSize[] |
findContainers(WZSize[] srcSizes,
WZSize minSize)
Filter an array of sizes by those that are equal to or larger than a specified minimum size
|
boolean |
fitsWithin(WZSize other)
Compares this instance with the specified instance to see if it is smaller
|
int |
getHeight() |
int |
getWidth() |
void |
invert()
Invert the coordinate values of this instance
|
WZSize |
inverted()
Create a new "inverted" version of this instance with the width and height values reversed
|
boolean |
isLandscape() |
static boolean |
isLandscape(int width,
int height) |
boolean |
isPortrait() |
static boolean |
isPortrait(int width,
int height) |
boolean |
isSquare() |
static boolean |
isSquare(int width,
int height) |
boolean |
isZero() |
static boolean |
isZero(int width,
int height) |
static String |
label(int width,
int height)
Returns a human-readable description of the specified values
|
boolean |
largerThan(WZSize other)
Compares this instance with the specified instance to see if it is larger
|
int |
longDimension() |
static int |
longDimension(int width,
int height) |
static WZSize |
offset(int w1,
int h1,
int w2,
int h2)
Calculates the offset between two dimensions.
|
WZSize |
offsetFrom(WZSize other)
Calculates the offset between the width and height values from this instance and the specified instance.
|
WZSize.ScaledDimensions |
scaleWithCrop(WZSize other)
Calculate the dimensions of this instance after scaling it so that it fits entirely within the specified instance, preserving the aspect ratio.
|
WZSize.ScaledDimensions |
scaleWithFill(WZSize other)
Calculate the dimensions of this instance after scaling it so that it fills the specified instance, preserving the aspect ratio.
|
void |
set(int width,
int height)
Update the property values of this instance with the specified values
|
void |
set(WZSize other)
Update the property values of this instance with the property values from the specified instance
|
void |
setHeight(int height)
Update the height value
|
void |
setWidth(int width)
Update the width value
|
String |
toString()
Returns a human-readable description of this instance
|
public WZSize()
public WZSize(int width, int height)
width
- The width valueheight
- The height valuepublic WZSize(WZSize other)
other
- The instance to replicatepublic boolean equals(int w1, int h1, int w2, int h2)
w1
- The width value of the first dimensionh1
- The height value of the first dimensionw2
- The width value of the second dimensionh2
- The height value of the second dimensiontrue
if the values are equal, false
otherwisepublic static float aspectRatio(int width, int height)
public static String aspectRatioLabel(int width, int height)
width
- width, in pixelsheight
- height, in pixelspublic static WZSize[] filterByAspectRatio(WZSize[] sizes, WZSize srcSize)
sizes
- the array of sizes to comparesrcSize
- the source sizepublic static WZSize[] findContainers(WZSize[] srcSizes, WZSize minSize)
srcSizes
- the array of sizes to compareminSize
- the minimum sizepublic static boolean equalsAspect(int w1, int h1, int w2, int h2)
w1
- The width value of the first dimensionh1
- The height value of the first dimensionw2
- The width value of the second dimensionh2
- The height value of the second dimensionpublic static boolean equalsAspect(WZSize s1, WZSize s2)
s1
- the first size for comparisons2
- the second size for comparisonpublic static WZSize offset(int w1, int h1, int w2, int h2)
w1
- The width value of the first dimensionh1
- The height value of the first dimensionw2
- The width value of the second dimensionh2
- The height value of the second dimensionpublic static WZSize absOffset(int w1, int h1, int w2, int h2)
w1
- The width value of the first dimensionh1
- The height value of the first dimensionw2
- The width value of the second dimensionh2
- The height value of the second dimensionpublic double area(int w, int h)
public WZPoint center(int width, int height)
width
- The width valueheight
- The height valuepublic static boolean isLandscape(int width, int height)
true
if width > height, false
otherwisepublic static boolean isPortrait(int width, int height)
true
if width < height, false
otherwisepublic static boolean isSquare(int width, int height)
true
if width == height, false
otherwisepublic static boolean isZero(int width, int height)
true
if width and height are both 0, false
otherwisepublic static int longDimension(int width, int height)
public static WZSize asLandscape(int width, int height)
public static WZSize asPortrait(int width, int height)
public static WZSize closestTo(WZSize src, WZSize[] others)
src
- The instance to use for comparison to the instances in the arrayothers
- An array of instances to compare with the specified instancepublic static int closestToIndex(WZSize src, WZSize[] others)
src
- The instance to use for comparison to the instances in the arrayothers
- An array of instances to compare with the specified instancepublic static WZSize closestTo(int width, int height, WZSize[] others)
width
- The width value to use for comparisonheight
- The height value to use for comparisonothers
- An array of instances to compare with the specified valuespublic static int closestToIndex(int width, int height, WZSize[] others)
width
- The width value to use for comparisonheight
- The height value to use for comparisonothers
- An array of instances to compare with the specified valuespublic static String label(int width, int height)
public int getWidth()
public void setWidth(int width)
width
- The width valuepublic int getHeight()
public void setHeight(int height)
height
- The height valuepublic void set(int width, int height)
width
- The width valueheight
- The height valuepublic void set(WZSize other)
other
- The instance with the property values to replicatepublic boolean equals(int width, int height)
width
- The width valueheight
- The height valuetrue
is the values are equal, false
otherwisepublic boolean equals(Object other)
public int compareTo(WZSize other)
compareTo
in interface Comparable<WZSize>
other
- The instance to be used for comparisonpublic int compareTo(int width, int height)
width
- The width valueheight
- The height valuepublic String toString()
public WZSize inverted()
public void invert()
public float aspectRatio()
public String aspectRatioLabel()
public boolean equalsAspect(int width, int height)
width
- The width to use for comparisonheight
- The height to use for comparisonpublic boolean equalsAspect(WZSize other)
other
- the other instance to use for comparisonpublic boolean isLandscape()
true
if width > height, false
otherwisepublic boolean isPortrait()
true
if width < height, false
otherwisepublic boolean isSquare()
true
if width == height, false
otherwisepublic boolean isZero()
true
if width and height are both 0, false
otherwisepublic int longDimension()
public WZSize asLandscape()
public WZSize asPortrait()
public boolean fitsWithin(WZSize other)
true
if the width and height values of this instance are less than the values from the specified instance, false
otherwisepublic boolean largerThan(WZSize other)
true
if the width and height values of this instance are greater than the values from the specified instance, false
otherwisepublic WZPoint center()
public double area()
public WZSize offsetFrom(WZSize other)
other
- The instance with the width and height values for the offset calculationpublic WZSize absOffsetFrom(WZSize other)
other
- The instance with the width and height values for the offset calculationpublic WZSize.ScaledDimensions scaleWithCrop(WZSize other)
other
- The destination rectangular instancepublic WZSize.ScaledDimensions scaleWithFill(WZSize other)
other
- The destination rectangular instancepublic WZSize.ScaledDimensions center(WZSize other)
other
- The destination rectangular instance© 2016 Wowza Media Systems, LLC. All rights reserved. Terms | Privacy | Trademarks | Legal