Rectangle
open class Rectangle : Polygon, CGDrawable, SVGDrawable, RayTracable
extension Rectangle: Intersectable
extension Rectangle: Hashable
A rectangle
-
Origin X coordinate
Declaration
Swift
public var x: Double -
Origin Y coordinate
Declaration
Swift
public var y: Double -
Width of the rectangle
Declaration
Swift
public var width: Double -
Height of the rectangle
Declaration
Swift
public var height: Double -
Instantiate a new
RectangleDeclaration
Swift
public init(x: Double, y: Double, width: Double, height: Double)Parameters
xOrigin X coordinate
yOrigin Y coordinate
widthWidth of the rectangle
heightHeight of the rectangle
-
Instantiate a new
RectangleDeclaration
Swift
public convenience init(centerX: Double, centerY: Double, width: Double, height: Double)Parameters
xOrigin X coordinate
yOrigin Y coordinate
widthWidth of the rectangle
heightHeight of the rectangle
-
Instantiate a new
RectangleDeclaration
Swift
public init(center: Vector, width: Double, height: Double)Parameters
xOrigin X coordinate
yOrigin Y coordinate
widthWidth of the rectangle
heightHeight of the rectangle
-
A Rectangle that contains the receiver
Declaration
Swift
public var boundingBox: Rectangle { get } -
Returns the coordinates of the center of the Rectangle
Declaration
Swift
public var center: Vector { get set } -
Coordinate of the top-left corner
Declaration
Swift
public var topLeft: Vector { get } -
Coordinate of the top-right corner
Declaration
Swift
public var topRight: Vector { get } -
Coordinate of the bottom-left corner
Declaration
Swift
public var bottomLeft: Vector { get } -
Coordinate of the botom-left corner
Declaration
Swift
public var bottomRight: Vector { get } -
The minimum
xcoordinateDeclaration
Swift
public var minX: Double { get } -
The minimum
ycoordinateDeclaration
Swift
public var minY: Double { get } -
The maximum
xcoordinateDeclaration
Swift
public var maxX: Double { get } -
The maximum
ycoordinateDeclaration
Swift
public var maxY: Double { get } -
Determine whether the specified point is in the rectangle
Tests whether the point is between the left and right edges, and top and bottom edges
Declaration
Swift
public func contains(_ point: Vector) -> BoolParameters
pointWhether the point is inside the rectangle
-
Draw the receiver in the specified context
Declaration
Swift
open func draw(in context: CGContext)Parameters
contextContext in which to draw
-
Draw a representation of the receiver meant for debugging the shape in the specified context
Declaration
Swift
open func debugDraw(in context: CGContext)Parameters
contextContext in which to draw
-
Create a
XMLElementrepresenting the receiverDeclaration
Swift
open func svgElement() -> XMLElement -
Create a grid of rectangles contained by the receiver.
Declaration
Swift
public func frames(rows: Int, columns: Int, margin: Int = 50) -> [Rectangle]Parameters
rowsNumber of rows
columnsNumber of columns
marginMargin between frames
Return Value
An array of the new
Rectangles
-
Calculate the intersection point of a ray and the the Rectangle
Adapted from Amy Williams et al.
Parameters
originOrigin of the ray
dirDirection of the ray
Return Value
The point of intersection, if the ray intersections the line
-
Declaration
Swift
public func modifyRay(_ ray: Ray) -
Calculate points of intersection with another shape.
Declaration
Swift
func intersections(with otherShape: Intersectable) -> [Vector]Parameters
otherShapeThe shape with which to find intersection points
Return Value
An array of Vectors
-
Calculate points of intersection with a
RectangleDeclaration
Swift
func intersection(with otherShape: Rectangle) -> [Vector]Parameters
otherShapeThe shape with which to find intersection points
Return Value
An array of Vectors
-
Create a Bézier path of the rectangle between the two points.
This method returns a single
BezierPathwhich draws lines from the start to end, passing through each corner.Declaration
Swift
public func bezierCurve(start: Radians, end: Radians) -> [BezierPath]Parameters
startStarting angle
endEnding Angle
Return Value
An array of
BezierPathwhich draw the shape -
Returns a Boolean value indicating whether two values are equal.
Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.
Declaration
Swift
public static func == (lhs: Rectangle, rhs: Rectangle) -> Bool -
Declaration
Swift
public func hash(into hasher: inout Hasher)
View on GitHub
Rectangle Class Reference