Esempio n. 1
1
void  MyRectangle::draw(CDC& dc)const
{
if (enable)
	if (isLine())
	{
		this->MyLine::draw(dc);
		return ;
	}
	else
	{
		CPen pen(m_style,m_width,m_clr); 
		CPen *penOld = dc.SelectObject( &pen ); 
		dc.SelectStockObject(NULL_BRUSH);   
		dc.Rectangle(_x1,_y1,_x2,_y2);

		dc.SelectObject(penOld);
		pen.DeleteObject();
	}
}
Esempio n. 2
0
bool MgPath::crossWithPath(const MgPath& p, const Box2d& box, Point2d& ptCross) const
{
    MgPathCrossCallback cc(box, ptCross);
    
    if (isLine() && p.isLine()) {
        return (mglnrel::cross2Line(getPoint(0), getPoint(1),
                                    p.getPoint(0), p.getPoint(1), ptCross)
                && box.contains(ptCross));
    }
    if (isLines() && p.isLines()) {
        for (int m = getCount() - (isClosed() ? 0 : 1), i = 0; i < m; i++) {
            Point2d a(getPoint(i)), b(getPoint(i + 1));
            
            for (int n = p.getCount() - (p.isClosed() ? 0 : 1), j = 0; j < n; j++) {
                Point2d c(p.getPoint(j)), d(p.getPoint(j + 1));
                
                if (mglnrel::cross2Line(a, b, c, d, cc.tmpcross)
                    && box.contains(cc.tmpcross)) {
                    float dist = cc.tmpcross.distanceTo(box.center());
                    if (cc.mindist > dist) {
                        cc.mindist = dist;
                        ptCross = cc.tmpcross;
                    }
                }
            }
        }
    }
    else if (isLine() && p.getSubPathCount() == 1) {
        cc.a = getPoint(0);
        cc.b = getPoint(1);
        p.scanSegments(cc);
    }
    else if (p.isLine() && getSubPathCount() == 1) {
        cc.a = p.getPoint(0);
        cc.b = p.getPoint(1);
        scanSegments(cc);
    }
    
    return cc.mindist < box.width();
}
Esempio n. 3
0
void
splitEdgeGroup(std::vector<CvPoint>& vPt)
{
  uint bg = 0;
  uint ed = vPt.size();

  //check if this is a line
  if (isLine(vPt, bg, ed))
    return;

  double isLine;


}
Esempio n. 4
0
ssize_t QSerial::readLine(char *buf, ssize_t count, long timeout_usec)
{
    const char *buf_ = buf;
    fd_set readfds;
    int ret;
    ssize_t size = 0;
    struct timeval timeout_s;

    timeout_usec = timeout_usec ? timeout_usec : timeoutOffs;
    timeout_s.tv_sec = timeout_usec / 1000000l;
    timeout_s.tv_usec = timeout_usec % 1000000l;

    FD_ZERO(&readfds);
    FD_SET(fd, &readfds);

    do {
        ssize_t size_;

        ret = select(fd + 1, &readfds, NULL, NULL, &timeout_s);
        if (ret == -1) {
                return -1;
        }
        size_ = ::read(fd, buf, count);
        if (size_ == -1) {
            return size;
        }
        timeout_s.tv_usec += timeoutPerChar * size_;
        timeout_s.tv_sec += timeout_s.tv_usec / 1000000l;
        timeout_s.tv_usec %= 1000000l;
        size += size_;
        count -= size_;
        buf += size_;
        if (isLine(buf_, size)) {
            return size;
        }
    } while (count > 0);

    errno = ERANGE;
    return -1;
}
Esempio n. 5
0
    bool GeoParser::isGeometryCollection(const BSONObj &obj) {
        BSONElement type = obj.getFieldDotted(GEOJSON_TYPE);
        if (type.eoo() || (String != type.type())) { return false; }
        if (GEOJSON_TYPE_GEOMETRY_COLLECTION != type.String()) { return false; }

        BSONElement coordElt = obj.getFieldDotted(GEOJSON_GEOMETRIES);
        if (coordElt.eoo() || (Array != coordElt.type())) { return false; }

        const vector<BSONElement>& coordinates = coordElt.Array();
        if (0 == coordinates.size()) { return false; }

        for (size_t i = 0; i < coordinates.size(); ++i) {
            if (coordinates[i].eoo() || (Object != coordinates[i].type())) { return false; }
            BSONObj obj = coordinates[i].Obj();
            if (!isGeoJSONPoint(obj) && !isLine(obj) && !isGeoJSONPolygon(obj)
                && !isMultiPoint(obj) && !isMultiPolygon(obj) && !isMultiLine(obj)) {
                return false;
            }
        }

        return true;
    }
