API Docs

This 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

w

number
The width of the rectangle

h

number
The height of the rectangle

Methods

constructor(w, h) -> None

Create a new HSSize object
constructor(w, h) -> None
Name Type Description
w number The width of the rectangle
h number The height of the rectangle
None

angle() -> number

Returns the angle between the positive x axis and this size, treated as a vector of (w, h)
angle() -> number
number
A number containing the angle in radians
new HSSize(1, 1).angle() // 0.7853981633974483 (pi/4)

equals(other) -> boolean

Checks if this size is equal to another size
equals(other) -> boolean
Name Type Description
other HSSize An HSSize to compare against
boolean
`true` if both sizes have the same width and height, otherwise `false`
new HSSize(10, 20).equals(new HSSize(10, 20)) // true

floor() -> HSSize

Truncates the width and height of this size towards negative infinity
floor() -> HSSize
HSSize
A new HSSize with the w and h values floored to the nearest integer
new HSSize(10.9, 20.1).floor() // new HSSize(10, 20)

scale(factor) -> HSSize

Scales this size
scale(factor) -> HSSize
Name Type Description
factor JSValue A number to scale both dimensions uniformly, or an HSSize/HSPoint to scale the width and height independently
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
new HSSize(10, 20).scale(2) // new HSSize(20, 40)