我们先定义一个数据结构 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));
};
}