コード例 #1
0
bool ompl::ProlateHyperspheroid::isOnPhs(const double point[]) const
{
    if (dataPtr_->isTransformUpToDate_ == false)
    {
        // The transform is not up to date until the transverse diameter has been set
        throw Exception ("The transverse diameter has not been set");
    }

    return (getPathLength(point) == dataPtr_->transverseDiameter_);
}
コード例 #2
0
void ParsedExclusionProjection::parse(const boost::intrusive_ptr<ExpressionContext>& expCtx,
                                      const BSONObj& spec,
                                      ExclusionNode* node,
                                      size_t depth) {
    for (auto elem : spec) {
        const auto fieldName = elem.fieldNameStringData().toString();

        // A $ should have been detected in ParsedAggregationProjection's parsing before we get
        // here.
        invariant(fieldName[0] != '$');

        switch (elem.type()) {
            case BSONType::Bool:
            case BSONType::NumberInt:
            case BSONType::NumberLong:
            case BSONType::NumberDouble:
            case BSONType::NumberDecimal: {
                // We have already verified this is an exclusion projection.
                invariant(!elem.trueValue());

                node->excludePath(FieldPath(fieldName));
                break;
            }
            case BSONType::Object: {
                // This object represents a nested projection specification, like the sub-object in
                // {a: {b: 0, c: 0}} or {"a.b": {c: 0}}.
                ExclusionNode* child;

                if (elem.fieldNameStringData().find('.') == std::string::npos) {
                    child = node->addOrGetChild(fieldName);
                } else {
                    // A dotted field is not allowed in a sub-object, and should have been detected
                    // in ParsedAggregationProjection's parsing before we get here.
                    invariant(depth == 0);

                    // We need to keep adding children to our tree until we create a child that
                    // represents this dotted path.
                    child = node;
                    auto fullPath = FieldPath(fieldName);
                    while (fullPath.getPathLength() > 1) {
                        child = child->addOrGetChild(fullPath.getFieldName(0));
                        fullPath = fullPath.tail();
                    }
                    // It is illegal to construct an empty FieldPath, so the above loop ends one
                    // iteration too soon. Add the last path here.
                    child = child->addOrGetChild(fullPath.fullPath());
                }

                parse(expCtx, elem.Obj(), child, depth + 1);
                break;
            }
            default: { MONGO_UNREACHABLE; }
        }
    }
}
コード例 #3
0
ファイル: th_pathfind.cpp プロジェクト: Skyivories/corsix-th
void THPathfinder::persist(LuaPersistWriter *pWriter) const
{
    if(m_pDestination == NULL)
    {
        pWriter->writeVUInt(0);
        return;
    }
    pWriter->writeVUInt(getPathLength() + 1);
    pWriter->writeVUInt(m_iNodeCacheWidth);
    pWriter->writeVUInt(m_iNodeCacheHeight);
    for(const node_t* pNode = m_pDestination; pNode; pNode = pNode->prev)
    {
        pWriter->writeVUInt(pNode->x);
        pWriter->writeVUInt(pNode->y);
    }
}
コード例 #4
0
vector<CCPoint> GestureRecognizer::resamplePoints(vector<CCPoint> points, int spacedPointsNum) {
	float spacedParamI = getPathLength(points) / (spacedPointsNum-1);
	float totalDistance = 0;

	vector<CCPoint> newPoints;
	newPoints.push_back(points[0]);

	for(int i=1; i<points.size(); i++) {
		float dist = getDistance(points[i-1], points[i]);
		if(totalDistance + dist >= spacedParamI) {
			float scale = (spacedParamI - totalDistance) / dist;
			float qx = points[i-1].x + scale * (points[i].x - points[i-1].x);
			float qy = points[i-1].y + scale * (points[i].y - points[i-1].y);
			CCPoint qPnt = CCPoint(qx, qy);
			newPoints.push_back(qPnt);
			points.insert(points.begin() + i, qPnt);
			totalDistance = 0;
		}
		else {
			totalDistance += dist;
		}
	}
	return newPoints;
}
コード例 #5
0
void ParsedExclusionProjection::parse(const BSONObj& spec, ExclusionNode* node, size_t depth) {
    bool idSpecified = false;

    for (auto elem : spec) {
        const auto fieldName = elem.fieldNameStringData();

        // A $ should have been detected by ParsedAggregationProjection before we get here.
        invariant(fieldName[0] != '$');

        // Track whether the projection spec specifies a desired behavior for the _id field.
        idSpecified = idSpecified || fieldName == "_id"_sd || fieldName.startsWith("_id."_sd);

        switch (elem.type()) {
            case BSONType::Bool:
            case BSONType::NumberInt:
            case BSONType::NumberLong:
            case BSONType::NumberDouble:
            case BSONType::NumberDecimal: {
                // We have already verified this is an exclusion projection. _id is the only field
                // which is permitted to be explicitly included here.
                invariant(!elem.trueValue() || elem.fieldNameStringData() == "_id"_sd);
                if (!elem.trueValue()) {
                    node->addProjectionForPath(FieldPath(fieldName));
                }
                break;
            }
            case BSONType::Object: {
                // This object represents a nested projection specification, like the sub-object in
                // {a: {b: 0, c: 0}} or {"a.b": {c: 0}}.
                ExclusionNode* child;

                if (elem.fieldNameStringData().find('.') == std::string::npos) {
                    child = node->addOrGetChild(fieldName.toString());
                } else {
                    // A dotted field is not allowed in a sub-object, and should have been detected
                    // in ParsedAggregationProjection's parsing before we get here.
                    invariant(depth == 0);

                    // We need to keep adding children to our tree until we create a child that
                    // represents this dotted path.
                    child = node;
                    auto fullPath = FieldPath(fieldName);
                    while (fullPath.getPathLength() > 1) {
                        child = child->addOrGetChild(fullPath.getFieldName(0).toString());
                        fullPath = fullPath.tail();
                    }
                    // It is illegal to construct an empty FieldPath, so the above loop ends one
                    // iteration too soon. Add the last path here.
                    child = child->addOrGetChild(fullPath.fullPath());
                }

                parse(elem.Obj(), child, depth + 1);
                break;
            }
            default: { MONGO_UNREACHABLE; }
        }
    }

    // If _id was not specified, then doing nothing will cause it to be included. If the default _id
    // policy is kExcludeId, we add a new entry for _id to the ExclusionNode tree here.
    if (!idSpecified && _policies.idPolicy == ProjectionPolicies::DefaultIdPolicy::kExcludeId) {
        _root->addProjectionForPath({FieldPath("_id")});
    }
}
コード例 #6
0
int getPathLength(CDGNode * node) {
  if (NULL == node)
    return 0;
  return 1 + getPathLength(getNextNode(node));
}