aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkIPoint16.h
blob: 27052b3f2a76c3c4e18e6404bf0aa505c9304e32 (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
/*
 * Copyright 2018 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkIPoint16_DEFINED
#define SkIPoint16_DEFINED

#include "SkTypes.h"

/** \struct SkIPoint16
 SkIPoint16 holds two 16 bit integer coordinates.
 */
struct SkIPoint16 {
    int16_t fX; //!< x-axis value used by SkIPoint16

    int16_t fY; //!< y-axis value used by SkIPoint16

    /** Sets fX to x, fY to y. If SK_DEBUG is defined, asserts
     if x or y does not fit in 16 bits.

     @param x  integer x-axis value of constructed SkIPoint
     @param y  integer y-axis value of constructed SkIPoint
     @return   SkIPoint16 (x, y)
     */
    static constexpr SkIPoint16 Make(int x, int y) {
        return {SkToS16(x), SkToS16(y)};
    }

    /** Returns x-axis value of SkIPoint16.

     @return  fX
     */
    int16_t x() const { return fX; }

    /** Returns y-axis value of SkIPoint.

     @return  fY
     */
    int16_t y() const { return fY; }

    /** Sets fX to x and fY to y.

     @param x  new value for fX
     @param y  new value for fY
     */
    void set(int x, int y) {
        fX = SkToS16(x);
        fY = SkToS16(y);
    }
};

#endif