PhotoMatrix
public class PhotoMatrix
A 2-d matrix of photos that can be rendered as a UIImage.
Specification Properties:
- photos[col,row] : the possibly-nil photo stored at the given column and row.
- columns : Int - the number of columns
- rows : Int - the nubmer of rows
- tileSize : Size - the size to render each photo stored in the matrix
Abstract Invariant:
- all photos stored in the matrix must have size == tileSize.
- For all photo, count[photo] == number of times photo appears in photos.
-
Number of rows in the matrix
Declaration
Swift
public let rows: Int
-
Number of columns in the matrix
Declaration
Swift
public let columns: Int
-
The size of each photo in the matrix
Declaration
Swift
public let tileSize: Size
-
Create a new PhotoMatrix with the given parameters.
Effects: Creates a new PhotoMatrix w/ the given properties.
Declaration
Swift
public init(columns: Int, rows: Int, tileSize: Size)
-
Get/set the photo at the given column and row.
Requires:
- (column,row) must be in the bounds of the matrix, and
- any photo stored in the matrix must have size == tileSize.
Declaration
Swift
public subscript(column: Int, row: Int) -> Photo? { get set }
-
The photo matrix rendered as a UIImage. Any empty matrix slots are left as black rectangles.
Note
This may be computation expensive and should not run on the main UI thread.Declaration
Swift
public var image: UIImage { get }
-
Counts how many times a photo appears in the matrix.
Note
This is O(1).
Declaration
Swift
public func count(of photo: Photo) -> Int
Parameters
photo
The photo to look for.
Return Value
how many entries in the photos contains that photo.