我們先定義一個數據結構 Position
struct Position {
double x;
double y;
};
struct Position Position(double x, double y)
{
struct Position position;
position.x = x;
position.y = y;
return position;
}
// 判斷一個 Position 是否在圖形內
typedef BOOL (^region_t)(struct Position p);
// 將原有的 region 平移 offset 之后,生成新的 region_t
region_t shift(region_t region, struct Position offset)
{
return ^(struct Position position) {
return region(minus(position, offset));
};
}