예제 #1
0
 /**
  * Like rotate(), but returns a new point instead of changing *this
  */
 Point rotated(float angle) const {
     float newX = x() * cos(angle) - y() * sin(angle);
     float newY = y() * cos(angle) + x() * sin(angle);
     return Point(newX, newY);
 }
예제 #2
0
int OSM_Model400::calculate( )
{
    // Return value, assume successful
    int retVal = 0;

    // Vectors for internal component streams
    OSM_Vector x( nSize() );       // net crusher contents
    OSM_Vector y( nSize() );       // material classified for breakage
    OSM_Vector z( nSize() );       // breakage products of y

    // Calculate classification function: C[]
    calculateC( );

    // Create contents matrix if required
    if( contents.rows()!=nComp() || contents.columns()!=nSize() )
    {
        contents.dimension( nComp(), nSize() );
    }

    //-- Main Loop - loop over components in the feed -----------------------

    for( int comp=0; comp<nComp(); comp++ )
    {
        // Aliases to component vectors
        OSM_Vector& feedC = feed()[comp];
        OSM_Vector& prodC = product()[comp];
        OSM_Vector& x     = contents[comp];

        if( feedC.sum() > 0 )                   // Component present ?
        {
            calculateA( comp );                 // Make appearance function
            double misconvergence = 1e20;       // Force misconvergence
            long iteration = 0;                 // No iterations yet

            //-- Iteration Loop - until converged or maximum iterations -----

            while( misconvergence>tolerance && iteration<maxIteration )
            {
                // classify material for breakage y = C(x)
                y.loadProduct( C, x );

                // obtain breakage products z = A(y)
                makeDaughters( y, z );

                // obtain next iteration of recycle: x = feed + z
                misconvergence = x.loadSumWithCompare( feedC, z );

                // a successful iteration (hopefully)
                iteration++;
            }
            // product component by balance
            prodC.loadSubtraction( x, y );
        }
        else
        {
            // product component is 0
            prodC = 0;
        }
    }
    // indicate success
    return retVal;
}
예제 #3
0
bool isBoxIntersectingTriangle(const Box_f & box, const Triangle_f & triangle) {
	/*    use separating axis theorem to test overlap between triangle and box */
	/*    need to test for overlap in these directions: */
	/*    1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
	/*       we do not even need to test these) */
	/*    2) normal of the triangle */
	/*    3) crossproduct(edge from tri, {x,y,z}-directin) */
	/*       this gives 3x3=9 more tests */

	Vec3 boxcenter = box.getCenter();
	Vec3 boxhalfsize(0.5f * box.getExtentX(), 0.5f * box.getExtentY(), 0.5f * box.getExtentZ());

	/* This is the fastest branch on Sun */
	/* move everything so that the boxcenter is in (0,0,0) */
	const auto v0 = triangle.getVertexA() - boxcenter;
	const auto v1 = triangle.getVertexB() - boxcenter;
	const auto v2 = triangle.getVertexC() - boxcenter;

	/* compute triangle edges */
	const auto e0 = triangle.getEdgeAB();
	const auto e1 = triangle.getEdgeBC();
	const auto e2 = triangle.getEdgeCA();

	/* Bullet 3:  */
	/*  test the 9 tests first (this was faster) */
	float p0, p1, p2, rad, pMin, pMax;

	Vec3 fe = e0.getAbs();
	p0 = e0.z() * v0.y() - e0.y() * v0.z();
	p2 = e0.z() * v2.y() - e0.y() * v2.z();
	if (p0 < p2) {
		pMin = p0;
		pMax = p2;
	} else {
		pMin = p2;
		pMax = p0;
	}
	rad = fe.z() * boxhalfsize.y() + fe.y() * boxhalfsize.z();
	if (pMin > rad || pMax < -rad)
		return 0;

	p0 = -e0.z() * v0.x() + e0.x() * v0.z();
	p2 = -e0.z() * v2.x() + e0.x() * v2.z();
	if (p0 < p2) {
		pMin = p0;
		pMax = p2;
	} else {
		pMin = p2;
		pMax = p0;
	}
	rad = fe.z() * boxhalfsize.x() + fe.x() * boxhalfsize.z();
	if (pMin > rad || pMax < -rad)
		return 0;

	p1 = e0.y() * v1.x() - e0.x() * v1.y();
	p2 = e0.y() * v2.x() - e0.x() * v2.y();
	if (p2 < p1) {
		pMin = p2;
		pMax = p1;
	} else {
		pMin = p1;
		pMax = p2;
	}
	rad = fe.y() * boxhalfsize.x() + fe.x() * boxhalfsize.y();
	if (pMin > rad || pMax < -rad)
		return 0;

	fe = e1.getAbs();
	p0 = e1.z() * v0.y() - e1.y() * v0.z();
	p2 = e1.z() * v2.y() - e1.y() * v2.z();
	if (p0 < p2) {
		pMin = p0;
		pMax = p2;
	} else {
		pMin = p2;
		pMax = p0;
	}
	rad = fe.z() * boxhalfsize.y() + fe.y() * boxhalfsize.z();
	if (pMin > rad || pMax < -rad)
		return 0;

	p0 = -e1.z() * v0.x() + e1.x() * v0.z();
	p2 = -e1.z() * v2.x() + e1.x() * v2.z();
	if (p0 < p2) {
		pMin = p0;
		pMax = p2;
	} else {
		pMin = p2;
		pMax = p0;
	}
	rad = fe.z() * boxhalfsize.x() + fe.x() * boxhalfsize.z();
	if (pMin > rad || pMax < -rad)
		return 0;

	p0 = e1.y() * v0.x() - e1.x() * v0.y();
	p1 = e1.y() * v1.x() - e1.x() * v1.y();
	if (p0 < p1) {
		pMin = p0;
		pMax = p1;
	} else {
		pMin = p1;
		pMax = p0;
	}
	rad = fe.y() * boxhalfsize.x() + fe.x() * boxhalfsize.y();
	if (pMin > rad || pMax < -rad)
		return 0;

	fe = e2.getAbs();
	p0 = e2.z() * v0.y() - e2.y() * v0.z();
	p1 = e2.z() * v1.y() - e2.y() * v1.z();
	if (p0 < p1) {
		pMin = p0;
		pMax = p1;
	} else {
		pMin = p1;
		pMax = p0;
	}
	rad = fe.z() * boxhalfsize.y() + fe.y() * boxhalfsize.z();
	if (pMin > rad || pMax < -rad)
		return 0;

	p0 = -e2.z() * v0.x() + e2.x() * v0.z();
	p1 = -e2.z() * v1.x() + e2.x() * v1.z();
	if (p0 < p1) {
		pMin = p0;
		pMax = p1;
	} else {
		pMin = p1;
		pMax = p0;
	}
	rad = fe.z() * boxhalfsize.x() + fe.x() * boxhalfsize.z();
	if (pMin > rad || pMax < -rad)
		return 0;

	p1 = e2.y() * v1.x() - e2.x() * v1.y();
	p2 = e2.y() * v2.x() - e2.x() * v2.y();
	if (p2 < p1) {
		pMin = p2;
		pMax = p1;
	} else {
		pMin = p1;
		pMax = p2;
	}
	rad = fe.y() * boxhalfsize.x() + fe.x() * boxhalfsize.y();
	if (pMin > rad || pMax < -rad)
		return 0;

	/* Bullet 1: */
	/*  first test overlap in the {x,y,z}-directions */
	/*  find min, max of the triangle each direction, and test for overlap in */
	/*  that direction -- this is equivalent to testing a minimal AABB around */
	/*  the triangle against the AABB */

	/* test in X-direction */
	if (std::min(std::min(v0.x(), v1.x()), v2.x()) > boxhalfsize[0]
		|| std::max(std::max(v0.x(), v1.x()), v2.x()) < -boxhalfsize[0])
		return 0;

	/* test in Y-direction */
	if (std::min(std::min(v0.y(), v1.y()), v2.y()) > boxhalfsize[1]
		|| std::max(std::max(v0.y(), v1.y()), v2.y()) < -boxhalfsize[1])
		return 0;

	/* test in Z-direction */
	if (std::min(std::min(v0.z(), v1.z()), v2.z()) > boxhalfsize[2]
		|| std::max(std::max(v0.z(), v1.z()), v2.z()) < -boxhalfsize[2])
		return 0;

	/* Bullet 2: */
	/*  test if the box intersects the plane of the triangle */
	/*  compute plane equation of triangle: normal*x+d=0 */
	Vec3 normal = e0.cross(e1);
	float d = -normal.dot(v0); /* plane eq: normal.x+d=0 */

	Vec3 vmin, vmax;
	for (int q = 0; q < 3; q++) {
		if (normal[q] > 0.0f) {
			vmin[q] = -boxhalfsize[q];
			vmax[q] = boxhalfsize[q];
		} else {
			vmin[q] = boxhalfsize[q];
			vmax[q] = -boxhalfsize[q];
		}
	}
	if (normal.dot(vmin) + d > 0.0f)
		return 0;
	if (normal.dot(vmax) + d >= 0.0f)
		return 1;

	return 0;
}
예제 #4
0
bool FloatRect::contains(const FloatRect& other) const
{
    return x() <= other.x() && maxX() >= other.maxX()
        && y() <= other.y() && maxY() >= other.maxY();
}
//-----------------------------------------------------------------------------
// Function: setBottomCoordinate()
//-----------------------------------------------------------------------------
void AddressSpaceVisualizationItem::setBottomCoordinate(qreal yCoordinate) {
	qreal width = rect().width();
	qreal height = yCoordinate - y();
	setRect(0, 0, width, height);
	VisualizerItem::reorganizeChildren();
}
예제 #6
0
	void system::set_geometry(const bool init) 
	{
		const double dt_max = 1.0/512;
		scheduler = Scheduler(dt_max);

		int np;
		float lx, ly, lz;
		FILE *fin = NULL;
		if (myproc == 0)
		{
			float wp;
			fin = fopen(fin_data, "r");
			int ival;
			size_t nread;

			nread = fread(&ival, sizeof(int), 1, fin);		assert(ival == 2*sizeof(int));
			nread = fread(&np, sizeof(int), 1, fin);
			nread = fread(&wp, sizeof(float), 1, fin);
			nread = fread(&ival, sizeof(int), 1, fin);		assert(ival == 2*sizeof(int));
			
			nread = fread(&ival, sizeof(int), 1, fin);		assert(ival == 3*sizeof(float));
			nread = fread(&lx, sizeof(float), 1, fin);
			nread = fread(&ly, sizeof(float), 1, fin);
			nread = fread(&lz, sizeof(float), 1, fin);
			nread = fread(&ival, sizeof(int), 1, fin);		assert(ival == 3*sizeof(float));

			fprintf(stderr, " np= %d  wp= %g \n",np, wp);
			fprintf(stderr, " lx= %g  ly= %g  lz= %g \n", lx, ly, lz);
		}

		MPI_Bcast(&lx,  1, MPI_FLOAT, 0, MPI_COMM_WORLD);
		MPI_Bcast(&ly,  1, MPI_FLOAT, 0, MPI_COMM_WORLD);
		MPI_Bcast(&lz,  1, MPI_FLOAT, 0, MPI_COMM_WORLD);

		t_end   = 0.2;

		n_restart = 2;
		dt_restart = dt_max;

		dt_dump = 0.01;

		di_log = 100;

		global_n = local_n = 0;

//		eulerian = true;

		const vec3 rmin(0.0);
		const vec3 rmax(lx, ly, lz);
		global_domain = boundary(rmin, rmax);
		global_domain_size = global_domain.hsize() * 2.0;

		const vec3 Len3 = global_domain.hsize() * 2.0;
		pfloat<0>::set_scale(Len3.x);
		pfloat<1>::set_scale(Len3.y);
		pfloat<2>::set_scale(Len3.z);

		if (myproc == 0) 
		{

			ptcl.resize(np);

			const int nx = (int)std::pow(np, 1.0/3.0);
			const dvec3 dr = dvec3(Len3.x/nx, Len3.y/nx, Len3.z/nx);
			const real rmax = dr.abs() * 1.0;

			fprintf(stderr, "dr= %g %g %g \n", dr.x, dr.y, dr.z);

			local_n  = ptcl.size();
			global_n = local_n;

			{
				std::vector<float> x(local_n), y(local_n), z(local_n);
				size_t nread;
				int ival;

				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				nread = fread(&x[0], sizeof(float), local_n, fin);
				assert((int)nread == local_n);
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				nread = fread(&y[0], sizeof(float), local_n, fin);
				assert((int)nread == local_n);
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				nread = fread(&z[0], sizeof(float), local_n, fin);
				assert((int)nread == local_n);
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));

				for (int i = 0; i < local_n; i++)
				{
					const dvec3 vel(0.0, 0.0, 0.0);
					ptcl[i] = Particle(x[i], y[i], z[i], vel.x, vel.y, vel.z, i);
					ptcl[i].rmax = rmax;
					ptcl[i].unset_derefine();
				}
			}

			U.resize(local_n);
			const int var_list[7] = {
				Fluid::VELX,
				Fluid::VELY,
				Fluid::VELZ,
				Fluid::DENS,
				Fluid::BX,
				Fluid::BY,
				Fluid::BZ};

			std::vector<float> data(local_n);
			for (int var = 0; var < 7; var++)
			{
				fprintf(stderr, " reading vat %d out of %d \n", var+1, 7);
				int ival;
				size_t nread;
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				nread = fread(&data[0], sizeof(float), local_n, fin);
				assert((int)nread == local_n);
				nread = fread(&ival, sizeof(int), 1, fin); assert(ival == local_n*(int)sizeof(float));
				for (int i = 0; i < local_n; i++)
					U[i][var_list[var]] = data[i];
			}
			for (int i = 0; i < local_n; i++)
			{
				assert(U[i][Fluid::DENS] > 0.0);
				U[i][Fluid::ETHM] = cs2 * U[i][Fluid::DENS];
			}


			fclose(fin);

			fprintf(stderr, "  *** proc= %d : local_n= %d  global_n= %d \n", myproc, local_n, global_n);
		} // myproc == 0

		MPI_Bcast(&global_n,  1, MPI_INT, 0, MPI_COMM_WORLD);

		fprintf(stderr, " proc= %d  distrubite \n", myproc);
		MPI_Barrier(MPI_COMM_WORLD);

		Distribute::int3 nt(1, 1, 1);
		switch(nproc) {
			case 1: break;
			case 2: nt.x = 2; nt.y = 1; nt.z = 1; break;
			case 4: nt.x = 2; nt.y = 2; nt.z = 1; break;
			case 6: nt.x = 3; nt.y = 2; nt.z = 1; break;
			case 8: nt.x = 2; nt.y = 2; nt.z = 2; break;
			case 16: nt.x = 4; nt.y = 2; nt.z = 2; break;
			case 32: nt.x = 4; nt.y = 4; nt.z = 2; break;
			case 64: nt.x = 4; nt.y = 4; nt.z = 4; break;
			case 128: nt.x = 8; nt.y = 4; nt.z = 4; break;
			case 256: nt.x = 8; nt.y = 8; nt.z = 4; break;
			case 512: nt.x = 8; nt.y = 8; nt.z = 8; break;
			default: assert(false);
		}

		const Distribute::int3 nt_glb(nt);
		const pBoundary pglobal_domain(pfloat3(0.0), pfloat3(Len3));
		distribute_glb.set(nproc, nt, pglobal_domain);

		for (int k = 0; k < 5; k++)
			distribute_data(true, false);

		const int nloc_reserve = (int)(2.0*global_n/nproc);
		fit_reserve_vec(ptcl,      nloc_reserve);
		fit_reserve_vec(ptcl_ppos, nloc_reserve);
		fit_reserve_vec(U,         nloc_reserve);
		fit_reserve_vec(dU,        nloc_reserve);
		fit_reserve_vec(Wgrad,     nloc_reserve);
		fit_reserve_vec(gradPsi,   nloc_reserve);
		fit_reserve_vec(cells,     nloc_reserve);

		MPI_Barrier(MPI_COMM_WORLD);

		fprintf(stderr, " *** proc= %d : local_n= %d  global_n= %d \n", myproc, local_n, global_n);
		fprintf(stderr, " proc= %d  building_mesh \n", myproc);

		MPI_Barrier(MPI_COMM_WORLD);



		const double t10 = mytimer::get_wtime();
		clear_mesh();
		int nattempt = build_mesh(true);
		double dt10 = mytimer::get_wtime() - t10;

		double volume_loc = 0.0;
		{
			std::vector<TREAL> v(local_n);
			for (int i = 0; i < local_n; i++)
				v[i] = cells[i].Volume;
			std::sort(v.begin(), v.end());  // sort volumes from low to high, to avoid roundoff errors
			for (int i = 0; i < local_n; i++)
				volume_loc += v[i];
		}


		double dt10max;
		MPI_Allreduce(&dt10, &dt10max, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
		double volume_glob = 0.0;	
		int    nattempt_max, nattempt_min;
		MPI_Allreduce(&volume_loc, &volume_glob,  1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
		MPI_Allreduce(&nattempt,   &nattempt_max, 1, MPI_INT,    MPI_MAX, MPI_COMM_WORLD);
		MPI_Allreduce(&nattempt,   &nattempt_min, 1, MPI_INT,    MPI_MIN, MPI_COMM_WORLD);

		const double volume_exact = global_domain_size.x*global_domain_size.y*global_domain_size.z;
		if (myproc == 0)
		{
			fprintf(stderr, "first call build_mesh:[ %g  sec ::  %g cells/s/proc/thread ]\n",
					dt10max,
					global_n/nproc/dt10max);
			fprintf(stderr, "   computed_volume= %g  exact_volume= %g diff= %g [ %g ]  nattempt= %d %d \n",
					volume_glob, volume_exact, 
					volume_glob - volume_exact,	(volume_glob - volume_exact)/volume_exact,
					nattempt_min, nattempt_max);
		}

		exchange_ptcl();

	}
예제 #7
0
/**
 * This function handles the logic for summing RebinnedOutput workspaces.
 * @param outputWorkspace the workspace to hold the summed input
 * @param progress the progress indicator
 * @param numSpectra
 * @param numMasked
 * @param numZeros
 */
void SumSpectra::doRebinnedOutput(MatrixWorkspace_sptr outputWorkspace,
                                  Progress &progress, size_t &numSpectra,
                                  size_t &numMasked, size_t &numZeros) {
  // Get a copy of the input workspace
  MatrixWorkspace_sptr in_ws = getProperty("InputWorkspace");

  // First, we need to clean the input workspace for nan's and inf's in order
  // to treat the data correctly later. This will create a new private
  // workspace that will be retrieved as mutable.
  auto localworkspace = replaceSpecialValues(in_ws);

  // Transform to real workspace types
  RebinnedOutput_sptr inWS =
      boost::dynamic_pointer_cast<RebinnedOutput>(localworkspace);
  RebinnedOutput_sptr outWS =
      boost::dynamic_pointer_cast<RebinnedOutput>(outputWorkspace);

  // Get references to the output workspaces's data vectors
  auto &outSpec = outputWorkspace->getSpectrum(0);
  auto &YSum = outSpec.mutableY();
  auto &YError = outSpec.mutableE();
  auto &FracSum = outWS->dataF(0);
  std::vector<double> Weight;
  std::vector<size_t> nZeros;
  if (m_calculateWeightedSum) {
    Weight.assign(YSum.size(), 0);
    nZeros.assign(YSum.size(), 0);
  }
  numSpectra = 0;
  numMasked = 0;
  numZeros = 0;

  const auto &spectrumInfo = localworkspace->spectrumInfo();
  // Loop over spectra
  for (const auto i : m_indices) {
    // Don't go outside the range.
    if ((i >= m_numberOfSpectra) || (i < 0)) {
      g_log.error() << "Invalid index " << i
                    << " was specified. Sum was aborted.\n";
      break;
    }

    if (spectrumInfo.hasDetectors(i)) {
      // Skip monitors, if the property is set to do so
      if (!m_keepMonitors && spectrumInfo.isMonitor(i))
        continue;
      // Skip masked detectors
      if (spectrumInfo.isMasked(i)) {
        numMasked++;
        continue;
      }
    }
    numSpectra++;

    // Retrieve the spectrum into a vector
    const auto &YValues = localworkspace->y(i);
    const auto &YErrors = localworkspace->e(i);
    const auto &FracArea = inWS->readF(i);

    if (m_calculateWeightedSum) {
      for (int k = 0; k < this->m_yLength; ++k) {
        if (YErrors[k] != 0) {
          double errsq = YErrors[k] * YErrors[k] * FracArea[k] * FracArea[k];
          YError[k] += errsq;
          Weight[k] += 1. / errsq;
          YSum[k] += YValues[k] * FracArea[k] / errsq;
          FracSum[k] += FracArea[k];
        } else {
          nZeros[k]++;
          FracSum[k] += FracArea[k];
        }
      }
    } else {
      for (int k = 0; k < this->m_yLength; ++k) {
        YSum[k] += YValues[k] * FracArea[k];
        YError[k] += YErrors[k] * YErrors[k] * FracArea[k] * FracArea[k];
        FracSum[k] += FracArea[k];
      }
    }

    // Map all the detectors onto the spectrum of the output
    outSpec.addDetectorIDs(localworkspace->getSpectrum(i).getDetectorIDs());

    progress.report();
  }

  if (m_calculateWeightedSum) {
    numZeros = 0;
    for (size_t i = 0; i < Weight.size(); i++) {
      if (numSpectra > nZeros[i])
        YSum[i] *= double(numSpectra - nZeros[i]) / Weight[i];
      if (nZeros[i] != 0)
        numZeros += nZeros[i];
    }
  }

  // Create the correct representation
  outWS->finalize();
}
예제 #8
0
 /**
  * to draw stuff and interface with QT
  */
 QPointF toQPointF() const { return QPointF(x(), y()); }
예제 #9
0
 operator Packet::Point() const {
     Packet::Point out;
     out.set_x(x());
     out.set_y(y());
     return out;
 }
예제 #10
0
 float cross(const Point& other) const {
     return x() * other.y() - y() * other.x();
 }
예제 #11
0
 std::string toString() const {
     std::stringstream str;
     str << "Point(" << x() << ", " << y() << ")";
     return str.str();
 }
예제 #12
0
 /** returns the perpendicular to the point, Counter Clockwise */
 Point perpCCW() const { return Point(-y(), x()); }
예제 #13
0
 /** returns the perpendicular to the point, Clockwise */
 Point perpCW() const { return Point(y(), -x()); }
예제 #14
0
 /**
 * Returns the angle of this point in radians CCW from +X.
 */
 float angle() const { return atan2(y(), x()); }
예제 #15
0
/*!
  Draw dots

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa draw(), drawCurve(), drawSticks(), drawLines(), drawSteps()
*/
void QwtPlotCurve::drawDots(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap, 
    int from, int to) const
{
    const QRect window = painter->window();
    if ( window.isEmpty() )
        return;

    const bool doFill = d_data->brush.style() != Qt::NoBrush;

    QwtPolygon polyline;
    if ( doFill )
        polyline.resize(to - from + 1);

    if ( to > from && d_data->paintAttributes & PaintFiltered )
    {
        if ( doFill )   
        {
            QPoint pp( xMap.transform(x(from)), yMap.transform(y(from)) );

            QwtPainter::drawPoint(painter, pp.x(), pp.y());
            polyline.setPoint(0, pp);

            int count = 1;
            for (int i = from + 1; i <= to; i++)
            {
                const QPoint pi(xMap.transform(x(i)), yMap.transform(y(i)));
                if ( pi != pp )
                {
                    QwtPainter::drawPoint(painter, pi.x(), pi.y());

                    polyline.setPoint(count, pi);
                    count++;

                    pp = pi;
                }
            }
            if ( int(polyline.size()) != count )
                polyline.resize(count);
        }
        else
        {
            // if we don't need to fill, we can sort out
            // duplicates independent from the order

            PrivateData::PixelMatrix pixelMatrix(window);

            for (int i = from; i <= to; i++)
            {
                const QPoint p( xMap.transform(x(i)),
                    yMap.transform(y(i)) );

                if ( pixelMatrix.testPixel(p) )
                    QwtPainter::drawPoint(painter, p.x(), p.y());
            }
        }
    }
    else
    {
        for (int i = from; i <= to; i++)
        {
            const int xi = xMap.transform(x(i));
            const int yi = yMap.transform(y(i));
            QwtPainter::drawPoint(painter, xi, yi);

            if ( doFill )
                polyline.setPoint(i - from, xi, yi);
        }
    }

    if ( doFill )
    {
        if ( d_data->paintAttributes & ClipPolygons )
            polyline = QwtClipper::clipPolygon(painter->window(), polyline);

        fillCurve(painter, xMap, yMap, polyline);
    }
}
예제 #16
0
 /**
  * does vector addition
  * adds the + operator, shorthand
  */
 Point operator+(Point other) const {
     return Point(x() + other.x(), y() + other.y());
 }
예제 #17
0
파일: edit.cpp 프로젝트: 0marcos0/Pedyrum
void Edit::resizeEvent(QResizeEvent *)
{
    button->setGeometry((x() + width() + (height() * 0.4)) - height(),
                        y() + (height() * 0.3),height() * 0.4,height() * 0.4);
}
예제 #18
0
 /**
  * see operator+
  * does vector division, note the operator
  */
 Point operator/(Point other) const {
     return Point(x() / other.x(), y() / other.y());
 }
예제 #19
0
/**
 * This function deals with the logic necessary for summing a Workspace2D.
 * @param outSpec The spectrum for the summed output.
 * @param progress The progress indicator.
 * @param numSpectra The number of spectra contributed to the sum.
 * @param numMasked The spectra dropped from the summations because they are
 * masked.
 * @param numZeros The number of zero bins in histogram workspace or empty
 * spectra for event workspace.
 */
void SumSpectra::doWorkspace2D(ISpectrum &outSpec, Progress &progress,
                               size_t &numSpectra, size_t &numMasked,
                               size_t &numZeros) {
  // Get references to the output workspaces's data vectors
  auto &OutputYSum = outSpec.mutableY();
  auto &OutputYError = outSpec.mutableE();

  std::vector<double> Weight;
  std::vector<size_t> nZeros;
  if (m_calculateWeightedSum) {
    Weight.assign(OutputYSum.size(), 0);
    nZeros.assign(OutputYSum.size(), 0);
  }
  numSpectra = 0;
  numMasked = 0;
  numZeros = 0;

  MatrixWorkspace_sptr in_ws = getProperty("InputWorkspace");
  // Clean workspace of any NANs or Inf values
  auto localworkspace = replaceSpecialValues(in_ws);
  const auto &spectrumInfo = localworkspace->spectrumInfo();
  // Loop over spectra
  for (const auto wsIndex : this->m_indices) {
    // Don't go outside the range.
    if ((wsIndex >= this->m_numberOfSpectra) || (wsIndex < 0)) {
      g_log.error() << "Invalid index " << wsIndex
                    << " was specified. Sum was aborted.\n";
      break;
    }

    if (spectrumInfo.hasDetectors(wsIndex)) {
      // Skip monitors, if the property is set to do so
      if (!m_keepMonitors && spectrumInfo.isMonitor(wsIndex))
        continue;
      // Skip masked detectors
      if (spectrumInfo.isMasked(wsIndex)) {
        numMasked++;
        continue;
      }
    }
    numSpectra++;

    const auto &YValues = localworkspace->y(wsIndex);
    const auto &YErrors = localworkspace->e(wsIndex);

    // Retrieve the spectrum into a vector

    for (int i = 0; i < m_yLength; ++i) {
      if (m_calculateWeightedSum) {
        if (std::isnormal(YErrors[i])) {
          const double errsq = YErrors[i] * YErrors[i];
          OutputYError[i] += errsq;
          Weight[i] += 1. / errsq;
          OutputYSum[i] += YValues[i] / errsq;
        } else {
          nZeros[i]++;
        }

      } else {
        OutputYSum[i] += YValues[i];
        OutputYError[i] += YErrors[i] * YErrors[i];
      }
    }

    // Map all the detectors onto the spectrum of the output
    outSpec.addDetectorIDs(
        localworkspace->getSpectrum(wsIndex).getDetectorIDs());

    progress.report();
  }

  if (m_calculateWeightedSum) {
    numZeros = 0;
    for (size_t i = 0; i < Weight.size(); i++) {
      if (numSpectra > nZeros[i])
        OutputYSum[i] *= double(numSpectra - nZeros[i]) / Weight[i];
      if (nZeros[i] != 0)
        numZeros += nZeros[i];
    }
  }
}
예제 #20
0
 /**
  * @returns (x*x,y*y)
  */
 Point operator*(Point other) const {
     return Point(x() * other.x(), y() * other.y());
 }
예제 #21
0
bool FloatRect::isExpressibleAsIntRect() const
{
    return isWithinIntRange(x()) && isWithinIntRange(y())
        && isWithinIntRange(width()) && isWithinIntRange(height())
        && isWithinIntRange(maxX()) && isWithinIntRange(maxY());
}
예제 #22
0
 /**
  * see operator+
  * does vector subtraction, note the operator
  * without parameter, it is the negative
  */
 Point operator-(Point other) const {
     return Point(x() - other.x(), y() - other.y());
 }
예제 #23
0
bool FloatRect::contains(const FloatPoint& point, ContainsMode containsMode) const
{
    if (containsMode == InsideOrOnStroke)
        return contains(point.x(), point.y());
    return x() < point.x() && maxX() > point.x() && y() < point.y() && maxY() > point.y();
}
예제 #24
0
 /**
  * multiplies the point by a -1 vector
  */
 Point operator-() const { return Point(-x(), -y()); }
void BtModuleManagerDialog::saveDialogSettings() {
    CBTConfig::set(CBTConfig::bookshelfWidth, size().width());
    CBTConfig::set(CBTConfig::bookshelfHeight, size().height());
    CBTConfig::set(CBTConfig::bookshelfPosX, x());
    CBTConfig::set(CBTConfig::bookshelfPosY, y());
}
예제 #26
0
    /**
     * see operator+
     * this modifies the value instead of returning a new value
     */
    Point& operator+=(Point other) {
        x() += other.x();
        y() += other.y();

        return *this;
    }
예제 #27
0
파일: main.cpp 프로젝트: CCJY/coliru
auto Curry=[](auto x,auto y){return[=]{auto i=x();while(i--)y();};};

#include <iostream>

int main() {
    auto foo = Curry([]{return 12;}, []{std::cout << "y\n";});
    foo();
}
예제 #28
0
/*!
  \brief Draw lines

  If the CurveAttribute Fitted is enabled a QwtCurveFitter tries
  to interpolate/smooth the curve, before it is painted.

  \param painter Painter
  \param xMap x map
  \param yMap y map
  \param from index of the first point to be painted
  \param to index of the last point to be painted

  \sa setCurveAttribute(), setCurveFitter(), draw(), 
      drawLines(), drawDots(), drawSteps(), drawSticks()
*/
void QwtPlotCurve::drawLines(QPainter *painter,
    const QwtScaleMap &xMap, const QwtScaleMap &yMap, 
    int from, int to) const
{
    int size = to - from + 1;
    if ( size <= 0 )
        return;

    QwtPolygon polyline;
    if ( ( d_data->attributes & Fitted ) && d_data->curveFitter )
    {
        // Transform x and y values to window coordinates
        // to avoid a distinction between linear and
        // logarithmic scales.

#if QT_VERSION < 0x040000
        QwtArray<QwtDoublePoint> points(size);
#else
        QPolygonF points(size);
#endif
        for (int i = from; i <= to; i++)
        {
            QwtDoublePoint &p = points[i];
            p.setX( xMap.xTransform(x(i)) );
            p.setY( yMap.xTransform(y(i)) );
        }

        points = d_data->curveFitter->fitCurve(points);
        size = points.size();

        if ( size == 0 )
            return;

        // Round QwtDoublePoints to QPoints
        // When Qwt support for Qt3 has been dropped (Qwt 6.x)
        // we will use a doubles for painting and the following
        // step will be obsolete.

        polyline.resize(size);

        const QwtDoublePoint *p = points.data();
        QPoint *pl = polyline.data();
        if ( d_data->paintAttributes & PaintFiltered )
        {

            QPoint pp(qRound(p[0].x()), qRound(p[0].y()));
            pl[0] = pp;

            int count = 1;
            for (int i = 1; i < size; i++)
            {
                const QPoint pi(qRound(p[i].x()), qRound(p[i].y()));
                if ( pi != pp )
                {
                    pl[count++] = pi;
                    pp = pi;
                }
            }
            if ( count != size )
                polyline.resize(count);
        }
        else
        {
            for ( int i = 0; i < size; i++ )
            {
                pl[i].setX( qRound(p[i].x()) );
                pl[i].setY( qRound(p[i].y()) );
            }
        }
    }
    else
    {
        polyline.resize(size);

        if ( d_data->paintAttributes & PaintFiltered )
        {
            QPoint pp( xMap.transform(x(from)), yMap.transform(y(from)) );
            polyline.setPoint(0, pp);

            int count = 1;
            for (int i = from + 1; i <= to; i++)
            {
                const QPoint pi(xMap.transform(x(i)), yMap.transform(y(i)));
                if ( pi != pp )
                {
                    polyline.setPoint(count, pi);
                    count++;

                    pp = pi;
                }
            }
            if ( count != size )
                polyline.resize(count);
        }
        else
        {
            for (int i = from; i <= to; i++)
            {
                int xi = xMap.transform(x(i));
                int yi = yMap.transform(y(i));

                polyline.setPoint(i - from, xi, yi);
            }
        }
    }

    if ( d_data->paintAttributes & ClipPolygons )
        polyline = QwtClipper::clipPolygon(painter->window(), polyline);

    QwtPainter::drawPolyline(painter, polyline);

    if ( d_data->brush.style() != Qt::NoBrush )
        fillCurve(painter, xMap, yMap, polyline);
}
예제 #29
0
파일: rect.cpp 프로젝트: sakazuki/actiona
	QString Rect::toString() const
	{
        return QString("Rect {x: %1, y: %2, width: %3, height: %4}").arg(x()).arg(y()).arg(width()).arg(height());
	}
예제 #30
0
 /**
 computes magnitude squared
 this is faster than mag()
 @return the magnitude squared
 */
 float magsq() const { return x() * x() + y() * y(); }