Difficulty |
2 |
Prerequisites |
|
Reading material |
In this extension, we define the usual transformations on patterns:
Translation |
|
Scaling |
|
Rotation |
1. 2D Implementation
Let’s start by creating the files that will host the new code.
Create files Include |
1.1. transform
We’ll start with a very general transform
function.
The more specific transformations (translation, scaling, rotation) will be able to rely on this function, making their implementation very short and simple.
Implement a function with signature
|
1.2. Transformations
Once you defined the transform
function, it’s trivial to define the others.
Define
Rely on the transformations defined in |
2. 3D Implementation
The 3D variants of the transformations are nearly identical.
Define the following functions:
|
3. Finishing Touches
Expose all functions (except the |
4. Evaluation
Render the following script:
|
-
Show that
transform
is implemented using a lambda pattern. -
Write tests for each of the transformations.
-
Make use of a simple
Pattern2D
/Pattern3D
that makes checking your transformations easy. -
Make sure that translation and scaling work in the correct direction, i.e., that
scale(2, 2, p)
enlarges the pattern and not shrink it.