当前位置: 首页>>代码示例>>C++>>正文


C++ point_t类代码示例

本文整理汇总了C++中point_t的典型用法代码示例。如果您正苦于以下问题:C++ point_t类的具体用法?C++ point_t怎么用?C++ point_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了point_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: queryLine

void World::queryLine(point_t v1, point_t v2, QueryCallback* qc) {
	if (use_partitioning) {
		//spatial hash version: check every rect in bucket intersecting line
		int min_x = (v1.getX()) / bucket_width;
		int max_x = (v2.getX()) / bucket_width;
		if (min_x > max_x)
			std::swap(min_x, max_x);
		int min_y = (v1.getY()) / bucket_height;
		int max_y = (v2.getY()) / bucket_height;
		if (min_y > max_y)
			std::swap(min_y, max_y);

		//todo: iterates over full box containing line; just iterate over any bucket intersecting.
		//iterate over all buckets intersecting line:
		for (int i = min_x; i <= max_x; i++)
			for (int j = min_y; j <= max_y; j++)
				if (bucket* b = getBucket(i, j))
					//iterate over all rects in bucket:
					for (auto iter : b->rect_v)
						//check if rect intersects the line:
						if (iter->queryOnLine(v1, v2))
							//halt if QueryCallback returns false.
							if (!qc->onMatch(iter,
									iter->getContactPointOnLine(v1, v2)))
								return;
	} else {
		//non spatial hash version: check every rect
		for (auto iter : v_rect) {
			if (iter->queryOnLine(v1, v2))
				if (!qc->onMatch(iter, iter->getContactPointOnLine(v1, v2)))
					return;
		}
	}
}
开发者ID:nstbayless,项目名称:sdlgame,代码行数:34,代码来源:World.cpp

示例2: _crossTwoCircles

static int _crossTwoCircles(point_t& pt1, point_t& pt2,
                            const point_t& c1, double r1,
                            const point_t& c2, double r2)
{
    double d, a, b, c, p, q, r;
    double cos_value[2], sin_value[2];
    
    if (mgEquals(c1.x, c2.x) && mgEquals(c1.y, c2.y) && mgEquals(r1, r2)) {
        return -1;
    }
    
    d = c1.distanceTo(c2);
    if (d > r1 + r2 || d < fabs(r1 - r2)) {
        return 0;
    }
    
    a = 2.0 * r1 * (c1.x - c2.x);
    b = 2.0 * r1 * (c1.y - c2.y);
    c = r2 * r2 - r1 * r1 - c1.distanceSquare(c2);
    p = a * a + b * b;
    q = -2.0 * a * c;
    if (mgEquals(d, r1 + r2) || mgEquals(d, fabs(r1 - r2))) {
        cos_value[0] = -q / p / 2.0;
        sin_value[0] = sqrt(1 - cos_value[0] * cos_value[0]);
        
        pt1.x = r1 * cos_value[0] + c1.x;
        pt1.y = r1 * sin_value[0] + c1.y;
        
        if (!mgEquals(pt1.distanceSquare(c2), r2 * r2)) {
            pt1.y = c1.y - r1 * sin_value[0];
        }
        return 1;
    }
    
    r = c * c - b * b;
    cos_value[0] = (sqrt(q * q - 4.0 * p * r) - q) / p / 2.0;
    cos_value[1] = (-sqrt(q * q - 4.0 * p * r) - q) / p / 2.0;
    sin_value[0] = sqrt(1 - cos_value[0] * cos_value[0]);
    sin_value[1] = sqrt(1 - cos_value[1] * cos_value[1]);
    
    pt1.x = r1 * cos_value[0] + c1.x;
    pt2.x = r1 * cos_value[1] + c1.x;
    pt1.y = r1 * sin_value[0] + c1.y;
    pt2.y = r1 * sin_value[1] + c1.y;
    
    if (!mgEquals(pt1.distanceSquare(c2), r2 * r2)) {
        pt1.y = c1.y - r1 * sin_value[0];
    }
    if (!mgEquals(pt2.distanceSquare(c2), r2 * r2)) {
        pt2.y = c1.y - r1 * sin_value[1];
    }
    if (mgEquals(pt1.y, pt2.y) && mgEquals(pt1.x, pt2.x)) {
        if (pt1.y > 0) {
            pt2.y = -pt2.y;
        } else {
            pt1.y = -pt1.y;
        }
    }
    return 2;
}
开发者ID:CharlyZhang,项目名称:vgcore,代码行数:60,代码来源:mgcurv.cpp

