//
// CCSize.h
// CCFC
//
//
#import <Foundation/Foundation.h>
@interface CCSize : NSObject
{
@public
CGFloat width;
CGFloat height;
}
- (id)initWithWidth:(CGFloat)width withHeight:(CGFloat)height;
+ (id)sizeWithCCSize:(CCSize *)size;
- (id)initWithCGSize:(CGSize)size;
+ (id)sizeWithCGSize:(CGSize)size;
- (void)dealloc;
- (BOOL)isEqualTo:(CCSize *)anotherSize;
- (BOOL)isEqualToCGSize:(CGSize)size;
- (BOOL)isZero;
- (void)setWidth:(CGFloat)width withHeight:(CGFloat)height;
- (CGSize)toCGSize;
@end
//
// CCSize.m
// CCFC
//
//
#import "CCSize.h"
#import "CCCommon.h"
#import "CCNSNumber.h"
@implementation CCSize
- (id)initWithWidth:(CGFloat)aWidth withHeight:(CGFloat)aHeight
{
COMMON_INIT_BEGIN
self->width = aWidth;
self->height = aHeight;
COMMON_INIT_END
}
+ (id)sizeWithCCSize:(CCSize *)size
{
CCSize *newSize = [[CCSize alloc]
initWithWidth:size->width withHeight:size->height];
return [newSize autorelease];
}
- (id)initWithCGSize:(CGSize)size
{
COMMON_INIT_BEGIN
width = size.width;
height = size.height;
COMMON_INIT_END
}
+ (id)sizeWithCGSize:(CGSize)size
{
CCSize *newSize = [[CCSize alloc] initWithCGSize:size];
return [newSize autorelease];
}
- (void)dealloc
{
[super dealloc];
}
- (BOOL)isEqualTo:(CCSize *)anotherSize
{
return (FLOAT_EQUAL_TO_FLOAT(width, anotherSize->width)
&& FLOAT_EQUAL_TO_FLOAT(height, anotherSize->height));
}
- (BOOL)isEqualToCGSize:(CGSize)size
{
return (FLOAT_EQUAL_TO_FLOAT(width, size.width)
&& FLOAT_EQUAL_TO_FLOAT(height, size.height));
}
- (BOOL)isZero
{
return (FLOAT_EQUAL_TO_ZERO(width)
&& FLOAT_EQUAL_TO_ZERO(height));
}
- (void)setWidth:(CGFloat)newWidth withHeight:(CGFloat)newHeight
{
self->width = newWidth;
self->height = newHeight;
}
- (CGSize)toCGSize
{
return CGSizeMake(width, height);
}
@end
微风不燥,阳光正好,你就像风一样经过这里,愿你停留的片刻温暖舒心。
我是程序员小迷(致力于C、C++、Java、Kotlin、Android、Shell、JavaScript、TypeScript、Python等编程技术的技巧经验分享),若作品对您有帮助,请关注、分享、点赞、收藏、在看、喜欢,您的支持是我们为您提供帮助的最大动力。
欢迎关注。助您在编程路上越走越好!