Exemplo n.º 1
0
bool RPolyline::reverse() {
    RPolyline nPolyline;
    QList<QSharedPointer<RShape> > segments = getExploded();

    // skip last segment if polyline is closed and add flag instead:
    int iLast = segments.count()-1;
    if (isClosed()) {
        iLast--;
    }

    for (int i=iLast; i>=0; i--) {
        QSharedPointer<RShape> seg = segments.at(i);
        QSharedPointer<RDirected> directed = seg.dynamicCast<RDirected>();
        directed->reverse();
        nPolyline.appendShape(*seg);
    }
    nPolyline.setClosed(closed);
    *this = nPolyline;
    return true;
}
Exemplo n.º 2
0
/**
 * Ends polyline and adds the last entity if the polyline is closed
 */
void RS_Polyline::endPolyline() {
        RS_DEBUG->print("RS_Polyline::endPolyline");

    if (isClosed()) {
                RS_DEBUG->print("RS_Polyline::endPolyline: adding closing entity");

        // remove old closing entity:
        if (closingEntity!=NULL) {
            removeEntity(closingEntity);
        }

        // add closing entity to the polyline:
        closingEntity = createVertex(data.startpoint, nextBulge);
        if (closingEntity!=NULL) {
            RS_EntityContainer::addEntity(closingEntity);
            //data.endpoint = data.startpoint;
        }
    }
    calculateBorders();
}
Exemplo n.º 3
0
SUMOReal
PositionVector::area() const {
    if (size() < 3) {
        return 0;
    }
    SUMOReal area = 0;
    PositionVector tmp = *this;
    if (!isClosed()) { // make sure its closed
        tmp.push_back(tmp[0]);
    }
    const int endIndex = (int)tmp.size() - 1;
    // http://en.wikipedia.org/wiki/Polygon
    for (int i = 0; i < endIndex; i++) {
        area += tmp[i].x() * tmp[i + 1].y() - tmp[i + 1].x() * tmp[i].y();
    }
    if (area < 0) { // we whether we had cw or ccw order
        area *= -1;
    }
    return area / 2;
}
Exemplo n.º 4
0
bool ZipFile::closeImpl() {
  bool ret = true;
  s_pcloseRet = 0;
  if (!isClosed()) {
    if (m_gzFile) {
      s_pcloseRet = gzclose(m_gzFile);
      ret = (s_pcloseRet == 0);
      m_gzFile = nullptr;
    }
    setIsClosed(true);
    if (m_innerFile.is<File>()) {
      m_innerFile.getTyped<File>()->close();
    }
    if (m_tempFile.is<File>()) {
      m_tempFile.getTyped<File>()->close();
      m_tempFile.reset();
    }
  }
  File::closeImpl();
  return ret;
}
Exemplo n.º 5
0
//----------------------------------------------------------------------
// connect
//----------------------------------------------------------------------
bool PipeConnection::connect()
{
    LBASSERT( getDescription()->type == CONNECTIONTYPE_PIPE );

    if( !isClosed( ))
        return false;

    _setState( STATE_CONNECTING );
    _sibling = new PipeConnection;
    _sibling->_sibling = this;

    if( !_createPipes( ))
    {
        close();
        return false;
    }

    _setState( STATE_CONNECTED );
    _sibling->_setState( STATE_CONNECTED );
    return true;
}
Exemplo n.º 6
0
//----------------------------------------------------------------------
// read
//----------------------------------------------------------------------
void NamedPipeConnection::readNB( void* buffer, const uint64_t bytes )
{
    if( isClosed( ))
        return;

    ResetEvent( _read.hEvent );
    DWORD use = LB_MIN( bytes, CO_READ_BUFFER_SIZE );


    if( ReadFile( _fd, buffer, use, &_readDone, &_read ) )
    {
        LBASSERT( _readDone > 0 );
        SetEvent( _read.hEvent );
    }
    else if( GetLastError() != ERROR_IO_PENDING )
    {
        LBWARN << "Could not start overlapped receive: " << lunchbox::sysError
               << ", closing connection" << std::endl;
        close();
    }
}
Exemplo n.º 7
0
void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionState)
{
    if (isClosed()) {
        exceptionState.throwDOMException(InvalidStateError, "Blob has been closed.");
        return;
    }

    // Dereferencing a Blob that has been closed should result in
    // a network error. Revoke URLs registered against it through
    // its UUID.
    DOMURL::revokeObjectUUID(executionContext, uuid());

    // A Blob enters a 'readability state' of closed, where it will report its
    // size as zero. Blob and FileReader operations now throws on
    // being passed a Blob in that state. Downstream uses of closed Blobs
    // (e.g., XHR.send()) consider them as empty.
    OwnPtr<BlobData> blobData = BlobData::create();
    blobData->setContentType(type());
    m_blobDataHandle = BlobDataHandle::create(std::move(blobData), 0);
    m_isClosed = true;
}
Exemplo n.º 8
0
PointCoordinateType ccPolyline::computeLength() const
{
	PointCoordinateType length = 0;

	unsigned vertCount = size();
	if (vertCount > 1 && m_theAssociatedCloud)
	{
		unsigned lastVert = isClosed() ? vertCount : vertCount-1;
		for (unsigned i=0; i<lastVert; ++i)
		{
			CCVector3 A;
			getPoint(i,A);
			CCVector3 B;
			getPoint((i+1)%vertCount,B);

			length += (B-A).norm();
		}
	}

	return length;
}
Exemplo n.º 9
0
bool PlainFile::closeImpl() {
  bool ret = true;
  s_pcloseRet = 0;
  if (!isClosed()) {
    if (m_stream) {
      s_pcloseRet = fclose(m_stream);
      m_stream = nullptr;
    } else if (getFd() >= 0) {
      s_pcloseRet = ::close(getFd());
    }
    if (m_buffer) {
      free(m_buffer);
      m_buffer = nullptr;
    }
    ret = (s_pcloseRet == 0);
    setIsClosed(true);
    setFd(-1);
  }
  File::closeImpl();
  return ret;
}
Exemplo n.º 10
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();
}
Exemplo n.º 11
0
const SocketAddress& ServerSocket::getLocalAddress(void) const
		throw (IOException&)
{
	MX_ASSERT(!isClosed());

	if (NULL == local_)
	{
		struct sockaddr_in6 sa;
		size_t saLen = sizeof(struct sockaddr_in6);
		::memset(&sa, 0, sizeof(sa));

		if (0 != mxos::getsockname(handle_, (struct sockaddr*) &sa, &saLen))
		{
			THROW3(IOException, "Can't get sock name", mxos::getLastSocketError());
		}

		local_ = new SocketAddress;
		local_->set((struct sockaddr*) &sa, saLen);
	}

	return *local_;
}
Exemplo n.º 12
0
void RSpline::print(QDebug dbg) const {
    dbg.nospace() << "RSpline(";
    RShape::print(dbg);

    dbg.nospace() << ", degree: " << getDegree();
    dbg.nospace() << ", order: " << getOrder();
    dbg.nospace() << ", closed: " << isClosed();
    dbg.nospace() << ", periodic: " << isPeriodic();
    dbg.nospace() << ", start point: " << getStartPoint();
    dbg.nospace() << ", end point: " << getEndPoint();
    dbg.nospace() << ", start tan: " << getTangentAtStart();
    dbg.nospace() << ", end tan: " << getTangentAtEnd();
    dbg.nospace() << ", t_min: " << getTMin();
    dbg.nospace() << ", t_max: " << getTMax();

    QList<RVector> controlPoints = getControlPointsWrapped();
    dbg.nospace() << ",\ncontrolPoints (" << controlPoints.count() << "): ";
    for (int i=0; i<controlPoints.count(); ++i) {
        dbg.nospace() << i << ": " << controlPoints.at(i) << ", ";
    }

    QList<RVector> fitPoints = getFitPoints();
    dbg.nospace() << ",\nfitPoints (" << fitPoints.count() << "): ";
    for (int i=0; i<fitPoints.count(); ++i) {
        dbg.nospace() << i << ": " << fitPoints.at(i) << ", ";
    }

    QList<double> knotVector = getKnotVector();
    dbg.nospace() << ",\nknots (" << knotVector.count() << "): ";
    for (int i=0; i<knotVector.count(); ++i) {
        dbg.nospace() << i << ": " << knotVector.at(i) << ", ";
    }

    knotVector = getActualKnotVector();
    dbg.nospace() << ",\ninternally used knots (" << knotVector.count() << "): ";
    for (int i=0; i<knotVector.count(); ++i) {
        dbg.nospace() << i << ": " << knotVector.at(i) << ", ";
    }
}
Exemplo n.º 13
0
//----------------------------------------
vector <ofPoint>& ofxBox2dPolygon::getVertices() {
	
    if(body == NULL) {
		return;
	}
	
	const b2Transform& xf = body->GetTransform();
	
	for (b2Fixture * f = body->GetFixtureList(); f; f = f->GetNext()) {
		b2PolygonShape * poly = (b2PolygonShape*)f->GetShape();
		
		if(poly) {
            ofPolyline::clear();
            for(int i=0; i<poly->GetVertexCount(); i++) {
				b2Vec2 pt = b2Mul(xf, poly->GetVertex(i));
                ofPolyline::addVertex(pt.x*OFX_BOX2D_SCALE, pt.y*OFX_BOX2D_SCALE);
			}
			if(isClosed()) ofPolyline::close();
		}
	}
    return ofPolyline::getVertices();
}
Exemplo n.º 14
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
void xPipeOutputStream::write(xArray<xbyte>& b, int off, int len) throw(xIOException,xIndexOutOfBoundsException)
{
	if(isClosed())
		throw xIOException(_T("Cannot write data, pipe closed"));
	if(len <= 0 || off+len > b.size() || off < 0)
		throw xIndexOutOfBoundsException();

	#ifdef XTK_OS_WINDOWS
		while ( len > 0 )
		{
			DWORD chunkWritten = 0;
			if (!::WriteFile(m_hPipeOut, b.getRawData() + off + (int)chunkWritten, len, &chunkWritten, NULL))
			{
				if(::GetLastError() == ERROR_BROKEN_PIPE)
				{
					close();
					throw xIOException(_T("Broken pipe, cannot write"));
				}
				else
					throw xIOException(_T("Error while writing on pipe"),::GetLastError());
			}

			if (!chunkWritten)
				break;
			len -= (int)chunkWritten;
		}

	#elif defined(XTK_OS_UNIX)
		while ( len > 0 )
		{
			ssize_t res = ::write(m_fdPipeOut, b.getRawData() + off, len);
			if(res < 0)
				throw xIOException(_T("Cannot write on pipe!"),errno);

			len -= res;
		}

	#endif
}
Exemplo n.º 15
0
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
//##############################################################################
//# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
//##############################################################################
int xPipeInputStream::available()
{
	if (isClosed())
		return false;
		
	#ifdef XTK_OS_WINDOWS
		DWORD nAvailable;

		//it works with anon pipes as well
		DWORD rc = ::PeekNamedPipe
			(
			m_hPipeIn,     // handle
			NULL, 0,      // ptr to buffer and its size
			NULL,         // [out] bytes read
			&nAvailable,  // [out] bytes available
			NULL          // [out] bytes left
			);

		if (!rc)
			return 0;

		return (int)nAvailable;
		
	#elif defined(XTK_OS_UNIX)
		// check if there is any input available
		struct timeval tv;
		tv.tv_sec = 0;
		tv.tv_usec = 0;

		fd_set readfds;
		FD_ZERO(&readfds);
		FD_SET(m_fdPipeIn, &readfds);
		if(::select(m_fdPipeIn + 1, &readfds, NULL, NULL, &tv) != 1)
			return 0;
		
		return 1;
		
	#endif
}
Exemplo n.º 16
0
//------------------------------------------------------------
ofxPolyline ofxPolyline::getResampledAndVerticesBySpacing(float spacing) {
    
    // Get resampled points while keeping vertices
    ofxPolyline polyline;
    polyline.setStrokeLinecap(getStrokeLinecap());
    polyline.setStrokeLinejoin(getStrokeLinejoin());
    float totalLength = getPerimeter();
    int currentIndex = 1;
    ofVec2f prevPoint = ofVec2f(FLT_MAX, FLT_MAX);
    for(float f=0; f<totalLength; f += spacing) {
        float index = getIndexAtLength(f);
        while (index > currentIndex) {
            ofVec2f newPoint = (*this)[currentIndex];
            // Don't add if this point is very close to the prev point
            if (!newPoint.match(prevPoint)) {
                polyline.lineTo(newPoint);
                prevPoint = newPoint;
            }
            currentIndex++;
        }
        ofVec2f newPoint = getPointAtLength(f);
        // Don't add if this point is very close to the prev point
        if (!newPoint.match(prevPoint)) {
            polyline.lineTo(newPoint);
            prevPoint = newPoint;
        }
    }
    
    if(!isClosed()) {
        if(polyline.size() > 0) {
            polyline[polyline.size()-1] = (*this)[size()-1];
        }
        polyline.setClosed(false);
    } else {
        polyline.setClosed(true);
    }
    return polyline;
}
Exemplo n.º 17
0
/**
 * Updates the tangents at the start and end to make the spline periodic.
 */