示例3: while

void fill_t::solid_fill(point_t p,float width,float height){
	//std::cout<<"width  "<<width<<" and height "<<height<<std::endl;
	std::queue <point_t> fillQueue;
	fillQueue.push(p);
	float pointx=p.getX();
	float pointy=p.getY();
	color_t c=colorArray[(int)pointx][(int)pointy];
	
    color_t pixels;
    
    while(!fillQueue.empty()){
    	// std::cout<<c.getR()<<" ANSSS"<<std::endl;
    	// exit(0);
		p=fillQueue.front();
		pointx=p.getX();
		pointy=p.getY();
		fillQueue.pop();
		
		//Added Canvas size check
		if(pointx>=width || pointy>=height || pointx<0 || pointy<0)
			continue;
		pixels = colorArray[(int)pointx][(int)pointy];
		
		if( (pixels.getR()==c.getR()) && (pixels.getG()==c.getG()) && (pixels.getB()==c.getB()) )
		{
			
			point_t p1(pointx, pointy);
			p1.draw(pen_t(color1,1));
			fillQueue.push(point_t(pointx+1,pointy));
			fillQueue.push(point_t(pointx,pointy+1));
			fillQueue.push(point_t(pointx-1,pointy));
			fillQueue.push(point_t(pointx,pointy-1));
		}
	}
}
开发者ID:Rahul-Singhal,项目名称:MyPaint,代码行数:35,代码来源:fill_t.cpp

示例4: queryOnLine

bool Rect::queryOnLine(point_t v1, point_t v2) {
	//checks each edge of rect to see if line intersects
	return (lineSegmentsIntersect({x,y},{x+w,y},v1,v2) ||
			lineSegmentsIntersect({x,y},{x,y+h},v1,v2) ||
			lineSegmentsIntersect({x,y+h},{x+w,y+h},v1,v2) ||
			lineSegmentsIntersect({x+w,y},{x+w,y+h},v1,v2) ||

			//checks if line contained within rect
			queryContains(v1.getX(),v1.getY()));
}
开发者ID:nstbayless,项目名称:sdlgame,代码行数:10,代码来源:Rect.cpp

示例5: get_integral_channels

/// the out integral channel will be resized to the required dimensions
void get_integral_channels(const integral_channels_t &in,
                           const point_t &modelWindowSize, const point_t &dataOffset, const int resizing_factor,
                           integral_channels_t &out)
{
    get_integral_channels(in,
                          dataOffset.x(), dataOffset.y(),
                          modelWindowSize.x(), modelWindowSize.y(),
                          resizing_factor,
                          out);
    return;
}
开发者ID:HaoLiuHust,项目名称:doppia,代码行数:12,代码来源:integral_channels_helpers.cpp

示例6: addPositiveSamples

void TrainingData::addPositiveSamples(const std::vector<std::string> &filenamesPositives,
                                      const point_t &modelWindowSize, const point_t &dataOffset)
{
    const size_t
            initialNumberOfTrainingSamples = getNumExamples(), // yl images number have been added to the training set
            finalNumberOfTrainingSamples = initialNumberOfTrainingSamples + filenamesPositives.size();
    if(finalNumberOfTrainingSamples > getMaxNumExamples())
    {
        throw std::runtime_error("TrainingData::addPositiveSamples is trying to add more data than initially specified");
    }


    printf("\nCollecting %zi positive samples\n", filenamesPositives.size());
    boost::progress_display progress_indicator(filenamesPositives.size());


    meta_datum_t  metaDatum;
    integral_channels_t sampleIntegralChannels;

    // integralChannelsComputer is already multithreaded, so no benefit on paralelizing this for loop
    for (size_t filenameIndex = 0; filenameIndex < filenamesPositives.size(); filenameIndex +=1)
    {
        gil::rgb8_image_t image;
        gil::rgb8c_view_t image_view = doppia::open_image(filenamesPositives[filenameIndex].c_str(), image);

        _integralChannelsComputer.set_image(image_view);
        _integralChannelsComputer.compute();

        get_integral_channels(_integralChannelsComputer.get_integral_channels(),
                              modelWindowSize, dataOffset, _integralChannelsComputer.get_shrinking_factor(),// shrinking factor = 4
                              sampleIntegralChannels);

        metaDatum.filename = filenamesPositives[filenameIndex];
        metaDatum.imageClass = 1;//classes[k];
        metaDatum.x = dataOffset.x();
        metaDatum.y = dataOffset.y();

        setDatum(initialNumberOfTrainingSamples + filenameIndex,
                 metaDatum, sampleIntegralChannels);

        ++progress_indicator;
    } // end of "for each filename"

    return;
}
开发者ID:mdqyy,项目名称:main_demo_cmake,代码行数:45,代码来源:TrainingData.cpp