// the input format is: iClassId featureid1:featurevalue1 featureid2:featurevalue2 ... 
bool LogisticRegression::ReadSampleFrmLine (string & sLine, Sample & theSample)
{
	istringstream isLine (sLine);
	if (!isLine)
		return false;

	// the class index
	isLine >> theSample.iClass;

	// the feature and its value
	string sItem;
	while (isLine >> sItem )
	{
		FeaValNode theNode;
		string::size_type iPos = sItem.find (':');
		theNode.iFeatureId = atoi (sItem.substr(0, iPos).c_str());
		theNode.dValue = atof (sItem.substr (iPos+1).c_str());
		theSample.FeaValNodeVec.push_back (theNode);
	}

	return true;
}
Esempio n. 7
0
    bool GeoParser::parseGeometryCollection(const BSONObj &obj, GeometryCollection *out) {
        BSONElement coordElt = obj.getFieldDotted(GEOJSON_GEOMETRIES);
        const vector<BSONElement>& geometries = coordElt.Array();

        for (size_t i = 0; i < geometries.size(); ++i) {
            const BSONObj& geoObj = geometries[i].Obj();

            if (isGeoJSONPoint(geoObj)) {
                PointWithCRS point;
                if (!parsePoint(geoObj, &point)) { return false; }
                out->points.push_back(point);
            } else if (isLine(geoObj)) {
                out->lines.mutableVector().push_back(new LineWithCRS());
                if (!parseLine(geoObj, out->lines.vector().back())) { return false; }
            } else if (isGeoJSONPolygon(geoObj)) {
                out->polygons.mutableVector().push_back(new PolygonWithCRS());
                if (!parsePolygon(geoObj, out->polygons.vector().back())) { return false; }
            } else if (isMultiPoint(geoObj)) {
                out->multiPoints.mutableVector().push_back(new MultiPointWithCRS());
                if (!parseMultiPoint(geoObj, out->multiPoints.mutableVector().back())) {
                    return false;
                }
            } else if (isMultiPolygon(geoObj)) {
                out->multiPolygons.mutableVector().push_back(new MultiPolygonWithCRS());
                if (!parseMultiPolygon(geoObj, out->multiPolygons.mutableVector().back())) {
                    return false;
                }
            } else {
                verify(isMultiLine(geoObj));
                out->multiLines.mutableVector().push_back(new MultiLineWithCRS());
                if (!parseMultiLine(geoObj, out->multiLines.mutableVector().back())) {
                    return false;
                }
            }
        }

        return true;
    }
