MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / forBlocksAlongLine

Function forBlocksAlongLine

source/base/StarBlocksAlongLine.hpp:11–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9// returns true after iterating through every cell otherwise.
10template <typename Scalar>
11bool forBlocksAlongLine(Vector<Scalar, 2> origin, Vector<Scalar, 2> const& dxdy, function<bool(int, int)> callback) {
12 Vector<Scalar, 2> remote = origin + dxdy;
13
14 double dx = dxdy[0];
15 if (dx < 0)
16 dx *= -1;
17
18 double dy = dxdy[1];
19 if (dy < 0)
20 dy *= -1;
21
22 double oxfloor = floor(origin[0]);
23 double oyfloor = floor(origin[1]);
24 double rxfloor = floor(remote[0]);
25 double ryfloor = floor(remote[1]);
26
27 if (dx == 0) {
28 if (oyfloor < ryfloor) {
29 for (int i = oyfloor; i <= ryfloor; ++i) {
30 if (!callback(oxfloor, i))
31 return false;
32 }
33 } else {
34 for (int i = oyfloor; i >= ryfloor; --i) {
35 if (!callback(oxfloor, i))
36 return false;
37 }
38 }
39 return true;
40
41 } else if (dy == 0) {
42 if (oxfloor < rxfloor) {
43 for (int i = oxfloor; i <= rxfloor; ++i) {
44 if (!callback(i, oyfloor))
45 return false;
46 }
47 } else {
48 for (int i = oxfloor; i >= rxfloor; --i) {
49 if (!callback(i, oyfloor))
50 return false;
51 }
52 }
53 return true;
54
55 } else {
56 int x = oxfloor;
57 int y = oyfloor;
58
59 int n = 1;
60 int x_inc, y_inc;
61 double error;
62
63 if (dxdy[0] > 0) {
64 x_inc = 1;
65 n += int(rxfloor) - x;
66 error = (oxfloor + 1 - origin[0]) * dy;
67 } else {
68 x_inc = -1;

Callers 1

testLineFunction · 0.85

Calls

no outgoing calls

Tested by 1

testLineFunction · 0.68