示例7: onMatch

chassis_id PhysicsRegion::queryFirstPoint(point_t point,
		flag_plane p) {
	struct : public rects::QueryCallback {
		const PhysicsRegion* parent;
		chassis_id ret=NO_CHASSIS;
		bool onMatch(rects::Rect* r, point_t at) {
			ret = parent->getChassisFromRect(r);
			return false;
		}
	} qc;
	qc.parent = this;
	for (byte i = 0; i < getPlaneCount(); i++) {
		flag_plane p_it = 1 << i;
		if (p_it & p)
			planes[i].queryPoint(point.getX(), point.getY(), &qc);
		if (qc.ret!=NO_CHASSIS)
			return qc.ret;
	}
	return qc.ret;
}
开发者ID:nstbayless,项目名称:sdlgame,代码行数:20,代码来源:PhysicsRegion.cpp

示例8: within_n

    bool Polygon::within_n(const point_t &p, double d2) const
    {
        if (_in_mbr(p)) {
            for (size_t i = 0; i < outer_.size(); ++i)
                if (outer_[i].contains(p))
                    return outer_[i].within_n(p, d2);

            for (size_t i = 0; i < inner_.size(); ++i)
                if (inner_[i].contains(p))
                    return inner_[i].within_n(p, d2);

            return true;
        } else {
            if (p.y() >= mbr_[0]) return _within_n(p, d2, 0);
            if (p.x() <= mbr_[1]) return _within_n(p, d2, 1);
            if (p.y() <= mbr_[2]) return _within_n(p, d2, 2);
            if (p.x() >= mbr_[3]) return _within_n(p, d2, 3);
        }

        // not reachable
        return true;
    }
开发者ID:gongzhitaao,项目名称:sigspatial2013,代码行数:22,代码来源:polygon.cpp

示例9: initWrite

void ModelIO::initWrite(const std::string datasetName,
                        const DetectorModel::DetectorTypes type,
                        const std::string detectorName,
                        const point_t modelWindow,
                        const rectangle_t objectWindow)
{

    doppia_protobuf::Point2d *model_window = _model.mutable_model_window_size();
    model_window->set_x(modelWindow.x());
    model_window->set_y(modelWindow.y());

    doppia_protobuf::Box *b = _model.mutable_object_window();
    b->mutable_min_corner()->set_x(objectWindow.min_corner().x());
    b->mutable_min_corner()->set_y(objectWindow.min_corner().y());
    b->mutable_max_corner()->set_x(objectWindow.max_corner().x());
    b->mutable_max_corner()->set_y(objectWindow.max_corner().y());

    _model.set_training_dataset_name(datasetName.c_str());
    _model.set_detector_type(type);
    _model.set_detector_name(detectorName);

    return;
}
开发者ID:HaoLiuHust,项目名称:doppia,代码行数:23,代码来源:ModelIO.cpp

示例10: _crossLineCircle

// http://mathworld.wolfram.com/Circle-LineIntersection.html
int _crossLineCircle(point_t& pt1, point_t& pt2, const point_t& a,
                     const point_t& b, double r)
{
    point_t d(b - a);
    double d2 = d.lengthSquare();
    double dz = a.crossProduct(b);
    double z2 = dz * dz;
    double delta = r * r * d2 - z2;
    
    if (delta < 0)
        return 0;
    
    double s = sqrt(delta) / d2;
    double sx = (d.y < 0 ? -d.x : d.x) * s;
    double sy = fabs(d.y) * s;
    double tx = dz * d.y / d2;
    double ty = -dz * d.x / d2;
    
    pt1 = point_t(tx + sx, ty + sy);
    pt2 = point_t(tx - sx, ty - sy);
    
    return delta < 1e-8 ? 1 : 2;
}
开发者ID:CharlyZhang,项目名称:vgcore,代码行数:24,代码来源:mgcurv.cpp

