Home Reference Source Repository

js/CoreGraphics/CGPath.js

  1. 'use strict'
  2.  
  3. //import CGRect from './CGRect'
  4. //import CGLineCap from './CGLineCap'
  5. //import CGLineJoin from './CGLineJoin'
  6. //import CGMutablePath from './CGMutablePath'
  7. //import CGPoint from './CGPoint'
  8. //import CGPathFillRule from './CGPathFillRule'
  9. //import CGPathApplierFunction from './CGPathApplierFunction'
  10.  
  11. const _typeID = null
  12.  
  13. /**
  14. * An immutable graphics path: a mathematical description of shapes or lines to be drawn in a graphics context.
  15. * @access public
  16. * @see https://developer.apple.com/documentation/coregraphics/cgpath
  17. */
  18. export default class CGPath {
  19.  
  20. // Creating Graphics Paths
  21.  
  22. /**
  23. * Create an immutable path of a rectangle.
  24. * @access public
  25. * @constructor
  26. * @param {CGRect} rect - The rectangle to add.
  27. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to the rectangle before it is added to the path.
  28. * @desc This is a convenience function that creates a path of an rectangle. Using this convenience function is more efficient than creating a mutable path and adding an rectangle to it.Calling this function is equivalent to using minX and related functions to find the corners of the rectangle, then using the moveTo(_:x:y:), addLineTo(_:x:y:), and closeSubpath() functions to draw the rectangle.
  29. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411155-init
  30. */
  31. constructor(rect, transform) {
  32.  
  33. // Examining a Graphics Path
  34.  
  35. this._boundingBox = null
  36. this._boundingBoxOfPath = null
  37. this._currentPoint = null
  38. this._isEmpty = false
  39. }
  40.  
  41. /**
  42. * Create an immutable path of an ellipse.
  43. * @access public
  44. * @param {CGRect} rect - The rectangle that bounds the ellipse.
  45. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to the ellipse before it is added to the path.
  46. * @returns {void}
  47. * @desc This is a convenience function that creates a path of an ellipse. Using this convenience function is more efficient than creating a mutable path and adding an ellipse to it.The ellipse is approximated by a sequence of Bézier curves. Its center is the midpoint of the rectangle defined by the rect parameter. If the rectangle is square, then the ellipse is circular with a radius equal to one-half the width (or height) of the rectangle. If the rect parameter specifies a rectangular shape, then the major and minor axes of the ellipse are defined by the width and height of the rectangle. The ellipse forms a complete subpath of the path—that is, the ellipse drawing starts with a move-to operation and ends with a close-subpath operation, with all moves oriented in the clockwise direction. If you supply an affine transform, then the constructed Bézier curves that define the ellipse are transformed before they are added to the path.
  48. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411177-init
  49. */
  50. initEllipseIn(rect, transform) {
  51.  
  52. // Examining a Graphics Path
  53.  
  54. this._boundingBox = null
  55. this._boundingBoxOfPath = null
  56. this._currentPoint = null
  57. this._isEmpty = false
  58. }
  59.  
  60. /**
  61. * Create an immutable path of a rounded rectangle.
  62. * @access public
  63. * @param {CGRect} rect - The rectangle to add.
  64. * @param {number} cornerWidth - The width of the rounded corner sections.
  65. * @param {number} cornerHeight - The height of the rounded corner sections.
  66. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to the rectangle before it is added to the path.
  67. * @returns {void}
  68. * @desc This is a convenience function that creates a path of an rounded rectangle. Using this convenience function is more efficient than creating a mutable path and adding an rectangle to it.Each corner of the rounded rectangle is one-quarter of an ellipse with axes equal to the cornerWidth and cornerHeight parameters. The rounded rectangle forms a complete subpath and is oriented in the clockwise direction.
  69. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411218-init
  70. */
  71. initRoundedRect(rect, cornerWidth, cornerHeight, transform) {
  72.  
  73. // Examining a Graphics Path
  74.  
  75. this._boundingBox = null
  76. this._boundingBoxOfPath = null
  77. this._currentPoint = null
  78. this._isEmpty = false
  79. }
  80.  
  81. // Copying a Graphics Path
  82.  
  83. /**
  84. * Creates an immutable copy of a graphics path.
  85. * @access public
  86. * @returns {?CGPath} -
  87. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411211-copy
  88. */
  89. copy() {
  90. return null
  91. }
  92.  
  93. /**
  94. * Creates an immutable copy of a graphics path transformed by a transformation matrix.
  95. * @access public
  96. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to all elements of the new path.
  97. * @returns {?CGPath} -
  98. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411161-copy
  99. */
  100. copyUsing(transform) {
  101. return null
  102. }
  103.  
  104. /**
  105. * Returns a new path equivalent to the results of drawing the path with a dashed stroke.
  106. * @access public
  107. * @param {number} phase - A value that specifies how far into the dash pattern the line starts, in units of the user space. For example, a value of 0 draws a line starting with the beginning of a dash pattern, and a value of 3 means the line is drawn with the dash pattern starting at three units from its beginning.
  108. * @param {number[]} lengths - An array of values that specify the lengths, in user space coordinates, of the painted and unpainted segments of the dash pattern.For example, the array [2,3] sets a dash pattern that alternates between a 2-unit-long painted segment and a 3-unit-long unpainted segment. The array [1,3,4,2] sets the pattern to a 1-unit painted segment, a 3-unit unpainted segment, a 4-unit painted segment, and a 2-unit unpainted segment.Pass an empty array to clear the dash pattern so that all stroke drawing in the context uses solid lines.
  109. * @param {CGAffineTransform} transform - An affine transform to apply to the path before dashing. Defaults to the identity transform if not specified.
  110. * @returns {CGPath} -
  111. * @desc The new path is created so that filling the new path draws the same pixels as stroking the original path with the specified dash parameters.
  112. * @see https://developer.apple.com/documentation/coregraphics/cgpath/2427137-copy
  113. */
  114. copyDashingWithPhase(phase, lengths, transform) {
  115. return null
  116. }
  117.  
  118. /**
  119. * Returns a new path equivalent to the results of drawing the path with a solid stroke.
  120. * @access public
  121. * @param {number} lineWidth - The line width to use, in user space units. The value must be greater than 0.
  122. * @param {CGLineCap} lineCap - The line cap style to render. (For equivalent CGContext drawing methods, the default style is butt.)
  123. * @param {CGLineJoin} lineJoin - The line join style to render. (For equivalent CGContext drawing methods, the default style is miter.)
  124. * @param {number} miterLimit - A value that limits how sharp individual corners in the path can be when using the miter line join style. When the ratio of a the length required for a mitered corner to the line width exceeds this value, that corner uses the bevel style instead.
  125. * @param {CGAffineTransform} transform - An affine transform to apply to the path before dashing. Defaults to the identity transform if not specified.
  126. * @returns {CGPath} -
  127. * @desc The new path is created so that filling the new path draws the same pixels as stroking the original path with the specified line style.
  128. * @see https://developer.apple.com/documentation/coregraphics/cgpath/2427133-copy
  129. */
  130. copyStrokingWithWidth(lineWidth, lineCap, lineJoin, miterLimit, transform) {
  131. return null
  132. }
  133.  
  134. /**
  135. * Creates a mutable copy of an existing graphics path.
  136. * @access public
  137. * @returns {?CGMutablePath} -
  138. * @desc You can modify a mutable graphics path by calling the various path geometry functions, such as addArc(_:x:y:radius:startAngle:endAngle:clockwise:), addLineTo(_:x:y:), and moveTo(_:x:y:).
  139. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411196-mutablecopy
  140. */
  141. mutableCopy() {
  142. return null
  143. }
  144.  
  145. /**
  146. * Creates a mutable copy of a graphics path transformed by a transformation matrix.
  147. * @access public
  148. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to all elements of the new path.
  149. * @returns {?CGMutablePath} -
  150. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411150-mutablecopy
  151. */
  152. mutableCopyUsing(transform) {
  153. return null
  154. }
  155.  
  156. // Examining a Graphics Path
  157.  
  158. /**
  159. * Returns whether the specified point is interior to the path.
  160. * @access public
  161. * @param {CGPoint} point - The point to check.
  162. * @param {CGPathFillRule} rule - The rule for determining which areas to treat as the interior of the path. Defaults to the winding rule if not specified.
  163. * @param {CGAffineTransform} transform - An affine transform to apply to the point before checking for containment in the path. Defaults to the identity transform if not specified.
  164. * @returns {boolean} -
  165. * @desc A point is contained in a path if it would be inside the painted region when the path is filled.
  166. * @see https://developer.apple.com/documentation/coregraphics/cgpath/2427117-contains
  167. */
  168. containsUsing(point, rule, transform) {
  169. return false
  170. }
  171.  
  172. /**
  173. * Indicates whether or not a graphics path represents a rectangle.
  174. * @access public
  175. * @param {?UnsafeMutablePointer<CGRect>} rect - On input, a pointer to an uninitialized rectangle. If the specified path represents a rectangle, on return contains a copy of the rectangle.
  176. * @returns {boolean} -
  177. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411163-isrect
  178. */
  179. isRect(rect) {
  180. return false
  181. }
  182. /**
  183. * Returns the bounding box containing all points in a graphics path.
  184. * @type {CGRect}
  185. * @desc The bounding box is the smallest rectangle completely enclosing all points in the path, including control points for Bézier and quadratic curves.
  186. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411165-boundingbox
  187. */
  188. get boundingBox() {
  189. return this._boundingBox
  190. }
  191. /**
  192. * Returns the bounding box of a graphics path.
  193. * @type {CGRect}
  194. * @desc The path bounding box is the smallest rectangle completely enclosing all points in the path but not including control points for Bézier and quadratic curves.
  195. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411200-boundingboxofpath
  196. */
  197. get boundingBoxOfPath() {
  198. return this._boundingBoxOfPath
  199. }
  200. /**
  201. * Returns the current point in a graphics path.
  202. * @type {CGPoint}
  203. * @desc If the path is empty—that is, if it has no elements—this function returns CGPointZero (see CGGeometry). To determine whether a path is empty, use isEmpty.
  204. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411132-currentpoint
  205. */
  206. get currentPoint() {
  207. return this._currentPoint
  208. }
  209. /**
  210. * Indicates whether or not a graphics path is empty.
  211. * @type {boolean}
  212. * @desc An empty path contains no elements.
  213. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411149-isempty
  214. */
  215. get isEmpty() {
  216. return this._isEmpty
  217. }
  218.  
  219. // Applying a Function to the Elements of a Path
  220.  
  221. /**
  222. * For each element in a graphics path, calls a custom applier function.
  223. * @access public
  224. * @param {?Object} info - A pointer to the user data that Core Graphics will pass to the function being applied, or NULL.
  225. * @param {CGPathApplierFunction} _function -
  226. * @returns {void}
  227. * @desc For each element in the specified path, Core Graphics calls the applier function, which can examine (but not modify) the element.
  228. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411203-apply
  229. */
  230. apply(info, _function) {
  231. }
  232.  
  233. // Working with Core Foundation Types
  234. /**
  235. * Returns the Core Foundation type identifier for Core Graphics graphics paths.
  236. * @type {CFTypeID}
  237. * @desc
  238. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411192-typeid
  239. */
  240. static get typeID() {
  241. return _typeID
  242. }
  243.  
  244. // Initializers
  245.  
  246. /**
  247. * Creates a dashed copy of another path.
  248. * @access public
  249. * @param {CGPath} path - The path to copy.
  250. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to elements of the converted path before adding them to the new path.
  251. * @param {number} phase - A value that specifies how far into the dash pattern the line starts, in units of the user space. For example, passing a value of 3 means the line is drawn with the dash pattern starting at three units from its beginning. Passing a value of 0 draws a line starting with the beginning of a dash pattern.
  252. * @param {?UnsafePointer<CGFloat>} lengths - An array of values that specify the lengths of the painted segments and unpainted segments, respectively, of the dash pattern—or NULL for no dash pattern.For example, passing an array with the values [2,3] sets a dash pattern that alternates between a 2-user-space-unit-long painted segment and a 3-user-space-unit-long unpainted segment. Passing the values [1,3,4,2] sets the pattern to a 1-unit painted segment, a 3-unit unpainted segment, a 4-unit painted segment, and a 2-unit unpainted segment.
  253. * @param {number} count - If the lengths parameter specifies an array, pass the number of elements in the array. Otherwise, pass 0.
  254. * @returns {void}
  255. * @desc The new path is created so that filling the new path draws the same pixels as stroking the original path with the specified dash parameters.
  256. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411134-init
  257. */
  258. init__byDashing(path, transform, phase, lengths, count) {
  259.  
  260. // Examining a Graphics Path
  261.  
  262. this._boundingBox = null
  263. this._boundingBoxOfPath = null
  264. this._currentPoint = null
  265. this._isEmpty = false
  266. }
  267.  
  268. /**
  269. * Creates a stroked copy of another path.
  270. * @access public
  271. * @param {CGPath} path - The path to copy.
  272. * @param {?UnsafePointer<CGAffineTransform>} transform - A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Core Graphics applies the transformation to elements of the converted path before adding them to the new path.
  273. * @param {number} lineWidth - The line width to use, in user space units. The value must be greater than 0.
  274. * @param {CGLineCap} lineCap - A line cap style constant—butt (the default), round, or square.
  275. * @param {CGLineJoin} lineJoin - A line join value—miter (the default), round, or bevel.
  276. * @param {number} miterLimit - The miter limit to use.
  277. * @returns {void}
  278. * @desc The new path is created so that filling the new path draws the same pixels as stroking the original path.If the line join style is set to kCGLineJoinMiter, Core Graphics uses the miter limit to determine whether the lines should be joined with a bevel instead of a miter. Core Graphics divides the length of the miter by the line width. If the result is greater than the miter limit, Core Graphics converts the style to a bevel.
  279. * @see https://developer.apple.com/documentation/coregraphics/cgpath/1411128-init
  280. */
  281. init__byStroking(path, transform, lineWidth, lineCap, lineJoin, miterLimit) {
  282.  
  283. // Examining a Graphics Path
  284.  
  285. this._boundingBox = null
  286. this._boundingBoxOfPath = null
  287. this._currentPoint = null
  288. this._isEmpty = false
  289. }
  290. }