HSSize
TypeThis is a JavaScript object used to represent the size of a rectangle, as used in various places throughout Hammerspoon's API, particularly where dealing with portions of a display. Behind the scenes it is a wrapper for the CGSize type in Swift/ObjectiveC.
Properties
Methods
constructor(w, h) -> None
Create a new HSSize object
Declaration
constructor(w, h) -> None
Parameters
| Name | Type | Description |
|---|---|---|
| w | number | The width of the rectangle |
| h | number | The height of the rectangle |
Returns
None
angle() -> number
Returns the angle between the positive x axis and this size, treated as a vector of (w, h)
Declaration
angle() -> number
Returns
number
A number containing the angle in radians
Example
new HSSize(1, 1).angle() // 0.7853981633974483 (pi/4)
equals(other) -> boolean
Checks if this size is equal to another size
Declaration
equals(other) -> boolean
Parameters
| Name | Type | Description |
|---|---|---|
| other | HSSize | An HSSize to compare against |
Returns
boolean
`true` if both sizes have the same width and height, otherwise `false`
Example
new HSSize(10, 20).equals(new HSSize(10, 20)) // true
floor() -> HSSize
Truncates the width and height of this size towards negative infinity
Declaration
floor() -> HSSize
Returns
HSSize
A new HSSize with the w and h values floored to the nearest integer
Example
new HSSize(10.9, 20.1).floor() // new HSSize(10, 20)
scale(factor) -> HSSize
Scales this size
Declaration
scale(factor) -> HSSize
Parameters
| Name | Type | Description |
|---|---|---|
| factor | JSValue | A number to scale both dimensions uniformly, or an HSSize/HSPoint to scale the width and height independently |
Returns
HSSize
A new HSSize scaled by the given factor, or an unchanged copy of this size if `factor` is not a number, HSSize or HSPoint
Example
new HSSize(10, 20).scale(2) // new HSSize(20, 40)