Пример #1
0
std::vector<point> continue_line(const std::vector<point> &line, const int distance)
{
    const point start = line.back();
    point end = line.back();
    const std::pair<double, double> slope = slope_of(line);
    end.x += distance * slope.first;
    end.y += distance * slope.second;
    return line_to(start.x, start.y, end.x, end.y, 0);
}
Пример #2
0
tripoint move_along_line( const tripoint &loc, const std::vector<tripoint> &line, const int distance )
{
    // May want to optimize this, but it's called fairly infrequently as part of specific attack
    // routines, erring on the side of readability.
    tripoint res( loc );
    const auto slope = slope_of( line );
    res.x += distance * slope.first.first;
    res.y += distance * slope.first.second;
    res.z += distance * slope.second;
    return res;
}
Пример #3
0
std::vector<tripoint> continue_line(const std::vector<tripoint> &line, const int distance)
{ // May want to optimize this, but it's called fairly infrequently as part of specific attack
  // routines, erring on the side of readability.
    tripoint start;
    tripoint end;
    start = end = line.back();
    // slope <<x,y>,z>
    std::pair<std::pair<double, double>, double> slope;
    slope = slope_of(line);
    end.x += int(distance * slope.first.first);
    end.y += int(distance * slope.first.second);
    end.z += int(distance * slope.second);
    return line_to(start, end, 0, 0);
}
Пример #4
0
std::vector<point> continue_line(std::vector<point> line, int distance)
{
 point start = line.back(), end = line.back();
 double slope = slope_of(line);
 int sX = (line.front().x < line.back().x ? 1 : -1),
     sY = (line.front().y < line.back().y ? 1 : -1);
 if (abs(slope) == 1) {
  end.x += distance * sX;
  end.y += distance * sY;
 } else if (abs(slope) < 1) {
  end.x += distance * sX;
  end.y += int(distance * abs(slope) * sY);
 } else {
  end.y += distance * sY;
  if (slope != SLOPE_VERTICAL)
   end.x += int(distance / abs(slope)) * sX;
 }
 return line_to(start.x, start.y, end.x, end.y, 0);
}