-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
125 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
(* point -> point arithmetic *) | ||
open Shape | ||
let ( /~ ) p1 p2 = { x = p1.x /. p2.x; y = p1.x /. p2.x } | ||
|
||
(* point -> scalar arithmetic *) | ||
let ( -! ) { x; y } scalar = { x = x -. scalar; y = y -. scalar } | ||
let ( /! ) { x; y } scalar = { x = x /. scalar; y = y /. scalar } | ||
let ( *! ) { x; y } scalar = { x = x *. scalar; y = y *. scalar } | ||
let pmap f { x; y } = { x = f x; y = f y } | ||
|
||
(* Tuple/Vector ops *) | ||
let tmap f (x, y) = (f x, f y) | ||
let tmap3 f (a, b, c) = (f a, f b, f c) | ||
let tmap4 f (a, b, c, d) = (f a, f b, f c, f d) | ||
|
||
(** Function composition *) | ||
let ( >> ) f g x = g (f x) | ||
|
||
(* Partitions point in a polygon into faces *) | ||
let rec take n lst = | ||
match (n, lst) with | ||
| 0, _ -> ([], lst) | ||
| _, [] -> ([], []) | ||
| n, x :: xs -> | ||
let taken, rest = take (n - 1) xs in | ||
(x :: taken, rest) | ||
|
||
let rec partition n ?(step = 0) lst = | ||
match lst with | ||
| [] -> [] | ||
| lst' -> | ||
let taken, _ = take n lst in | ||
if List.length taken = n then | ||
taken | ||
:: | ||
partition n ~step (List.tl lst') | ||
else [] | ||
|
||
(* Misc *) | ||
let range n = List.init n Fun.id |
Oops, something went wrong.