OpenSiv3D icon indicating copy to clipboard operation
OpenSiv3D copied to clipboard

サイズが 0 の Rect, RectF を "empty" な状態であると定義

Open Reputeless opened this issue 2 years ago • 1 comments

サイズが 0 の長方形を「空の長方形」とする。

  • Rect::isEmpty(), Rect::operator bool #880
  • Rect::getOverlap(cother) #872
  • static Rect Rect::Empty() #881

RectF も同様に。

Reputeless avatar Sep 01 '22 11:09 Reputeless

# include <Siv3D.hpp> // OpenSiv3D v0.6.6

void Main()
{
	Optional<Point> from;

	const Rect rect{ 300, 200, 300, 200 };

	while (System::Update())
	{
		ClearPrint();

		if (MouseL.down())
		{
			from = Cursor::Pos();
		}
		else if (MouseL.up())
		{
			from.reset();
		}

		rect.drawFrame(1, 0);

		if (from)
		{
			const Rect rect2 = Rect::FromPoints(*from, Cursor::Pos());

			rect2.drawFrame(1, 0, Palette::Skyblue);

			if (const Rect overlap = rect.getOverlap(rect2))
			{
				Print << overlap;

				overlap.draw(Palette::Orange);
			}
		}
	}
}

Reputeless avatar Sep 01 '22 12:09 Reputeless