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

Method splitLine

source/base/StarWorldGeometry.cpp:98–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98StaticList<Line2F, 2> WorldGeometry::splitLine(Line2F line, bool preserveDirection) const {
99 if (m_size[0] == 0)
100 return {line};
101
102 bool swapDirection = line.makePositive() && preserveDirection;
103 Vec2F minWrap = xwrap(line.min());
104
105 // diff is safe because we're looking for the line gnostic diff
106 Line2F lineWrap = Line2F(minWrap, minWrap + line.diff());
107
108 // Since min is wrapped, we're only checking to see if max is on the other
109 // side of the wrap point
110 if (lineWrap.max()[0] > m_size[0]) {
111 Vec2F intersection = lineWrap.intersection(Line2F(Vec2F(m_size[0], 0), Vec2F(m_size)), true).point;
112 if (swapDirection)
113 return {Line2F(lineWrap.max() - Vec2F(m_size[0], 0), Vec2F(0, intersection[1])),
114 Line2F(Vec2F(m_size[0], intersection[1]), lineWrap.min())};
115 else
116 return {Line2F(lineWrap.min(), Vec2F(m_size[0], intersection[1])),
117 Line2F(Vec2F(0, intersection[1]), lineWrap.max() - Vec2F(m_size[0], 0))};
118 } else {
119 if (swapDirection)
120 lineWrap.reverse();
121 return {lineWrap};
122 }
123}
124
125StaticList<Line2F, 2> WorldGeometry::splitLine(Line2F line, Vec2F const& position, bool preserveDirection) const {
126 line.translate(position);

Callers 1

collidingTilesAlongLineFunction · 0.80

Calls 7

makePositiveMethod · 0.45
minMethod · 0.45
diffMethod · 0.45
maxMethod · 0.45
intersectionMethod · 0.45
reverseMethod · 0.45
translateMethod · 0.45

Tested by

no test coverage detected