Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Nov 7, 2023
1 parent 8cd34d6 commit c9c946e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 32 deletions.
31 changes: 10 additions & 21 deletions Sources/Backend/ImageProcessing/Iconset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import Foundation

/// Represents an iconset file.
/// A representation of an iconset file.
struct Iconset {
/// The individual icons contained within the iconset.
let icons: [Icon]
Expand Down Expand Up @@ -35,15 +35,15 @@ struct Iconset {
}

extension Iconset {
/// Sizing and scaling information used to create the various icons in an iconset.
/// Sizing and scaling information used to create the icons in an iconset.
struct Dimension: CustomStringConvertible {
/// The length of each side of the icon.
let length: Int
var length: Int

/// The scaling factor of the icon.
let scale: Int
var scale: Int

/// A size calculated by multiplying `length` by `scale`.
/// A size calculated by multiplying the dimension's length by its scale.
var size: CGSize {
CGSize(width: length * scale, height: length * scale)
}
Expand All @@ -59,12 +59,6 @@ extension Iconset {
"\(length)x\(length)\(scaleDescription)"
}

/// Creates an instance with the given length and scaling factor.
init(length: Int, scale: Int) {
self.length = length
self.scale = scale
}

/// An array of all required sizes and scales for the icons in an iconset.
static let all: [Self] = [16, 32, 128, 256, 512].reduce(into: []) { dimensions, length in
dimensions.append(contentsOf: [
Expand All @@ -78,7 +72,8 @@ extension Iconset {
extension Iconset {
/// An individual icon in an iconset.
struct Icon {
private enum IconValidationError: String, FormattedError {
/// An error that can occur during the validation of an icon.
enum ValidationError: String, FormattedError {
case invalidDimensions = "Image width and height must be equal."

var errorMessage: FormattedText {
Expand All @@ -87,21 +82,15 @@ extension Iconset {
}

/// The image used to create the icon.
let image: Image
var image: Image

/// Sizing and scaling information used to draw the icon's image at the required size.
let dimension: Dimension

/// Creates an icon with the given image and dimension.
init(image: Image, dimension: Dimension) {
self.image = image
self.dimension = dimension
}
var dimension: Dimension

/// Validates the dimensions of the icon, ensuring that the width and height are equal.
func validateDimensions() throws {
guard image.width == image.height else {
throw IconValidationError.invalidDimensions
throw ValidationError.invalidDimensions
}
}

Expand Down
14 changes: 3 additions & 11 deletions Sources/Backend/ImageProcessing/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,13 @@ extension Image {
/// An image destination that writes an image to a url.
struct URLDestination {
/// The url to write the image to.
let url: URL
var url: URL

/// The image to write.
let image: Image
var image: Image

/// An identifier specifying the type of image data to write.
let type: FileType

/// Creates an image destination that writes the given image to the given
/// url, using the data type specified by the given type identifier.
init(url: URL, image: Image, type: FileType) {
self.url = url
self.image = image
self.type = type
}
var type: FileType

/// Writes the image's data to the destination's url.
func write() throws {
Expand Down

0 comments on commit c9c946e

Please sign in to comment.