| 1 | /* | 
|---|
| 2 | * Copyright 2018 Google Inc. | 
|---|
| 3 | * | 
|---|
| 4 | * Use of this source code is governed by a BSD-style license that can be | 
|---|
| 5 | * found in the LICENSE file. | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef SkIPoint16_DEFINED | 
|---|
| 9 | #define SkIPoint16_DEFINED | 
|---|
| 10 |  | 
|---|
| 11 | #include "include/core/SkTypes.h" | 
|---|
| 12 | #include "include/private/SkTo.h" | 
|---|
| 13 |  | 
|---|
| 14 | /** \struct SkIPoint16 | 
|---|
| 15 | SkIPoint16 holds two 16 bit integer coordinates. | 
|---|
| 16 | */ | 
|---|
| 17 | struct SkIPoint16 { | 
|---|
| 18 | int16_t fX; //!< x-axis value used by SkIPoint16 | 
|---|
| 19 |  | 
|---|
| 20 | int16_t fY; //!< y-axis value used by SkIPoint16 | 
|---|
| 21 |  | 
|---|
| 22 | /** Sets fX to x, fY to y. If SK_DEBUG is defined, asserts | 
|---|
| 23 | if x or y does not fit in 16 bits. | 
|---|
| 24 |  | 
|---|
| 25 | @param x  integer x-axis value of constructed SkIPoint | 
|---|
| 26 | @param y  integer y-axis value of constructed SkIPoint | 
|---|
| 27 | @return   SkIPoint16 (x, y) | 
|---|
| 28 | */ | 
|---|
| 29 | static constexpr SkIPoint16 Make(int x, int y) { | 
|---|
| 30 | return {SkToS16(x), SkToS16(y)}; | 
|---|
| 31 | } | 
|---|
| 32 |  | 
|---|
| 33 | /** Returns x-axis value of SkIPoint16. | 
|---|
| 34 |  | 
|---|
| 35 | @return  fX | 
|---|
| 36 | */ | 
|---|
| 37 | int16_t x() const { return fX; } | 
|---|
| 38 |  | 
|---|
| 39 | /** Returns y-axis value of SkIPoint. | 
|---|
| 40 |  | 
|---|
| 41 | @return  fY | 
|---|
| 42 | */ | 
|---|
| 43 | int16_t y() const { return fY; } | 
|---|
| 44 |  | 
|---|
| 45 | /** Sets fX to x and fY to y. | 
|---|
| 46 |  | 
|---|
| 47 | @param x  new value for fX | 
|---|
| 48 | @param y  new value for fY | 
|---|
| 49 | */ | 
|---|
| 50 | void set(int x, int y) { | 
|---|
| 51 | fX = SkToS16(x); | 
|---|
| 52 | fY = SkToS16(y); | 
|---|
| 53 | } | 
|---|
| 54 | }; | 
|---|
| 55 |  | 
|---|
| 56 | #endif | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|