Skip to content

Commit

Permalink
pick in reverse order so top most lines are selected first
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSapps committed Nov 10, 2016
1 parent e534e58 commit 00856a6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ SET_PROPERTY(TARGET minilua PROPERTY FOLDER "3rdparty")

SET(oddlib_src
src/gpuselect.cpp
include/reverse_for.hpp
include/types.hpp
include/proxy_nanovg.h
include/msvc_sdl_link.hpp
Expand Down
19 changes: 19 additions & 0 deletions include/reverse_for.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <type_traits>

template<typename It>
class Range
{
It b, e;
public:
Range(It b, It e) : b(b), e(e) {}
It begin() const { return b; }
It end() const { return e; }
};

template<typename ORange, typename OIt = decltype(std::begin(std::declval<ORange>())), typename It = std::reverse_iterator<OIt>>
inline Range<It> reverse_for(ORange&& originalRange)
{
return Range<It>(It(std::end(originalRange)), It(std::begin(originalRange)));
}
27 changes: 26 additions & 1 deletion src/collisionline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "proxy_nanovg.h"
#include <glm/glm.hpp>
#include <glm/gtx/vector_angle.hpp>
#include "reverse_for.hpp"

/*static*/ const std::map<CollisionLine::eLineTypes, CollisionLine::LineData> CollisionLine::mData =
{
Expand Down Expand Up @@ -52,9 +53,33 @@ void CollisionLine::SetSelected(bool selected)
return eUnknown;
}


namespace std {
template<class T>
T begin(std::pair<T, T> p)
{
return p.first;
}
template<class T>
T end(std::pair<T, T> p)
{
return p.second;
}
}

template<class Range>
std::pair<
std::reverse_iterator<decltype(begin(std::declval<Range>()))>,
std::reverse_iterator<decltype(begin(std::declval<Range>()))>
>
make_reverse_range(Range&& r)
{
return std::make_pair(make_reverse_iterator(begin(r)), make_reverse_iterator(end(r)));
}

/*static*/ CollisionLine* CollisionLine::Pick(const CollisionLines& lines, const glm::vec2& pos, float lineScale)
{
for (const std::unique_ptr<CollisionLine>& item : lines)
for (const std::unique_ptr<CollisionLine>& item : reverse_for(lines))
{
// Check collision with the arrow head triangle, if there is one
//Physics::IsPointInTriangle(item->mLine.mP1, ? , ? , pos);
Expand Down

0 comments on commit 00856a6

Please sign in to comment.