void RSpline::updateTangentsPeriodic() {
    if (!isValid() || !isClosed()) {
        qWarning() << "RSpline::updateTangentsPeriodic(): "
                      "spline not valid or not closed";
    }

    // TODO: tangent support:
//    RVector lStartTangent = tangentStart;
//    RVector lEndTangent = tangentEnd;

    unsetTangents();

    double tangent1 = getDirection1();
    double tangent2 = RMath::getNormalizedAngle(getDirection2() + M_PI);
    RVector v1 = RVector::createPolar(1.0, tangent1);
    RVector v2 = RVector::createPolar(1.0, tangent2);
    RVector t = (v1 + v2).getNormalized();

    // TODO: tangent support:
//    RVector t1 = t;
//    RVector t2 = t;
//    t1.valid = lStartTangent.valid;
//    t2.valid = lEndTangent.valid;

//    if (!lStartTangent.isValid()) {
//        setTangentAtStart(t1);
//    }
//    else {
//        setTangentAtStart(lStartTangent);
//    }
//    if (!lEndTangent.isValid()) {
//        setTangentAtEnd(t2);
//    }
//    else {
//        setTangentAtEnd(lEndTangent);
//    }
    setTangents(t, t);
}
Exemplo n.º 18
0
void MainWindow::on_startButton_clicked()
{
    row = ui->tableProvider->rowCount();
    column = ui->tableCustomer->columnCount();

    fillProviders();
    fillCustomers();
    fillTariff();
    if (isClosed())
    {
        createPlan();
        findUV();
        printUV();
        while (!planIsGood()) {
            findBadCell();
            findCycle();
            findMinAndBuildNewPlan();
            findUV();
            printUV();
        };
    };
    printPlan();
}
Exemplo n.º 19
0
void MediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState)
{
    if (isOpen()) {
        scheduleEvent(eventNames().sourceopenEvent);
        return;
    }

    if (oldState == openKeyword() && newState == endedKeyword()) {
        scheduleEvent(eventNames().sourceendedEvent);
        return;
    }

    ASSERT(isClosed());

    m_activeSourceBuffers->clear();

    // Clear SourceBuffer references to this object.
    for (auto& buffer : *m_sourceBuffers)
        buffer->removedFromMediaSource();
    m_sourceBuffers->clear();
    
    scheduleEvent(eventNames().sourcecloseEvent);
}
Exemplo n.º 20
0
QDebug ConsoleAppender::debug(QDebug &rDebug) const
{
  QString layout_name;
  if (layout())
    layout_name = layout()->name();
  QString target;
  if (mTarget == STDOUT_TARGET)
    target = QLatin1String("STDOUT");
  else
    target = QLatin1String("STDERR");

  rDebug.nospace() << "ConsoleAppender("
                   << "name:" << name() << " "
                   << "filter:" << firstFilter() << " "
                   << "isactive:" << isActive() << " "
                   << "isclosed:" << isClosed() << " "
                   << "layout:" << layout_name << " "
                   << "target:" << target << " "
                   << "referencecount:" << referenceCount() << " "
                   << "threshold:" << threshold().toString()
                   << ")";
  return rDebug.space();
}
Exemplo n.º 21
0
void MediaSource::onReadyStateChange(const AtomicString& oldState, const AtomicString& newState)
{
    if (isOpen()) {
        scheduleEvent(eventNames().sourceopenEvent);
        return;
    }

    if (oldState == openKeyword() && newState == endedKeyword()) {
        scheduleEvent(eventNames().sourceendedEvent);
        return;
    }

    ASSERT(isClosed());

    m_activeSourceBuffers->clear();

    // Clear SourceBuffer references to this object.
    for (unsigned long i = 0, length =  m_sourceBuffers->length(); i < length; ++i)
        m_sourceBuffers->item(i)->removedFromMediaSource();
    m_sourceBuffers->clear();
    
    scheduleEvent(eventNames().sourcecloseEvent);
}
Exemplo n.º 22
0
//----------------------------------------
void ofxBox2dEdge::create(b2World * b2dworld) {
   
    bFlagShapeUpdate = false;
    
    if(size() < 2) {
		printf("need at least 3 points\n");
		return;
	}
	
	if (body != NULL) {
		b2dworld->DestroyBody(body);
		body = NULL;
	}
	
	// create the body from the world (1)
	b2BodyDef		bd;
	bd.type			= density <= 0.0 ? b2_staticBody : b2_dynamicBody;
	body			= b2dworld->CreateBody(&bd);
    
    vector<ofPoint>&pts = ofPolyline::getVertices();
	for(int i=1; i<(int)size(); i++) {
        b2EdgeShape edge;
        edge.Set(screenPtToWorldPt(pts[i-1]), screenPtToWorldPt(pts[i]));
        body->CreateFixture(&edge, density);
    }
    mesh.clear();
    mesh.setUsage(body->GetType()==b2_staticBody?GL_STATIC_DRAW:GL_DYNAMIC_DRAW);
    mesh.setMode(OF_PRIMITIVE_LINE_STRIP);
    for(int i=0; i<(int)size(); i++) {
        mesh.addVertex(ofVec3f(pts[i].x, pts[i].y));
    }
    
    // Temporary hack to ensure it's flagged as changed, until we
    // switch to OF 0.8.0.
    setClosed(isClosed());
    alive = true;
}
Exemplo n.º 23
0
void WebKitMediaSource::removeSourceBuffer(WebKitSourceBuffer* buffer, ExceptionCode& ec)
{
    // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-removesourcebuffer
    // 1. If sourceBuffer is null then throw an INVALID_ACCESS_ERR exception and
    // abort these steps.
    if (!buffer) {
        ec = INVALID_ACCESS_ERR;
        return;
    }

    // 2. If sourceBuffers is empty then throw an INVALID_STATE_ERR exception and
    // abort these steps.
    if (isClosed() || !m_sourceBuffers->length()) {
        ec = INVALID_STATE_ERR;
        return;
    }

    // 3. If sourceBuffer specifies an object that is not in sourceBuffers then
    // throw a NOT_FOUND_ERR exception and abort these steps.
    // 6. Remove sourceBuffer from sourceBuffers and fire a removesourcebuffer event
    // on that object.
    if (!m_sourceBuffers->remove(buffer)) {
        ec = NOT_FOUND_ERR;
        return;
    }

    // 7. Destroy all resources for sourceBuffer.
    m_activeSourceBuffers->remove(buffer);

    // 4. Remove track information from audioTracks, videoTracks, and textTracks for all tracks
    // associated with sourceBuffer and fire a simple event named change on the modified lists.
    // FIXME(91649): support track selection

    // 5. If sourceBuffer is in activeSourceBuffers, then remove it from that list and fire a
    // removesourcebuffer event on that object.
    // FIXME(91649): support track selection
}
Exemplo n.º 24
0
Position
PositionVector::getCentroid() const {
    PositionVector tmp = *this;
    if (!isClosed()) { // make sure its closed
        tmp.push_back(tmp[0]);
    }
    const int endIndex = (int)tmp.size() - 1;
    SUMOReal div = 0; // 6 * area including sign
    SUMOReal x = 0;
    SUMOReal y = 0;
    if (tmp.area() != 0) { // numerical instability ?
        // http://en.wikipedia.org/wiki/Polygon
        for (int i = 0; i < endIndex; i++) {
            const SUMOReal z = tmp[i].x() * tmp[i + 1].y() - tmp[i + 1].x() * tmp[i].y();
            div += z; // area formula
            x += (tmp[i].x() + tmp[i + 1].x()) * z;
            y += (tmp[i].y() + tmp[i + 1].y()) * z;
        }
        div *= 3; //  6 / 2, the 2 comes from the area formula
        return Position(x / div, y / div);
    } else {
        // compute by decomposing into line segments
        // http://en.wikipedia.org/wiki/Centroid#By_geometric_decomposition
        SUMOReal lengthSum = 0;
        for (int i = 0; i < endIndex; i++) {
            SUMOReal length = tmp[i].distanceTo(tmp[i + 1]);
            x += (tmp[i].x() + tmp[i + 1].x()) * length / 2;
            y += (tmp[i].y() + tmp[i + 1].y()) * length / 2;
            lengthSum += length;
        }
        if (lengthSum == 0) {
            // it is probably only one point
            return tmp[0];
        }
        return Position(x / lengthSum, y / lengthSum);
    }
}
//----------------------------------------
void ofxBox2dPolygon::triangulatePoly(float resampleAmt, int nPointsInside) {
	
	triangles.clear();
	bool wasClosed = isClosed();
	if(size() > 0) {
		
		// copy over the points into a polyline
		ofPolyline polyOutline;
		ofPolyline newPoly;
		
		// make sure to close the polyline and then
		// simplify and resample by spacing...
		setClosed(true);
		if(!bIsSimplified) simplify();
		newPoly = getResampledBySpacing(resampleAmt);
		
		// save the outline...
		polyOutline = newPoly;
		
		// add some random points inside then
		// triangulate the polyline...
		if(nPointsInside!=-1) addRandomPointsInside(newPoly, nPointsInside);
		triangles = triangulatePolygonWithOutline(newPoly, polyOutline);
			
//		clear();
        ofPolyline::clear();
        mesh.clear();
		if(wasClosed) ofPolyline::setClosed(wasClosed);
        
		// now add back into polyshape
		for (size_t i=0; i<newPoly.size(); i++) {
			addVertex(newPoly[i]);
		}
	}
	
	bIsTriangulated = true;
}
Exemplo n.º 26
0
  // @mfunc Close this <c OMFile>, any unsaved changes are discarded.
  //   @precondition <f isOpen()>
  //   @postcondition <f !isOpen()>
  //   @postcondition <f isClosed()>
