2020-01-03 15:25:21 +01:00
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
# pragma once
2020-01-20 21:53:24 +01:00
# include "til/at.h"
2020-03-10 01:17:24 +01:00
# include "til/color.h"
2020-01-09 18:07:52 +01:00
# include "til/some.h"
2020-03-10 21:51:26 +01:00
# include "til/size.h"
2020-03-13 01:04:43 +01:00
# include "til/point.h"
til::rectangle (#4912)
## Summary of the Pull Request
Introduces convenience type `til::rectangle` which automatically implements our best practices for rectangle-related types and provides automatic conversions in/out of the relevant types.
## PR Checklist
* [x] In support of Differential Rendering #778
* [X] I work here.
* [x] Tests added/passed
* [x] I'm a core contributor.
## Detailed Description of the Pull Request / Additional comments
- Automatically converts in from anything with a Left/Top/Right/Bottom or left/top/right/bottom (Win32 `RECT`)
- Automatically converts Console type `SMALL_RECT` and shifts it from **inclusive** to **exclusive** on instantiation
- Automatically converts out to `SMALL_RECT` (converting back to **inclusive**), `RECT`, or `D2D1_RECT_F`.
- Constructs from bare integers written into source file
- Constructs from a single `til::point` as a 1x1 size rectangle with top-left corner (origin) at that point
- Constructs from a single `til::size` as a WxH size rectangle with top-left corner (origin) at 0,0
- Constructs from a `til::point` and a `til::size` representing the top-left corner and the width by height.
- Constructs from a `til::point` and another `til::point` representing the top-left corner and the **exclusive** bottom-right corner.
- Default constructs to empty
- Uses Chromium numerics for all basic math operations (+, -, *, /)
- Provides equality tests
- Provides `operator bool` to know when it's valid (has an area > 0) and `empty()` to know the contrary
- Accessors for left/top/right/bottom
- Type converting accessors (that use safe conversions and throw) for left/top/right/bottom
- Convenience methods for finding width/height (with Chromium numerics operations) and type-converting templates (with Chromium numerics conversions).
- Accessors for origin (top-left point) and the size/dimensions (as a `til::size`).
- Intersect operation on `operator &` to find where two `til::rectangle`s overlap, returned as a `til::rectangle`.
- Union operation on `operator |` to find the total area covered by two `til::rectangles`, returned as a `til::rectangle`.
- Subtract operation on `operator -` to find the area remaining after one `til::rectangle` is removed from another, returned as a `til::some<til::rectangle, 4>`.
- TAEF/WEX Output and Comparators so they will print very nicely with `VERIFY` and `Log` macros in our testing suite.
- Additional comparators, TAEF/WEX output, and tests written on `til::some` to support the Subtract operation.
- A natvis
## Validation Steps Performed
- See automated tests of functionality.
2020-03-14 18:27:47 +01:00
# include "til/rectangle.h"
2020-03-19 17:10:13 +01:00
# include "til/bitmap.h"
2020-01-30 01:55:48 +01:00
# include "til/u8u16convert.h"
2020-01-09 18:07:52 +01:00
2020-01-03 15:25:21 +01:00
namespace til // Terminal Implementation Library. Also: "Today I Learned"
{
}
// These sit outside the namespace because they sit outside for WIL too.
// Inspired from RETURN_IF_WIN32_BOOL_FALSE
// WIL doesn't include a RETURN_BOOL_IF_FALSE, and RETURN_IF_WIN32_BOOL_FALSE
// will actually return the value of GLE.
# define RETURN_BOOL_IF_FALSE(b) \
do \
{ \
const bool __boolRet = wil : : verify_bool ( b ) ; \
if ( ! __boolRet ) \
{ \
return __boolRet ; \
} \
} while ( 0 , 0 )
// Due to a bug (DevDiv 441931), Warning 4297 (function marked noexcept throws exception) is detected even when the throwing code is unreachable, such as the end of scope after a return, in function-level catch.
# define CATCH_LOG_RETURN_FALSE() \
catch ( . . . ) \
{ \
__pragma ( warning ( suppress : 4297 ) ) ; \
LOG_CAUGHT_EXCEPTION ( ) ; \
return false ; \
}
2020-02-10 23:09:08 +01:00
// MultiByteToWideChar has a bug in it where it can return 0 and then not set last error.
// WIL has a fit if the last error is 0 when a bool false is returned.
// This macro doesn't have a fit. It just reports E_UNEXPECTED instead.
# define THROW_LAST_ERROR_IF_AND_IGNORE_BAD_GLE(condition) \
do \
{ \
if ( condition ) \
{ \
const auto gle = : : GetLastError ( ) ; \
if ( gle ) \
{ \
THROW_WIN32 ( gle ) ; \
} \
else \
{ \
THROW_HR ( E_UNEXPECTED ) ; \
} \
} \
} while ( 0 , 0 )