TEST_F(BoxTests, ClosestPointIsBottomRightCornerWhenInBottomRightRegion) { Box b(OrderedPair(-1, 1), 2, 2); OrderedPair p(3, -4); std::auto_ptr<OrderedPair> closest(b.getClosestVertex(p)); EXPECT_EQ(OrderedPair(1, -1), *closest); }
TEST_F(BoxTests, GetSeparatingAxesReturnsEdgeNormals) { Box b(Point(1, 1), 3, 3); std::auto_ptr<AxisSet> separatingAxes(b.getSeparatingAxes()); EXPECT_EQ(2, separatingAxes->size()); EXPECT_EQ(OrderedPair(1, 0), separatingAxes->getAxis(0)); EXPECT_EQ(OrderedPair(0, 1), separatingAxes->getAxis(1)); }
TEST_F(BoxTests, ClosestPointIsOnEdgeDirectlyHorizontalAndShit) { Box b(OrderedPair(-1, 1), 2, 2); OrderedPair p(10, 0); std::auto_ptr<OrderedPair> closest(b.getClosestVertex(p)); EXPECT_EQ(OrderedPair(1, 0), *closest); p = OrderedPair(10, 0.5); std::auto_ptr<OrderedPair> closest2(b.getClosestVertex(p)); EXPECT_EQ(OrderedPair(1, 0.5), *closest2); }
TEST_F(BoxTests, ClosestPointIsOnEdgeDirectlyAboveWhenBelow) { Box b(OrderedPair(-1, 1), 2, 2); OrderedPair p(0, -2); std::auto_ptr<OrderedPair> closest(b.getClosestVertex(p)); EXPECT_EQ(OrderedPair(0, -1), *closest); p = OrderedPair(-0.5, -2); std::auto_ptr<OrderedPair> closest2(b.getClosestVertex(p)); EXPECT_EQ(OrderedPair(-0.5, -1), *closest2); }
TEST_F(BoxTests, ClosestPointIsTopLeftCornerWhenInTopLeftRegion) { Box b(OrderedPair(-1, 1), 2, 2); OrderedPair p(-2, 5); std::auto_ptr<OrderedPair> closest(b.getClosestVertex(p)); EXPECT_EQ(Point(-1, 1), *closest); }
/*! * Inserts a half edge pair between HalfEdgeMesh::Vertex pointed to by v1 and v2. The first HalfEdgeMesh::HalfEdge (v1->v2) is the inner one, and the second (v2->v1) is the outer. * \param [in] v1 vertex 1, Vector3<float> * \param [in] v2 vertex 2, Vector3<float> * \param [out] indx1 the index to the half-edge from v1 to v2, unsigned int * \param [out] indx2 the index to the half-edge from v2 to v1, unsigned int * \return a bool indicating whether the half-edge pair was successfully inserted (true) or already existed (false) */ bool HalfEdgeMesh::AddHalfEdgePair(unsigned int v1, unsigned int v2, unsigned int &indx1, unsigned int &indx2) { std::map<OrderedPair, unsigned int>::iterator it = mUniqueEdgePairs.find(OrderedPair(v1, v2)); if (it != mUniqueEdgePairs.end()){ indx1 = it->second; indx2 = e(it->second).pair; if(v1 != e(indx1).vert ){ std::swap(indx1, indx2); // sort correctly } return false; } // If not found, calculate both half-edges indices indx1 = mEdges.size(); indx2 = indx1+1; // Create edges and set pair index HalfEdge edge1, edge2; edge1.pair = indx2; edge2.pair = indx1; // Connect the edges to the verts edge1.vert = v1; edge2.vert = v2; // Connect the verts to the edges v(v1).edge = indx1; v(v2).edge = indx2; // Store the edges in mEdges mEdges.push_back(edge1); mEdges.push_back(edge2); // Store the first edge in the map as an OrderedPair OrderedPair op(v1, v2); mUniqueEdgePairs[op] = indx1; // op. [ ] constructs a new entry in map, ordering not important // sorting done when retrieving return true; }