void OMFile::close(void)
{
  TRACE("OMFile::close");
  PRECONDITION("Open", isOpen());
  PRECONDITION("Valid root", _root != 0);

  _root->close();
  _rootStore->close();

  if (isValid()) {
    OMStoredObjectFactory* factory = findFactory(_encoding);
    ASSERT("Recognized file encoding", factory != 0);
    factory->close(this);
  }

  _rootStore = 0; //  We don't own _rootStore
  _root->detach();
  delete _root;
  _root = 0;
  _isOpen = false;
  _isClosed = true;
  POSTCONDITION("Closed", isClosed());
  POSTCONDITION("Closed", !isOpen());
}
Exemplo n.º 27
0
double QgsLineStringV2::vertexAngle( const QgsVertexId& vertex ) const
{
  if ( vertex.vertex == 0 || vertex.vertex >= ( numPoints() - 1 ) )
  {
    if ( isClosed() )
    {
      double previousX = mX.at( numPoints() - 1 );
      double previousY = mY.at( numPoints() - 1 );
      double currentX = mX.at( 0 );
      double currentY = mY.at( 0 );
      double afterX = mX.at( 1 );
      double afterY = mY.at( 1 );
      return QgsGeometryUtils::averageAngle( previousX, previousY, currentX, currentY, afterX, afterY );
    }
    else if ( vertex.vertex == 0 )
    {
      return QgsGeometryUtils::linePerpendicularAngle( mX.at( 0 ), mY.at( 0 ), mX.at( 1 ), mY.at( 1 ) );
    }
    else
    {
      int a = numPoints() - 2;
      int b = numPoints() - 1;
      return QgsGeometryUtils::linePerpendicularAngle( mX.at( a ), mY.at( a ), mX.at( b ), mY.at( b ) );
    }
  }
  else
  {
    double previousX = mX.at( vertex.vertex - 1 );
    double previousY = mY.at( vertex.vertex - 1 );
    double currentX = mX.at( vertex.vertex );
    double currentY = mY.at( vertex.vertex );
    double afterX = mX.at( vertex.vertex + 1 );
    double afterY = mY.at( vertex.vertex + 1 );
    return QgsGeometryUtils::averageAngle( previousX, previousY, currentX, currentY, afterX, afterY );
  }
}
Exemplo n.º 28
0
protocol::TMHello
buildHello (uint256 const& sharedValue, Application& app)
{
    protocol::TMHello h;

    Blob vchSig;
    app.getLocalCredentials ().getNodePrivate ().signNodePrivate (
        sharedValue, vchSig);

    h.set_protoversion (to_packed (BuildInfo::getCurrentProtocol()));
    h.set_protoversionmin (to_packed (BuildInfo::getMinimumProtocol()));
    h.set_fullversion (BuildInfo::getFullVersionString ());
    h.set_nettime (app.getOPs ().getNetworkTimeNC ());
    h.set_nodepublic (app.getLocalCredentials ().getNodePublic (
                      ).humanNodePublic ());
    h.set_nodeproof (&vchSig[0], vchSig.size ());
    // h.set_ipv4port (portNumber); // ignored now
    h.set_testnet (false);

    // We always advertise ourselves as private in the HELLO message. This
    // suppresses the old peer advertising code and allows PeerFinder to
    // take over the functionality.
    h.set_nodeprivate (true);

    auto const closedLedger = app.getLedgerMaster().getClosedLedger();

    if (closedLedger && closedLedger->isClosed ())
    {
        uint256 hash = closedLedger->getHash ();
        h.set_ledgerclosed (hash.begin (), hash.size ());
        hash = closedLedger->getParentHash ();
        h.set_ledgerprevious (hash.begin (), hash.size ());
    }

    return h;
}
Exemplo n.º 29
0
MediaSource::~MediaSource()
{
    LOG(MediaSource, "MediaSource::~MediaSource %p", this);
    ASSERT(isClosed());
}
Exemplo n.º 30
0
bool MediaSource::canSuspendForDocumentSuspension() const
{
    return isClosed() && !m_asyncEventQueue.hasPendingEvents();
}