API Docs

This is a JavaScript object used to represent coordinates, or "points", as used in various places throughout Hammerspoon's API, particularly where dealing with positions on a screen. Behind the scenes it is a wrapper for the CGPoint type in Swift/ObjectiveC.

Properties

x

number
A coordinate for the x-axis position of this point

y

number
A coordinate for the y-axis position of this point

Methods

constructor(x, y) -> None

Create a new HSPoint object
constructor(x, y) -> None
Name Type Description
x number A coordinate for this point on the x-axis
y number A coordinate for this point on the y-axis
None

angle() -> number

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

angleTo(other) -> number

Returns the angle between the positive x axis and the vector from this point to another point or rect's center
angleTo(other) -> number
Name Type Description
other JSValue An HSPoint, or an HSRect (whose center will be used)
number
A number containing the angle in radians, or 0 if `other` is not an HSPoint or HSRect
new HSPoint(0, 0).angleTo(new HSPoint(1, 1)) // 0.7853981633974483

distance(other) -> number

Finds the distance between this point and another point or rect's center
distance(other) -> number
Name Type Description
other JSValue An HSPoint, or an HSRect (whose center will be used)
number
A number containing the distance, or 0 if `other` is not an HSPoint or HSRect
new HSPoint(0, 0).distance(new HSPoint(3, 4)) // 5.0

equals(other) -> boolean

Checks if this point is equal to another point
equals(other) -> boolean
Name Type Description
other HSPoint An HSPoint to compare against
boolean
`true` if both points have the same x and y coordinates, otherwise `false`
new HSPoint(1, 2).equals(new HSPoint(1, 2)) // true

floor() -> HSPoint

Truncates the coordinates of this point towards negative infinity
floor() -> HSPoint
HSPoint
A new HSPoint with the x and y coordinates floored to the nearest integer
new HSPoint(1.7, -1.2).floor() // new HSPoint(1, -2)

inside(rect) -> boolean

Checks if this point lies inside a given rect
inside(rect) -> boolean
Name Type Description
rect HSRect An HSRect to check against
boolean
`true` if this point lies within the bounds of `rect`, otherwise `false`
new HSPoint(5, 5).inside(new HSRect(0, 0, 10, 10)) // true

move(offset) -> HSPoint

Moves this point by an offset
move(offset) -> HSPoint
Name Type Description
offset JSValue An HSPoint (using its x/y), or an HSSize (using its w/h)
HSPoint
A new HSPoint moved by the given offset, or an unchanged copy of this point if `offset` is not an HSPoint or HSSize
new HSPoint(1, 1).move(new HSPoint(2, 3)) // new HSPoint(3, 4)

normalize() -> HSPoint

Normalizes this point, treated as a vector, to a length of 1
normalize() -> HSPoint
HSPoint
A new HSPoint with the same direction as this point but a length of 1, or `new HSPoint(0, 0)` if this point has zero length
new HSPoint(3, 4).normalize() // new HSPoint(0.6, 0.8)

rotateCCW(aroundPoint, times) -> HSPoint

Rotates this point counter-clockwise around another point
rotateCCW(aroundPoint, times) -> HSPoint
Name Type Description
aroundPoint HSPoint The HSPoint to rotate around
times number The number of 90 degree counter-clockwise rotations to perform
HSPoint
A new HSPoint containing the rotated coordinates
new HSPoint(1, 0).rotateCCW(new HSPoint(0, 0), 1) // new HSPoint(0, 1)

scale(factor) -> HSPoint

Scales this point, treated as a vector
scale(factor) -> HSPoint
Name Type Description
factor JSValue A number to scale both coordinates uniformly, or an HSSize/HSPoint to scale the x and y coordinates independently
HSPoint
A new HSPoint scaled by the given factor, or an unchanged copy of this point if `factor` is not a number, HSSize or HSPoint
new HSPoint(2, 3).scale(2) // new HSPoint(4, 6)

vector(other) -> HSPoint

Returns the vector from this point to another point or rect's center
vector(other) -> HSPoint
Name Type Description
other JSValue An HSPoint, or an HSRect (whose center will be used)
HSPoint
A new HSPoint representing the vector, or `new HSPoint(0, 0)` if `other` is not an HSPoint or HSRect
new HSPoint(1, 1).vector(new HSPoint(4, 5)) // new HSPoint(3, 4)