NSGeomerty.h

132 篇文章 0 订阅

NS_INLINE NSPoint NSMakePoint(CGFloat x, CGFloat y) { //生成NSPoint

    NSPoint p;

    p.x = x;

    p.y = y;

    return p;

}


NS_INLINE NSSize NSMakeSize(CGFloat w, CGFloat h) {//生成NSSize

    NSSize s;

    s.width = w;

    s.height = h;

    return s;

}


NS_INLINE NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h) {//生成NSRect

    NSRect r;

    r.origin.x = x;

    r.origin.y = y;

    r.size.width = w;

    r.size.height = h;

    return r;

}


NS_INLINE CGFloat NSMaxX(NSRect aRect) {//x点+宽度,返回的就是此rect里x的最大值

    return (aRect.origin.x + aRect.size.width);

}


NS_INLINE CGFloat NSMaxY(NSRect aRect) {//y点+高度,返回的就是此rect里y的最大值

    return (aRect.origin.y + aRect.size.height);

}


NS_INLINE CGFloat NSMidX(NSRect aRect) {//x+宽度/2, 反回的是此rect里x的中间值 

    return (aRect.origin.x + aRect.size.width * (CGFloat)0.5);

}


NS_INLINE CGFloat NSMidY(NSRect aRect) {//y+高度/2,返回的是此rect里y的中间值

    return (aRect.origin.y + aRect.size.height * (CGFloat)0.5);

}


NS_INLINE CGFloat NSMinX(NSRect aRect) {//返回x

    return (aRect.origin.x);

}


NS_INLINE CGFloat NSMinY(NSRect aRect) {//返回y

    return (aRect.origin.y);

}


NS_INLINE CGFloat NSWidth(NSRect aRect) {//返回宽度

    return (aRect.size.width);

}


NS_INLINE CGFloat NSHeight(NSRect aRect) {//返回高度

    return (aRect.size.height);

}


NS_INLINE NSRect NSRectFromCGRect(CGRect cgrect) {//CGRect to NSRect

    union _ {NSRect ns; CGRect cg;};

    return ((union _ *)&cgrect)->ns;

}


NS_INLINE CGRect NSRectToCGRect(NSRect nsrect) {//NSRect to CGRect

    union _ {NSRect ns; CGRect cg;};

    return ((union _ *)&nsrect)->cg;

}


NS_INLINE NSPoint NSPointFromCGPoint(CGPoint cgpoint) {// CGPoint to NSPoint

    union _ {NSPoint ns; CGPoint cg;};

    return ((union _ *)&cgpoint)->ns;

}


NS_INLINE CGPoint NSPointToCGPoint(NSPoint nspoint) {//NSPoint to CGPoint

    union _ {NSPoint ns; CGPoint cg;};

    return ((union _ *)&nspoint)->cg;

}


NS_INLINE NSSize NSSizeFromCGSize(CGSize cgsize) {//CGSize to NSSize

    union _ {NSSize ns; CGSize cg;};

    return ((union _ *)&cgsize)->ns;

}


NS_INLINE CGSize NSSizeToCGSize(NSSize nssize) {//NSSize to CGSize

    union _ {NSSize ns; CGSize cg;};

    return ((union _ *)&nssize)->cg;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值