I want to create a function that takes any equation and return cgpath. How do I make my condition for the equation a generic one? I have a temporary holder for the equation in the parameter as a String.
Here is the function I wrote which draws a path for the math function (x-4)^2 + (y-3)^2 = 4. I want to move this math equation as a parameter so I can use this function to solve any equation.
func createPath(for equation: String) -> CGPath {
let path = CGMutablePath()
var firstPoint = true
for x in -100...100 {
for y in -100...100 {
if pow(Decimal(x - 4), 2) + pow(Decimal(y - 3), 2) == 4 {
if firstPoint {
path.move(to: CGPoint(x: x, y: y))
firstPoint = false
} else {
path.addLine(to: CGPoint(x: x, y: y))
}
}
}
}
return path
}