示例#1
0
Handle<Value>
buildException(Arguments const& args) {
    HandleScope scope;
    if (argumentCountMismatch(args, 1)) {
        return throwArgumentCountMismatchException(args, 1);
    }
    if ( ! args[0]->IsInt32()) {
        return throwTypeError("argument 1 must be an integer (DNSServiceErrorType)");
    }

    DNSServiceErrorType error = args[0]->Int32Value();
    return scope.Close(buildException(error));
}
	/**
	 * @return All indexes points used to build the tetrahedron
	 */
	template<class T> std::set<unsigned int> ConvexHull3D<T>::buildTetrahedron(const std::vector<Point3<T>> &points)
	{
		//1. initialize
		std::set<unsigned int> pointsUsed;

		//2. build a point (use first point)
		if(points.size()<1)
		{
			throw buildException(points, pointsUsed);
		}

		this->points[nextPointIndex++] = points[0];
		pointsUsed.insert(0);

		//3. build a line (find two distinct points)
		for(unsigned int i=1; i<points.size(); i++)
		{
			if(points[i]!=this->points[0])
			{
				this->points[nextPointIndex++] = points[i];
				pointsUsed.insert(i);
				break;
			}
		}

		if(pointsUsed.size()!=2)
		{
			throw buildException(points, pointsUsed);
		}

		//4. build triangles (find a point which doesn't belong to line).
		Vector3<T> lineVector = this->points[0].vector(this->points[1]);
		for(unsigned int i=1; i<points.size(); i++)
		{
			if(pointsUsed.find(i)!=pointsUsed.end())
			{ //point already used to build the tetrahedron
				continue;
			}

			Vector3<T> linesCrossProduct = lineVector.crossProduct(this->points[0].vector(points[i]));
			if(linesCrossProduct.X != (T)0.0 || linesCrossProduct.Y != (T)0.0 || linesCrossProduct.Z != (T)0.0)
			{
				this->points[nextPointIndex++] = points[i];
				pointsUsed.insert(i);
				break;
			}
		}

		if(pointsUsed.size()!=3)
		{
			throw buildException(points, pointsUsed);
		}

		unsigned int triangleIndex1 = nextTriangleIndex++;
		unsigned int triangleIndex2 = nextTriangleIndex++;
		indexedTriangles.insert(std::pair<unsigned int, IndexedTriangle3D<T>>(triangleIndex1, IndexedTriangle3D<T>(0, 1, 2)));
		indexedTriangles.insert(std::pair<unsigned int, IndexedTriangle3D<T>>(triangleIndex2, IndexedTriangle3D<T>(0, 2, 1)));
		nbTrianglesByPoint[0] = 2;
		nbTrianglesByPoint[1] = 2;
		nbTrianglesByPoint[2] = 2;

		//5. build tetrahedron (find a no coplanar point to the triangle)
		const Vector3<T> &firstTriangleNormal = this->indexedTriangles.find(0)->second.computeNormal(this->points);
		const Point3<T> &firstPoint = this->points.find(0)->second;
		for(unsigned int i=1;i<points.size();i++)
		{
			if(pointsUsed.find(i)!=pointsUsed.end())
			{ //point already used to build the tetrahedron
				continue;
			}

			const Vector3<T> &triangleToPoint = firstPoint.vector(points[i]);
			if(firstTriangleNormal.dotProduct(triangleToPoint) != (T)0.0)
			{
				addNewPoint(points[i]);
				pointsUsed.insert(i);
				break;
			}
		}

		if(pointsUsed.size()!=4)
		{
			throw buildException(points, pointsUsed);
		}

		return pointsUsed;
	}