hammerspoon2-docs
    Preparing search index...

    Class HSPoint

    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.

    Index

    Constructors

    • Create a new HSPoint object

      Parameters

      • x: number

        A coordinate for this point on the x-axis

      • y: number

        A coordinate for this point on the y-axis

      Returns HSPoint

    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

    • Returns the angle between the positive x axis and this point, treated as a vector

      Returns number

      A number containing the angle in radians

    • Returns the angle between the positive x axis and the vector from this point to another point or rect's center

      Parameters

      • other: HSRect | HSPoint

        An HSPoint, or an HSRect (whose center will be used)

      Returns number

      A number containing the angle in radians, or 0 if other is not an HSPoint or HSRect

    • Finds the distance between this point and another point or rect's center

      Parameters

      • other: HSRect | HSPoint

        An HSPoint, or an HSRect (whose center will be used)

      Returns number

      A number containing the distance, or 0 if other is not an HSPoint or HSRect

    • Checks if this point is equal to another point

      Parameters

      • other: HSPoint

        An HSPoint to compare against

      Returns boolean

      true if both points have the same x and y coordinates, otherwise false

    • Truncates the coordinates of this point towards negative infinity

      Returns HSPoint

      A new HSPoint with the x and y coordinates floored to the nearest integer

    • Checks if this point lies inside a given rect

      Parameters

      • rect: HSRect

        An HSRect to check against

      Returns boolean

      true if this point lies within the bounds of rect, otherwise false

    • Moves this point by an offset

      Parameters

      • offset: HSSize | HSPoint

        An HSPoint (using its x/y), or an HSSize (using its w/h)

      Returns HSPoint

      A new HSPoint moved by the given offset, or an unchanged copy of this point if offset is not an HSPoint or HSSize

    • Normalizes this point, treated as a vector, to a length of 1

      Returns 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

    • Rotates this point counter-clockwise around another point

      Parameters

      • aroundPoint: HSPoint

        The HSPoint to rotate around

      • times: number

        The number of 90 degree counter-clockwise rotations to perform

      Returns HSPoint

      A new HSPoint containing the rotated coordinates

    • Scales this point, treated as a vector

      Parameters

      • factor: number | HSSize | HSPoint

        A number to scale both coordinates uniformly, or an HSSize/HSPoint to scale the x and y coordinates independently

      Returns 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

    • Returns the vector from this point to another point or rect's center

      Parameters

      • other: HSRect | HSPoint

        An HSPoint, or an HSRect (whose center will be used)

      Returns HSPoint

      A new HSPoint representing the vector, or new HSPoint(0, 0) if other is not an HSPoint or HSRect