POPGeometry.mm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. Copyright (c) 2014-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the BSD-style license found in the
  5. LICENSE file in the root directory of this source tree. An additional grant
  6. of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #import "POPGeometry.h"
  9. #if !TARGET_OS_IPHONE
  10. @implementation NSValue (POP)
  11. + (NSValue *)valueWithCGPoint:(CGPoint)point {
  12. return [NSValue valueWithBytes:&point objCType:@encode(CGPoint)];
  13. }
  14. + (NSValue *)valueWithCGSize:(CGSize)size {
  15. return [NSValue valueWithBytes:&size objCType:@encode(CGSize)];
  16. }
  17. + (NSValue *)valueWithCGRect:(CGRect)rect {
  18. return [NSValue valueWithBytes:&rect objCType:@encode(CGRect)];
  19. }
  20. + (NSValue *)valueWithCFRange:(CFRange)range {
  21. return [NSValue valueWithBytes:&range objCType:@encode(CFRange)];
  22. }
  23. + (NSValue *)valueWithCGAffineTransform:(CGAffineTransform)transform
  24. {
  25. return [NSValue valueWithBytes:&transform objCType:@encode(CGAffineTransform)];
  26. }
  27. - (CGPoint)CGPointValue {
  28. CGPoint result;
  29. [self getValue:&result];
  30. return result;
  31. }
  32. - (CGSize)CGSizeValue {
  33. CGSize result;
  34. [self getValue:&result];
  35. return result;
  36. }
  37. - (CGRect)CGRectValue {
  38. CGRect result;
  39. [self getValue:&result];
  40. return result;
  41. }
  42. - (CFRange)CFRangeValue {
  43. CFRange result;
  44. [self getValue:&result];
  45. return result;
  46. }
  47. - (CGAffineTransform)CGAffineTransformValue {
  48. CGAffineTransform result;
  49. [self getValue:&result];
  50. return result;
  51. }
  52. @end
  53. #endif
  54. #if TARGET_OS_IPHONE
  55. #import "POPDefines.h"
  56. #if SCENEKIT_SDK_AVAILABLE
  57. #import <SceneKit/SceneKit.h>
  58. /**
  59. Dirty hacks because iOS is weird and decided to define both SCNVector3's and SCNVector4's objCType as "t". However @encode(SCNVector3) and @encode(SCNVector4) both return the proper definition ("{SCNVector3=fff}" and "{SCNVector4=ffff}" respectively)
  60. [[NSValue valueWithSCNVector3:SCNVector3Make(0.0, 0.0, 0.0)] objcType] returns "t", whereas it should return "{SCNVector3=fff}".
  61. *flips table*
  62. */
  63. @implementation NSValue (SceneKitFixes)
  64. + (NSValue *)valueWithSCNVector3:(SCNVector3)vec3 {
  65. return [NSValue valueWithBytes:&vec3 objCType:@encode(SCNVector3)];
  66. }
  67. + (NSValue *)valueWithSCNVector4:(SCNVector4)vec4 {
  68. return [NSValue valueWithBytes:&vec4 objCType:@encode(SCNVector4)];
  69. }
  70. @end
  71. #endif
  72. #endif