示例11: is_in

    bool Plane::is_in(const point_t &p) const
    {
        assert(p.size() == a.size());
        double sum = 0;

        for (unsigned i=0; i<a.size(); ++i)
            sum += a[i] * p[i];

        //std::cerr << "Sum = " << sum << std::endl;

        switch(sign) {
        case lt: return (sum < b);
            break;
        case lte: return (sum <= b);
            break;
        case gt: return (sum > b);
            break;
        case gte: return (sum >= b);
            break;
        }
        assert(false);
        return false;
    }
开发者ID:YIYAYIYAYOUCHENG,项目名称:rtscan,代码行数:23,代码来源:constraint_space.cpp

示例12:

	inline bool operator==( point_t<origin_type::screen> const& lhs, point_t<origin_type::screen> const& rhs ) noexcept
	{
		return lhs.x() == rhs.x() && lhs.y() == rhs.y();
	}
开发者ID:LNSEAB,项目名称:mmaccel,代码行数:4,代码来源:point.hpp

示例13: lineSegmentsIntersect

/** Returns true if intersection between the two line segments.*/
bool lineSegmentsIntersect(point_t a1, point_t a2,point_t b1,point_t b2) {
	//if lines vertical:
	if (a1.getX()==a2.getX())
		if ((a1.getX()>b1.getX()&&a1.getX()<b2.getX())
				||(a1.getX()>b2.getX()&&a1.getX()<b1.getX())) {
			float m_b = (b1-b2).getSlope();
			float b_b = b1.getY()-b1.getX()*m_b;
			float y_intersect = b_b + m_b*a1.getX();
			return ((y_intersect>a1.getY())!=(y_intersect>a2.getY()));
		}
	if (b1.getX()==b2.getX())
		if ((b1.getX()>a1.getX()&&b1.getX()<a2.getX())
				||(b1.getX()>a2.getX()&&b1.getX()<a1.getX())) {
			float m_a = (a1-a2).getSlope();
			float b_a = a1.getY()-a1.getX()*m_a;
			float y_intersect = b_a + m_a*b1.getX();
			return ((y_intersect>b1.getY())!=(y_intersect>b2.getY()));
		}
	//solve for intersection:
	float m_a = (a1-a2).getSlope();
	float m_b = (b1-b2).getSlope();
	float b_a = a1.getY()-a1.getX()*m_a;
	float b_b = b1.getY()-b1.getX()*m_b;

	//overlapping lines do not intersect.
	if (m_a==m_b) return false;

	float x_intersect = (b_a+b_b)/(m_a-m_b);
	return ((x_intersect>a1.getX()&&x_intersect<a2.getX())||(x_intersect>a2.getX()&&x_intersect<a1.getX())) &&
			((x_intersect>b1.getX()&&x_intersect<b2.getX())||(x_intersect>b2.getX()&&x_intersect<b1.getX()));
}
开发者ID:nstbayless,项目名称:sdlgame,代码行数:32,代码来源:Rect.cpp

示例14: lineSegmentsIntersectCoord

/** Returns point of intersection between the two line segments.*/
point_t lineSegmentsIntersectCoord(point_t a1, point_t a2,point_t b1,point_t b2) {
	point_t DEFAULT_RETURN = {-1,-1};
	//solve for intersection:
	float m_a;
	float b_a;
	if (a1.getX()!=a2.getX()) {
		m_a = (a1-a2).getSlope();
		b_a = a1.getY()-a1.getX()*m_a;
	}
	float m_b;
	float b_b;
	if (b1.getX()!=b2.getX()) {
		m_b = (b1-b2).getSlope();
		b_b = b1.getY()-b1.getX()*m_b;
	}
	if (a1.getX()==a2.getX()&&b1.getX()==b2.getX())
		return DEFAULT_RETURN;
	if (a1.getX()==a2.getX())
		return {a1.getX(),b_b+m_b*a1.getX()};
	if (b1.getX()==b2.getX())
		return {b1.getX(),b_a+m_a*b1.getX()};

	//overlapping lines do not intersect.
	if (m_a==m_b) return DEFAULT_RETURN;

	float x_intersect = (b_a+b_b)/(m_a-m_b);
	return {x_intersect, b_a + x_intersect*m_a};
}
开发者ID:nstbayless,项目名称:sdlgame,代码行数:29,代码来源:Rect.cpp

示例15: get_angle

double get_angle(point_t v1, point_t v2) {
  return atan2(v1.dot(v2), v1.cross(v2));
}
开发者ID:pufe,项目名称:aulinhas-spoj-br,代码行数:3,代码来源:cercamg.cpp


注:本文中的point_t类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。