view test/v2d.d @ 109:5ab8e92611f9 trunk

[svn r113] Added initial support for associative arrays (AAs). Fixed some problems with the string runtime support functions. Fixed initialization of array of structs. Fixed slice assignment where LHS is slice but RHS is dynamic array. Fixed problems with result of assignment expressions. Fixed foreach problems with key type mismatches.
author lindquist
date Wed, 21 Nov 2007 04:13:15 +0100
parents c53b6e3fe49a
children d9d5d59873d8
line wrap: on
line source

struct V2D(T)
{
    T x,y;

    T dot(ref V2D v)
    {
        return x*v.x + y*v.y;
    }

    V2D opAdd(ref V2D v)
    {
        return V2D(x+v.x, y+v.y);
    }
}

alias V2D!(float) V2Df;

void main()
{
    printf("V2D test\n");
    auto up = V2Df(0.0f, 1.0f);
    auto right = V2Df(1.0f, 0.0f);
    assert(up.dot(right) == 0.0f);
    auto upright = up + right;
    assert(upright.x == 1.0f && upright.y == 1.0f);
    auto copy = upright;
    copy.x++;
    assert(copy.x > upright.x);
    printf("  SUCCESS\n");
}