aboutsummaryrefslogtreecommitdiff
path: root/dep/g3dlite/source/Vector2int16.cpp
blob: 16893eb17526977b65916a3cfedf07eb64c8bbf4 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
 \file G3D/Vector2int16.cpp
 
 \author Morgan McGuire, http://graphics.cs.williams.edu
  
 \created 2003-08-09
 \edited  2011-01-06
 */

#include "G3D/platform.h"
#include "G3D/g3dmath.h"
#include "G3D/Vector2int16.h"
#include "G3D/Vector2.h"
#include "G3D/BinaryInput.h"
#include "G3D/BinaryOutput.h"
#include "G3D/Any.h"
#include "G3D/Vector2int32.h"

namespace G3D {

Vector2int16::Vector2int16(const class Vector2int32& v) : x(v.x), y(v.y) {}

Vector2int16::Vector2int16(const Any& any) {
    any.verifyName("Vector2int16", "Point2int16");
    any.verifyType(Any::TABLE, Any::ARRAY);
    any.verifySize(2);

    if (any.type() == Any::ARRAY) {
        x = any[0];
        y = any[1];
    } else {
        // Table
        x = any["x"];
        y = any["y"];
    }
}


Vector2int16& Vector2int16::operator=(const Any& a) {
    *this = Vector2int16(a);
    return *this;
}


Any Vector2int16::toAny() const {
    Any any(Any::ARRAY, "Vector2int16");
    any.append(x, y);
    return any;
}

Vector2int16::Vector2int16(const class Vector2& v) {
    x = (int16)iFloor(v.x + 0.5);
    y = (int16)iFloor(v.y + 0.5);
}


Vector2int16::Vector2int16(class BinaryInput& bi) {
    deserialize(bi);
}


void Vector2int16::serialize(class BinaryOutput& bo) const {
    bo.writeInt16(x);
    bo.writeInt16(y);
}


void Vector2int16::deserialize(class BinaryInput& bi) {
    x = bi.readInt16();
    y = bi.readInt16();
}


Vector2int16 Vector2int16::clamp(const Vector2int16& lo, const Vector2int16& hi) {
    return Vector2int16(iClamp(x, lo.x, hi.x), iClamp(y, lo.y, hi.y));
}


}