Esempio n. 8
0
bool Player::isWin()
{
    return isLine(m_x,m_y)?true:false;
}
Esempio n. 9
0
bool TSShapeImport::import(const TSMesh* mesh,
	const TSMaterialList* materialList,ITRGeometry* geometry)
{
	const TSMeshAccess* pmesh = static_cast<const TSMeshAccess*>(mesh);
	const TSVertex* pVertices = pmesh->getVertices();
	const Point2F* pTextureCoords = pmesh->getTextureCoords();

	TPlaneF::DistancePrecision = distancePrecision;
	TPlaneF::NormalPrecision = normalPrecision;

	// Copy faces
	int nFaces = pmesh->getFaceCount();
	const TSMeshFace* pFaces = pmesh->getFaces();
	for (int i = 0; i < nFaces; i++) {
		const TSMeshFace& face = pFaces[i];
		ITRBitVector bv;

		// Build surface
		geometry->surfaceList.push_back(ITRGeometry::Surface());
		ITRGeometry::Surface& surface = geometry->surfaceList.last();
		surface.type = ITRGeometry::Surface::Material;
		surface.material = face.fMaterial;
		surface.textureOffset.x = 
			surface.textureOffset.y = 0;

		// Identify link surfaces
		const TSMaterial& material = (*materialList)[surface.material];
		if (material.fType == TSMaterial::MatRGB && 
			material.fRGB.fRed == .0f &&
			material.fRGB.fGreen == .0f &&
			material.fRGB.fBlue == .0f)
			surface.type = ITRGeometry::Surface::Link;
		else
			if (material.fType == TSMaterial::MatPalette && 
				material.fIndex == 0)
				surface.type = ITRGeometry::Surface::Link;

		// Build poly
		surface.polyCount = 1;
		surface.polyIndex = geometry->polyList.size();
		geometry->polyList.push_back(ITRGeometry::Poly());

		ITRGeometry::Poly& poly = geometry->polyList.last();
		poly.vertexCount = (face.fV[2] == face.fV[3])? 3: 4;
		poly.vertexIndex = geometry->vertexList.size();
		geometry->vertexList.setSize(geometry->vertexList.size() + poly.vertexCount);
		ITRGeometry::Vertex* vp = &geometry->vertexList[poly.vertexIndex];

		for (int i = 0; i < poly.vertexCount; i++) {
			Point3F sp = snap(pVertices[face.fV[i]].fPoint);
			vp[i].pointIndex = geometry->point3List.add(sp);
			vp[i].textureIndex = geometry->point2List.add
				(pTextureCoords[face.fT[i]]);
			bv.set(vp[i].pointIndex);
		}

		// Build plane
		// Make sure the three points of the poly are not on a line.
		TPlaneF plane;
		Point3F *p1 = &geometry->point3List[vp[0].pointIndex];
		Point3F *p2 = &geometry->point3List[vp[1].pointIndex];
		Point3F *p3 = &geometry->point3List[vp[2].pointIndex];
		if (poly.vertexCount > 3 && isLine(*p1,*p2,*p3)) {
			p1 = p2, p2 = p3;
			p3 = &geometry->point3List[vp[3].pointIndex];
		}
		if (isLine(*p1,*p2,*p3)) {
			printf("   Degenerate poly dropped\n");
			geometry->surfaceList.decrement();
			continue;
		}
		plane.set(*p1,*p2,*p3);

		// Add plane to list.
		ITRVector<TPlaneF>::iterator itr = 
			::find(geometry->planeList.begin(),geometry->planeList.end(),plane);
		if (itr == geometry->planeList.end()) {
			// Try too match inverted plane.
			plane.neg();
			itr = ::find(geometry->planeList.begin(),
				geometry->planeList.end(),plane);
			if (itr == geometry->planeList.end()) {
				// No inverted either, so add original plane
				// to the list.
				surface.planeIndex = geometry->planeList.size();
				surface.planeFront = true;
				plane.neg();
				geometry->planeList.push_back(plane);
			}
			else {
				surface.planeIndex = itr - geometry->planeList.begin();
				surface.planeFront = false;
			}
		}
		else {
			surface.planeIndex = itr - geometry->planeList.begin();
			surface.planeFront = true;
		}

		// Build bitvec of points used by the surface
		surface.pointIndex = geometry->bitList.size();
		surface.pointCount = bv.compress(&geometry->bitList);
	}
	//setBoundingBox(*geometry);
	return true;
}