1// Aseprite
2// Copyright (C) 2019-2022 Igara Studio S.A.
3// Copyright (C) 2017 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "app/util/wrap_point.h"
13
14#include "app/util/wrap_value.h"
15
16#include <algorithm>
17
18namespace app {
19
20gfx::Point wrap_point(const filters::TiledMode tiledMode,
21 const gfx::Size& spriteSize,
22 const gfx::Point& pt,
23 const bool clamp)
24{
25 gfx::Point out;
26
27 if (int(tiledMode) & int(filters::TiledMode::X_AXIS))
28 out.x = wrap_value(pt.x, spriteSize.w);
29 else if (clamp)
30 out.x = std::clamp(pt.x, 0, spriteSize.w-1);
31 else
32 out.x = pt.x;
33
34 if (int(tiledMode) & int(filters::TiledMode::Y_AXIS))
35 out.y = wrap_value(pt.y, spriteSize.h);
36 else if (clamp)
37 out.y = std::clamp(pt.y, 0, spriteSize.h-1);
38 else
39 out.y = pt.y;
40
41 return out;
42}
43
44gfx::PointF wrap_pointF(const filters::TiledMode tiledMode,
45 const gfx::Size& spriteSize,
46 const gfx::PointF& pt)
47{
48 gfx::PointF out;
49
50 if (int(tiledMode) & int(filters::TiledMode::X_AXIS))
51 out.x = wrap_value<double>(pt.x, spriteSize.w);
52 else
53 out.x = pt.x;
54
55 if (int(tiledMode) & int(filters::TiledMode::Y_AXIS))
56 out.y = wrap_value<double>(pt.y, spriteSize.h);
57 else
58 out.y = pt.y;
59
60 return out;
61}
62
63} // namespace app
64