File:  [Isaki's NoNo m68k/m88k emulator] / nono / lib / rect.h
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:05:26 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v027, v026, v025, v024, v023, v022, v021, v020, HEAD
nono 1.0.0

//
// nono
// Copyright (C) 2021 nono project
// Licensed under nono-license.txt
//

//
// 矩形構造体
//

#pragma once

#include "header.h"

//
// 自前の Rect 構造体
//
struct Rect
{
	int x {};
	int y {};
	int w {};
	int h {};

	Rect() {}

	Rect(int x_, int y_, int w_, int h_) {
		x = x_;
		y = y_;
		w = w_;
		h = h_;
	}

	void SetLTRB(int left, int top, int right, int bottom) {
		x = left;
		y = top;
		w = right - x + 1;
		h = bottom - y + 1;
	}

	int GetRight() const  { return x + w - 1; }
	int GetBottom() const { return y + h - 1; }

	void Offset(int dx, int dy) {
		x += dx;
		y += dy;
	}

	// 点 (px, py) がこの矩形の内側(境界を含む)にあれば true を返す
	bool Contains(int px, int py) const {
		return (x <= px && px < x + w &&
		        y <= py && py < y + h);
	}
};

//
// 自前の Rect<float> 構造体
//
struct RectF
{
	float x {};
	float y {};
	float w {};
	float h {};

	RectF() {}

	RectF(float x_, float y_, float w_, float h_) {
		x = x_;
		y = y_;
		w = w_;
		h = h_;
	}
};

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.