summaryrefslogtreecommitdiff
path: root/chapter2/point.cxx
blob: 9b56f9e1c07278ecc03ea095021b714d29ae5260 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// FILE: point.cxx
// CLASS IMPLEMENTED: point (See point.h for documentation.)

#include "point.h"

namespace main_savitch_2A
{
    
    point::point(double initial_x, double initial_y)
    {
        x = initial_x;   // Constructor sets the point to a given position.
        y = initial_y;
    }

    
    void point::shift(double x_amount, double y_amount)
    {
        x += x_amount;
        y += y_amount;   
    }

    
    void point::rotate90( )
    {
        double new_x;
        double new_y;

        new_x = y;  // For a 90 degree clockwise rotation, the new x is the original y,
        new_y = -x; // and the new y is -1 times the original x.
        x = new_x;
        y = new_y; 
    }
}