Annotation of nono/lib/rect.h, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2021 nono project
        !             4: // Licensed under nono-license.txt
        !             5: //
        !             6: 
        !             7: //
        !             8: // 矩形構造体
        !             9: //
        !            10: 
        !            11: #pragma once
        !            12: 
        !            13: #include "header.h"
        !            14: 
        !            15: //
        !            16: // 自前の Rect 構造体
        !            17: //
        !            18: struct Rect
        !            19: {
        !            20:        int x {};
        !            21:        int y {};
        !            22:        int w {};
        !            23:        int h {};
        !            24: 
        !            25:        Rect() {}
        !            26: 
        !            27:        Rect(int x_, int y_, int w_, int h_) {
        !            28:                x = x_;
        !            29:                y = y_;
        !            30:                w = w_;
        !            31:                h = h_;
        !            32:        }
        !            33: 
        !            34:        void SetLTRB(int left, int top, int right, int bottom) {
        !            35:                x = left;
        !            36:                y = top;
        !            37:                w = right - x + 1;
        !            38:                h = bottom - y + 1;
        !            39:        }
        !            40: 
        !            41:        int GetRight() const  { return x + w - 1; }
        !            42:        int GetBottom() const { return y + h - 1; }
        !            43: 
        !            44:        void Offset(int dx, int dy) {
        !            45:                x += dx;
        !            46:                y += dy;
        !            47:        }
        !            48: 
        !            49:        // 点 (px, py) がこの矩形の内側(境界を含む)にあれば true を返す
        !            50:        bool Contains(int px, int py) const {
        !            51:                return (x <= px && px < x + w &&
        !            52:                        y <= py && py < y + h);
        !            53:        }
        !            54: };
        !            55: 
        !            56: //
        !            57: // 自前の Rect<double> 構造体
        !            58: //
        !            59: struct RectD
        !            60: {
        !            61:        double x {};
        !            62:        double y {};
        !            63:        double w {};
        !            64:        double h {};
        !            65: 
        !            66:        RectD() {}
        !            67: 
        !            68:        RectD(double x_, double y_, double w_, double h_) {
        !            69:                x = x_;
        !            70:                y = y_;
        !            71:                w = w_;
        !            72:                h = h_;
        !            73:        }
        !            74: };

unix.superglobalmegacorp.com

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