#
hs.geometry
Utility object to represent points, sizes and rects in a bidimensional plane
An hs.geometry object can be:
- a point, or vector2, with
x
andy
fields for its coordinates - a size with
w
andh
fields for width and height respectively - a rect, which has both a point component for one of its corners, and a size component - so it has all 4 fields
- a unit rect, which is a rect with all fields between 0 and 1; it represents a "relative" rect within another (absolute) rect
(e.g. a unit rect
x=0,y=0 , w=0.5,h=0.5
is the quarter portion closest to the origin); please note that hs.geometry makes no distinction internally between regular rects and unit rects; you can convert to and from as needed via the appropriate methods
You can create these objects in many different ways, via my_obj=hs.geometry.new(...)
or simply my_obj=hs.geometry(...)
by passing any of the following:
- 4 parameters
X,Y,W,H
for the respective fields - W and H, or X and Y, can benil
:hs.geometry(X,Y)
creates a poinths.geometry(nil,nil,W,H)
creates a sizehs.geometry(X,Y,W,H)
creates a rect given its width and height from a corner
- a table
{X,Y}
creates a point - a table
{X,Y,W,H}
creates a rect - a table
{x=X,y=Y,w=W,h=H}
creates a rect, or if you omit X and Y, or W and H, creates a size or a point respectively - a table
{x1=X1,y1=Y1,x2=X2,y2=Y2}
creates a rect, where X1,Y1 and X2,Y2 are the coordinates of opposite corners - a string:
"X Y"
or"X,Y"
creates a point"WxH"
or"W*H"
creates a size"X Y/WxH"
or"X,Y W*H"
(or variations thereof) creates a rect given its width and height from a corner"X1,Y1>X2,Y2"
or"X1 Y1 X2 Y2"
(or variations thereof) creates a rect given two opposite corners"[X,Y WxH]"
or"[X1,Y1 X2,Y2]"
or variations (note the square brackets) creates a unit rect where x=X/100, y=Y/100, w=W/100, h=H/100
- a point and a size
"X Y","WxH"
or{x=X,y=Y},{w=W,h=H}
create a rect
You can use any of these anywhere an hs.geometry object is expected in Hammerspoon; the constructor will be called for you.
#
API Overview
Constructors - API calls which return an object, typically one that offers API methods
copy new point rect size
Fields - Variables which can only be accessed from an object returned by a constructor
area aspect bottomright center h length string table topleft w wh - (#x)
x1 x2 x2y2 xy y y1 y2
Methods - API calls which can only be made on an object returned by a constructor
angle angleTo distance equals fit floor fromUnitRect inside intersect move normalize rotateCCW scale toUnitRect type union vector