068e3e7bc2
## Summary of the Pull Request Introduces convenience type `til::point` which automatically implements our best practices for point-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 X/Y (console `COORD`) or x/y (Win32 `POINT`) - Automatically converts out to `COORD`, `POINT`, or `D2D1_POINT_2F`. - Constructs from bare integers written into source file - Default constructs to empty - Uses Chromium Math for all basic math operations (+, -, *, /) - Provides equality tests - Accessors for x/y - Type converting accessors (that use safe conversions and throw) for x/y - TAEF/WEX Output and Comparators so they will print very nicely with `VERIFY` and `Log` macros in our testing suite. - A natvis ## Validation Steps Performed - See automated tests of functionality.
60 lines
2.6 KiB
C++
60 lines
2.6 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "til/at.h"
|
|
#include "til/color.h"
|
|
#include "til/some.h"
|
|
#include "til/size.h"
|
|
#include "til/point.h"
|
|
#include "til/u8u16convert.h"
|
|
|
|
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; \
|
|
}
|
|
|
|
// 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)
|