Skip to main content

point_in_rounded_rect

Function point_in_rounded_rect 

Source
pub fn point_in_rounded_rect(
    px: i32,
    py: i32,
    w: i32,
    h: i32,
    r: (i32, i32, i32, i32),
) -> bool
Expand description

(px, py)(要素ローカル座標)が角丸矩形の内側にあるかを返す。 w, h は要素サイズ、r は border-radius(ピクセル)。 計算量: O(1) — 4 隅の楕円判定のみ。

ただし毎ピクセル呼ばれる使い方をしているため、 角丸付き背景の塗りは全体で O(W×H) になる。 本来は 4 隅だけ判定し、内側は矩形として一括で塗れる (このページでは当該分岐に入らないため未着手。実測 rrect=0)。