Utility object to represent points, sizes and rects in a bidimensional plane
An hs.geometry object can be:
x
and y
fields for its coordinatesw
and h
fields for width and height respectivelyx=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 methodsYou 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:
X,Y,W,H
for the respective fields  W and H, or X and Y, can be nil
: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{X,Y}
creates a point{X,Y,W,H}
creates a rect{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{x1=X1,y1=Y1,x2=X2,y2=Y2}
creates a rect, where X1,Y1 and X2,Y2 are the coordinates of opposite corners"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"X Y","WxH"
or {x=X,y=Y},{w=W,h=H}
create a rectYou can use any of these anywhere an hs.geometry object is expected in Hammerspoon; the constructor will be called for you.
Signature  hs.geometry.copy(geom) > hs.geometry object 

Type  Constructor 
Description  Creates a copy of an hs.geometry object 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 151 
Signature  hs.geometry.new(...) > hs.geometry object 

Type  Constructor 
Description  Creates a new hs.geometry object 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 141 
Signature  hs.geometry.point(x, y) > hs.geometry point 

Type  Constructor 
Description  Convenience function for creating a point object 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 732 
Signature  hs.geometry.rect(x, y, w, h) > hs.geometry rect 

Type  Constructor 
Description  Convenience function for creating a recttable 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 717 
Signature  hs.geometry.size(w, h) > hs.geometry size 

Type  Constructor 
Description  Convenience function for creating a size object 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 744 
Signature  hs.geometry.area 

Type  Field 
Description  A number representing the area of this rect or size; changing it will scale the rect/size  see `hs.geometry:scale()` 
Source  extensions/geometry/geometry.lua line 333 
Signature  hs.geometry.aspect 

Type  Field 
Description  A number representing the aspect ratio of this rect or size; changing it will reshape the rect/size, keeping its area and center constant 
Source  extensions/geometry/geometry.lua line 352 
Signature  hs.geometry.bottomright 

Type  Field 
Description  Alias for `x2y2` 
Source  extensions/geometry/geometry.lua line 267 
Signature  hs.geometry.center 

Type  Field 
Description  A point representing the geometric center of this rect or the midpoint of this vector2; changing it will move the rect/vector accordingly 
Source  extensions/geometry/geometry.lua line 305 
Signature  hs.geometry.h 

Type  Field 
Description  The height of this rect or size; changing it will keep the rect's x,y corner constant 
Source  extensions/geometry/geometry.lua line 218 
Signature  hs.geometry.length 

Type  Field 
Description  A number representing the length of the diagonal of this rect, or the length of this vector2; changing it will scale the rect/vector  see `hs.geometry:scale()` 
Source  extensions/geometry/geometry.lua line 318 
Signature  hs.geometry.string 

Type  Field 
Description  The `"X,Y/WxH"` string for this hs.geometry object (*reduced precision*); useful e.g. for logging 
Source  extensions/geometry/geometry.lua line 281 
Signature  hs.geometry.table 

Type  Field 
Description  The `{x=X,y=Y,w=W,h=H}` table for this hs.geometry object; useful e.g. for serialization/deserialization 
Source  extensions/geometry/geometry.lua line 275 
Signature  hs.geometry.topleft 

Type  Field 
Description  Alias for `xy` 
Source  extensions/geometry/geometry.lua line 206 
Signature  hs.geometry.w 

Type  Field 
Description  The width of this rect or size; changing it will keep the rect's x,y corner constant 
Source  extensions/geometry/geometry.lua line 214 
Signature  hs.geometry.wh 

Type  Field 
Description  The size component for this hs.geometry object; setting this to a new size will keep the rect's x,y corner constant 
Source  extensions/geometry/geometry.lua line 251 
Signature  hs.geometry.x 

Type  Field 
Description  The x coordinate for this point or rect's corner; changing it will move the rect but keep the same width and height 
Source  extensions/geometry/geometry.lua line 173 
Signature  hs.geometry.x1 

Type  Field 
Description  Alias for `x` 
Source  extensions/geometry/geometry.lua line 181 
Signature  hs.geometry.x2 

Type  Field 
Description  The x coordinate for the second corner of this rect; changing it will affect the rect's width 
Source  extensions/geometry/geometry.lua line 231 
Signature  hs.geometry.x2y2 

Type  Field 
Description  The point denoting the other corner of this hs.geometry object; setting this to a new point will change the rect's width and height 
Source  extensions/geometry/geometry.lua line 263 
Signature  hs.geometry.xy 

Type  Field 
Description  The point component for this hs.geometry object; setting this to a new point will move the rect but keep the same width and height 
Source  extensions/geometry/geometry.lua line 202 
Signature  hs.geometry.y 

Type  Field 
Description  The y coordinate for this point or rect's corner; changing it will move the rect but keep the same width and height 
Source  extensions/geometry/geometry.lua line 177 
Signature  hs.geometry.y1 

Type  Field 
Description  Alias for `y` 
Source  extensions/geometry/geometry.lua line 185 
Signature  hs.geometry.y2 

Type  Field 
Description  The y coordinate for the second corner of this rect; changing it will affect the rect's height 
Source  extensions/geometry/geometry.lua line 235 
Signature  hs.geometry:angle() > number 

Type  Method 
Description  Returns the angle between the positive x axis and this vector2 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 516 
Signature  hs.geometry:angleTo(point) > number 

Type  Method 
Description  Returns the angle between the positive x axis and the vector connecting this point or rect's center to another point or rect's center 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 529 
Signature  hs.geometry:distance(point) > number 

Type  Method 
Description  Finds the distance between this point or rect's center and another point or rect's center 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 542 
Signature  hs.geometry:equals(other) > boolean 

Type  Method 
Description  Checks if two geometry objects are equal 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 390 
Signature  hs.geometry:fit(bounds) > hs.geometry object 

Type  Method 
Description  Ensure this rect is fully inside `bounds`, by scaling it down if it's larger (preserving its aspect ratio) and moving it if necessary 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 448 
Signature  hs.geometry:floor() > hs.geometry object 

Type  Method 
Description  Truncates all coordinates in this object to integers 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 483 
Signature  hs.geometry:fromUnitRect(frame) > hs.geometry rect 

Type  Method 
Description  Converts a unit rect within a given frame into a rect 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 672 
Signature  hs.geometry:inside(rect) > boolean 

Type  Method 
Description  Checks if this hs.geometry object lies fully inside a given rect 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 570 
Signature  hs.geometry:intersect(rect) > hs.geometry rect 

Type  Method 
Description  Returns the intersection rect between this rect and another rect 
Parameters 

Returns 

Notes 

Source  extensions/geometry/geometry.lua line 585 
Signature  hs.geometry:move(point) > hs.geometry object 

Type  Method 
Description  Moves this point/rect 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 403 
Signature  hs.geometry:normalize() > point 

Type  Method 
Description  Normalizes this vector2 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 468 
Signature  hs.geometry:rotateCCW(aroundpoint, ntimes) > hs.geometry point 

Type  Method 
Description  Rotates a point around another point N times 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 695 
Signature  hs.geometry:scale(size) > hs.geometry object 

Type  Method 
Description  Scales this vector2/size, or this rect *keeping its center constant* 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 419 
Signature  hs.geometry:toUnitRect(frame) > hs.geometry unit rect 

Type  Method 
Description  Converts a rect into its unit rect within a given frame 
Parameters 

Returns 

Notes 

Source  extensions/geometry/geometry.lua line 644 
Signature  hs.geometry:type() > string 

Type  Method 
Description  Returns the type of an hs.geometry object 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 45 
Signature  hs.geometry:union(rect) > hs.geometry rect 

Type  Method 
Description  Returns the smallest rect that encloses both this rect and another rect 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 555 
Signature  hs.geometry:vector(point) > point 

Type  Method 
Description  Returns the vector2 from this point or rect's center to another point or rect's center 
Parameters 

Returns 

Source  extensions/geometry/geometry.lua line 500 