Rotations and reflections I
Description:
There are exactly eight ways to map a square onto itself by rotation or reflection. We can take its mirror image (reflection in horizontal, vertical, or either of two 45-degree diagonal lines); rotate it (by 90 degrees clockwise, 90 degrees anti-clockwise, or 180 degrees); or just leave it alone.
These eight transformations together comprise the dihedral group Dih(4).
In this kata we're going to write a class Dih4
that represents this collection of rotations and reflections. An object (instance) of this class will have one of eight possible values, corresponding to the eight transformations.
The Dih4
class will need to include at least the following features:
Names or constants for the possible values:
IDENTITY ROTATE_90_ANTICLOCKWISE ROTATE_180 ROTATE_90_CLOCKWISE REFLECT_VERTICAL REFLECT_FORWARD_DIAGONAL REFLECT_HORIZONTAL REFLECT_REVERSE_DIAGONAL
(these are in the same order as in the picture above).
A function
then()
that works out the effect of performing transformations successively. For example, ifr
is the 90-degree clockwise rotation andf
is the reflection with vertical mirror line,r.then(f)
should equal the reflection with reverse-diagonal mirror line.A function
inv()
that gives the inverse (opposite) of a transformation. For example, ifr
is the 90-degree clockwise rotation, thenr.inv()
should equal the 90-degree anticlockwise rotation.Functions
is_rotation()
andis_reflection()
that test whether a transformation is a rotation or a reflection. (The identity transformation is considered to be a rotation (by 0 degrees) but not a reflection.)Tests for equality and inequality: an
equals()
method (Java) or==
and!=
operators (C++).
See the example tests for more examples of how the syntax of Dih4
objects should go.
Note to C++ codewarriors: some of the test cases use const Dih4
objects -- plan accordingly.
Similar Kata:
Stats:
Created | May 12, 2017 |
Published | Jun 1, 2017 |
Warriors Trained | 1422 |
Total Skips | 304 |
Total Code Submissions | 2331 |
Total Times Completed | 232 |
C++ Completions | 168 |
Java Completions | 68 |
Total Stars | 50 |
% of votes with a positive feedback rating | 88% of 42 |
Total "Very Satisfied" Votes | 35 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 8 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 6 kyu |