Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
The location and size of a rectangle region.
The width and height of a Rect
can be negative; for instance,
a Rect
with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is
equivalent to a Rect
with an origin of [ 10, 10 ] and a size
of [ -10, -10 ].
Application code can normalize rectangles using rectNormalize
;
this function will ensure that the width and height of a rectangle are
positive values. All functions taking a Rect
as an argument
will internally operate on a normalized copy; all functions returning a
Rect
will always return a normalized rectangle.
Since: 1.0
Synopsis
- newtype Rect = Rect (ManagedPtr Rect)
- newZeroRect :: MonadIO m => m Rect
- rectAlloc :: (HasCallStack, MonadIO m) => m Rect
- rectContainsPoint :: (HasCallStack, MonadIO m) => Rect -> Point -> m Bool
- rectContainsRect :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Bool
- rectEqual :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Bool
- rectExpand :: (HasCallStack, MonadIO m) => Rect -> Point -> m Rect
- rectFree :: (HasCallStack, MonadIO m) => Rect -> m ()
- rectGetArea :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetBottomLeft :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetBottomRight :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetCenter :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetHeight :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetTopLeft :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetTopRight :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetWidth :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetX :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetY :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectInit :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> Float -> Float -> m Rect
- rectInitFromRect :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Rect
- rectInset :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectInsetR :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectInterpolate :: (HasCallStack, MonadIO m) => Rect -> Rect -> Double -> m Rect
- rectIntersection :: (HasCallStack, MonadIO m) => Rect -> Rect -> m (Bool, Rect)
- rectNormalize :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectNormalizeR :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectOffset :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectOffsetR :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectRound :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectRoundExtents :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectRoundToPixel :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectScale :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectUnion :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Rect
- rectZero :: (HasCallStack, MonadIO m) => m Rect
- getRectOrigin :: MonadIO m => Rect -> m Point
- getRectSize :: MonadIO m => Rect -> m Size
Exported types
Memory-managed wrapper type.
Instances
Eq Rect Source # | |
GBoxed Rect Source # | |
Defined in GI.Graphene.Structs.Rect | |
ManagedPtrNewtype Rect Source # | |
Defined in GI.Graphene.Structs.Rect toManagedPtr :: Rect -> ManagedPtr Rect | |
TypedObject Rect Source # | |
Defined in GI.Graphene.Structs.Rect | |
HasParentTypes Rect Source # | |
Defined in GI.Graphene.Structs.Rect | |
tag ~ 'AttrSet => Constructible Rect tag Source # | |
IsGValue (Maybe Rect) Source # | Convert |
Defined in GI.Graphene.Structs.Rect gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe Rect -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe Rect) | |
type ParentTypes Rect Source # | |
Defined in GI.Graphene.Structs.Rect |
Methods
Click to display all available methods, including inherited ones
Methods
containsPoint, containsRect, equal, expand, free, init, initFromRect, inset, insetR, interpolate, intersection, normalize, normalizeR, offset, offsetR, round, roundExtents, roundToPixel, scale, union.
Getters
getArea, getBottomLeft, getBottomRight, getCenter, getHeight, getTopLeft, getTopRight, getWidth, getX, getY.
Setters
None.
alloc
:: (HasCallStack, MonadIO m) | |
=> m Rect | Returns: the newly allocated rectangle |
containsPoint
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Point |
|
-> m Bool | Returns: |
Checks whether a Rect
contains the given coordinates.
Since: 1.0
containsRect
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Rect |
|
-> m Bool | Returns: |
Checks whether a Rect
fully contains the given
rectangle.
Since: 1.0
equal
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Rect |
|
-> m Bool | Returns: |
Checks whether the two given rectangle are equal.
Since: 1.0
expand
free
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m () |
Frees the resources allocated by rectAlloc
.
Since: 1.0
getArea
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Float | Returns: the area of the normalized rectangle |
Compute the area of given normalized rectangle.
Since: 1.10
getBottomLeft
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Point |
Retrieves the coordinates of the bottom-left corner of the given rectangle.
Since: 1.0
getBottomRight
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Point |
Retrieves the coordinates of the bottom-right corner of the given rectangle.
Since: 1.0
getCenter
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Point |
Retrieves the coordinates of the center of the given rectangle.
Since: 1.0
getHeight
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Float | Returns: the normalized height of the rectangle |
Retrieves the normalized height of the given rectangle.
Since: 1.0
getTopLeft
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Point |
Retrieves the coordinates of the top-left corner of the given rectangle.
Since: 1.0
getTopRight
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Point |
Retrieves the coordinates of the top-right corner of the given rectangle.
Since: 1.0
getWidth
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Float | Returns: the normalized width of the rectangle |
Retrieves the normalized width of the given rectangle.
Since: 1.0
getX
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Float | Returns: the normalized X coordinate of the rectangle |
Retrieves the normalized X coordinate of the origin of the given rectangle.
Since: 1.0
getY
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Float | Returns: the normalized Y coordinate of the rectangle |
Retrieves the normalized Y coordinate of the origin of the given rectangle.
Since: 1.0
init
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> Float |
|
-> m Rect | Returns: the initialized rectangle |
initFromRect
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Rect |
|
-> m Rect | Returns: the initialized rectangle |
Initializes r
using the given src
rectangle.
This function will implicitly normalize the Rect
before returning.
Since: 1.0
inset
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Float |
|
-> Float |
|
-> m Rect | Returns: the inset rectangle |
Changes the given rectangle to be smaller, or larger depending on the given inset parameters.
To create an inset rectangle, use positive dX
or dY
values; to
create a larger, encompassing rectangle, use negative dX
or dY
values.
The origin of the rectangle is offset by dX
and dY
, while the size
is adjusted by (2 * @d_x, 2 * @d_y)
. If dX
and dY
are positive
values, the size of the rectangle is decreased; if dX
and dY
are
negative values, the size of the rectangle is increased.
If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.
Since: 1.0
insetR
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Float |
|
-> Float |
|
-> m Rect |
Changes the given rectangle to be smaller, or larger depending on the given inset parameters.
To create an inset rectangle, use positive dX
or dY
values; to
create a larger, encompassing rectangle, use negative dX
or dY
values.
The origin of the rectangle is offset by dX
and dY
, while the size
is adjusted by (2 * @d_x, 2 * @d_y)
. If dX
and dY
are positive
values, the size of the rectangle is decreased; if dX
and dY
are
negative values, the size of the rectangle is increased.
If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.
Since: 1.4
interpolate
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Rect |
|
-> Double |
|
-> m Rect |
Linearly interpolates the origin and size of the two given rectangles.
Since: 1.0
intersection
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Rect |
|
-> m (Bool, Rect) | Returns: |
Computes the intersection of the two given rectangles.
The intersection in the image above is the blue outline.
If the two rectangles do not intersect, res
will contain
a degenerate rectangle with origin in (0, 0) and a size of 0.
Since: 1.0
normalize
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Rect | Returns: the normalized rectangle |
Normalizes the passed rectangle.
This function ensures that the size of the rectangle is made of positive values, and that the origin is the top-left corner of the rectangle.
Since: 1.0
normalizeR
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Rect |
Normalizes the passed rectangle.
This function ensures that the size of the rectangle is made of positive values, and that the origin is in the top-left corner of the rectangle.
Since: 1.4
offset
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Float |
|
-> Float |
|
-> m Rect | Returns: the offset rectangle |
Offsets the origin by dX
and dY
.
The size of the rectangle is unchanged.
Since: 1.0
offsetR
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Float |
|
-> Float |
|
-> m Rect |
Offsets the origin of the given rectangle by dX
and dY
.
The size of the rectangle is left unchanged.
Since: 1.4
round
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Rect |
Deprecated: (Since version 1.10)Use rectRoundExtents
instead
Rounds the origin and size of the given rectangle to
their nearest integer values; the rounding is guaranteed
to be large enough to have an area bigger or equal to the
original rectangle, but might not fully contain its extents.
Use rectRoundExtents
in case you need to round
to a rectangle that covers fully the original one.
This function is the equivalent of calling floor
on
the coordinates of the origin, and ceil
on the size.
Since: 1.4
roundExtents
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Rect |
Rounds the origin of the given rectangle to its nearest integer value and and recompute the size so that the rectangle is large enough to contain all the conrners of the original rectangle.
This function is the equivalent of calling floor
on
the coordinates of the origin, and recomputing the size
calling ceil
on the bottom-right coordinates.
If you want to be sure that the rounded rectangle completely covers the area that was covered by the original rectangle — i.e. you want to cover the area including all its corners — this function will make sure that the size is recomputed taking into account the ceiling of the coordinates of the bottom-right corner. If the difference between the original coordinates and the coordinates of the rounded rectangle is greater than the difference between the original size and and the rounded size, then the move of the origin would not be compensated by a move in the anti-origin, leaving the corners of the original rectangle outside the rounded one.
Since: 1.10
roundToPixel
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> m Rect | Returns: the pixel-aligned rectangle. |
Deprecated: (Since version 1.4)Use rectRound
instead
Rounds the origin and the size of the given rectangle to their nearest integer values; the rounding is guaranteed to be large enough to contain the original rectangle.
Since: 1.0
scale
:: (HasCallStack, MonadIO m) | |
=> Rect |
|
-> Float |
|
-> Float |
|
-> m Rect |
Scales the size and origin of a rectangle horizontaly by sH
,
and vertically by sV
. The result res
is normalized.
Since: 1.10
union
Computes the union of the two given rectangles.
The union in the image above is the blue outline.
Since: 1.0
zero
:: (HasCallStack, MonadIO m) | |
=> m Rect | Returns: a fixed rectangle |
Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.
Since: 1.4
Properties
origin
the coordinates of the origin of the rectangle
getRectOrigin :: MonadIO m => Rect -> m Point Source #
Get the value of the “origin
” field.
When overloading is enabled, this is equivalent to
get
rect #origin
size
the size of the rectangle
getRectSize :: MonadIO m => Rect -> m Size Source #
Get the value of the “size
” field.
When overloading is enabled, this is equivalent to
get
rect #size