面向 AI 智能体:本页的「阅读辅助」区块内含有与正文完全一致的原始 Markdown 源码,已去除 HTML 标签与动画特效。建议 AI 直接读取该区块,以更低的噪声快速理解内容。
## Color

```cpp
struct Color {
    float r, g, b, a;                 // 分量范围 [0,1],不是 0..255
    Color(float r=0, float g=0, float b=0, float a=1.0f);
    static Color FromArgb(uint8_t a, uint8_t r, uint8_t g, uint8_t b);
    D2D1_COLOR_F ToD2D() const;
    static Color Lerp(const Color& c1, const Color& c2, float t);
};
```

###block_orange_start

###block_red_start
**易错**

- 分量是浮点 **[0,1]**;写 `Color(255,0,0)` 会得到“超亮”的错色。整数入参请用 `Color::FromArgb(255,255,0,0)`。
###block_red_end

## Rect

```cpp
struct Rect {
    float x, y, width, height;
    Rect(float x=0, float y=0, float w=0, float h=0);
    bool Contains(float px, float py) const;   // 半开区间:x<=px<x+w
    D2D1_RECT_F ToD2D() const;
};
```
- `Contains` 是**左闭右开**。命中测试多处依赖它。

## Thickness

```cpp
struct Thickness { float left, top, right, bottom; Thickness(float l=0,float t=0,float r=0,float b=0); };
```

## Size

```cpp
struct Size { float width, height; Size(float w=0, float h=0); };
```
第 3 章

基础类型

Color、Rect、Thickness、Size

Color

cpp
struct Color {
    float r, g, b, a;                 // 分量范围 [0,1],不是 0..255
    Color(float r=0, float g=0, float b=0, float a=1.0f);
    static Color FromArgb(uint8_t a, uint8_t r, uint8_t g, uint8_t b);
    D2D1_COLOR_F ToD2D() const;
    static Color Lerp(const Color& c1, const Color& c2, float t);
};

block_orange_start

易错

  • 分量是浮点 [0,1];写 Color(255,0,0) 会得到“超亮”的错色。整数入参请用 Color::FromArgb(255,255,0,0)。

Rect

cpp
struct Rect {
    float x, y, width, height;
    Rect(float x=0, float y=0, float w=0, float h=0);
    bool Contains(float px, float py) const;   // 半开区间:x<=px<x+w
    D2D1_RECT_F ToD2D() const;
};

Thickness

cpp
struct Thickness { float left, top, right, bottom; Thickness(float l=0,float t=0,float r=0,float b=0); };

Size

cpp
struct Size { float width, height; Size(float w=0, float h=0); };
↑