Skip to content

Commit

Permalink
Merge pull request #104 from FayCarsons/fix-repeat
Browse files Browse the repository at this point in the history
Refactor repeat
  • Loading branch information
FayCarsons authored Mar 1, 2024
2 parents 06ae924 + 47a768c commit 38a327b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/transform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ let rec rotate degrees = function
| Circle circle' -> Circle { circle' with c = rotate_point degrees circle'.c }
| Ellipse ellipse' ->
Ellipse { ellipse' with c = rotate_point degrees ellipse'.c }
| Line _line -> failwith "Not Implemented"
| Line line' -> Line { line' with b = rotate_point degrees line'.b }
| Polygon polygon' ->
Polygon
{
Expand All @@ -87,11 +87,14 @@ let rec rotate degrees = function
let compose f g x = g (f x)

let repeat n op shape =
let match_list l =
match l with [] -> [ op shape ] | last :: _ -> op last :: l
let rec repeat' = function
| 0, shapes -> shapes
| n, [] -> repeat' (n - 1, [ shape ])
| n, (transformed :: _ as shapes) ->
repeat' (n - 1, op transformed :: shapes)
in
let shapes = List.fold_right (fun _ acc -> match_list acc) (Util.range n) [] in
complex shapes
Complex (repeat' (n, []))


(** Takes a function and a shape and returns a new shape with the
function applied to the original's color *)
Expand Down

0 comments on commit 38a327b

Please sign in to comment.