void main() { int i; struct c_comp a[4], y[4], b[4]; for (i = 0; i < 4; i++) { a[i].rmz = i + 1; a[i].imz = 0; } i = c2p(a, 4, y); /*调用系数表示转化为点表示的函数,并打印*/ if (i) { printf("c2p:\n"); for (i = 0; i < 4; i++) { printf("%f+i*%f\n", y[i].rmz, y[i].imz); } } i = p2c(y, 4, b); /*调用点表示转化为系数表示的函数,并打印*/ if (i) { printf("p2c:\n"); for (i = 0; i < 4; i++) { printf("%f+i*%f\n", b[i].rmz, b[i].imz); } } }
void draw(const glm::vec2& resolution, const glm::vec2& position = glm::vec2(0.0)) override { if(_window && (_window->getAABB().max.x - _window->getPadding() != _size)) setSize(_window->getAABB().max.x - _window->getPadding()); auto p = c2p(position); _line.draw(resolution, p); }
Boolean MRJSession::addToClassPath(const char* dirPath) { // Need to convert the path into an FSSpec, and add it MRJ's class path. Str255 path; FSSpec pathSpec; OSStatus status = ::FSMakeFSSpec(0, 0, c2p(dirPath, path), &pathSpec); if (status == noErr) return addToClassPath(pathSpec); return false; }
//----------------------------------------------------------------------------- void GdiplusDrawContext::fillLinearGradient (CGraphicsPath* _path, const CGradient& gradient, const CPoint& startPoint, const CPoint& endPoint, bool evenOdd, CGraphicsTransform* t) { #if DEBUG DebugPrint ("WARNING: GdiplusDrawContext::fillLinearGradient is not working as expected ! FIXME"); #endif GdiplusGraphicsPath* gdiPlusPath = dynamic_cast<GdiplusGraphicsPath*> (_path); if (gdiPlusPath && pGraphics) { GdiplusDrawScope drawScope (pGraphics, currentState.clipRect, getCurrentTransform ()); Gdiplus::GraphicsPath* path = gdiPlusPath->getGraphicsPath (); if (t) { Gdiplus::Matrix matrix; convert (matrix, *t); path = path->Clone (); path->Transform (&matrix); } Gdiplus::Color* colors = new Gdiplus::Color [gradient.getColorStops ().size ()]; Gdiplus::REAL* positions = new Gdiplus::REAL [gradient.getColorStops ().size ()]; uint32_t index = 0; for (CGradient::ColorStopMap::const_iterator it = gradient.getColorStops ().begin (); it != gradient.getColorStops ().end (); ++it, ++index) { CColor color = it->second; color.alpha = (int8_t)((float)color.alpha * currentState.globalAlpha); colors[index] = createGdiPlusColor (color); positions[index] = (Gdiplus::REAL)it->first; } Gdiplus::PointF c1p ((Gdiplus::REAL)(startPoint.x), (Gdiplus::REAL)(startPoint.y)); Gdiplus::PointF c2p ((Gdiplus::REAL)(endPoint.x), (Gdiplus::REAL)(endPoint.y)); Gdiplus::LinearGradientBrush brush (c1p, c2p, colors[0], colors[gradient.getColorStops ().size () - 1]); brush.SetInterpolationColors (colors, positions, static_cast<INT> (gradient.getColorStops ().size ())); path->SetFillMode (evenOdd ? Gdiplus::FillModeAlternate : Gdiplus::FillModeWinding); pGraphics->FillPath (&brush, path); if (path != gdiPlusPath->getGraphicsPath ()) delete path; delete [] colors; delete [] positions; } }
CCommandQueue::iterator CCommandAI::GetCancelQueued(const Command& c, CCommandQueue& q) { CCommandQueue::iterator ci = q.end(); while (ci != q.begin()) { --ci; //iterate from the end and dont check the current order const Command& c2 = *ci; const int& cmd_id = c.GetID(); const int& cmd2_id = c2.GetID(); if (((cmd_id == cmd2_id) || ((cmd_id < 0) && (cmd2_id < 0)) || (cmd2_id == CMD_FIGHT && cmd_id == CMD_ATTACK && c2.params.size() == 1)) && (c2.params.size() == c.params.size())) { if (c.params.size() == 1) { // assume the param is a unit-ID or feature-ID if ((c2.params[0] == c.params[0]) && (cmd2_id != CMD_SET_WANTED_MAX_SPEED)) { return ci; } } else if (c.params.size() >= 3) { if (cmd_id < 0) { BuildInfo bc(c); BuildInfo bc2(c2); if (bc.def && bc2.def && fabs(bc.pos.x - bc2.pos.x) * 2 <= std::max(bc.GetXSize(), bc2.GetXSize()) * SQUARE_SIZE && fabs(bc.pos.z - bc2.pos.z) * 2 <= std::max(bc.GetZSize(), bc2.GetZSize()) * SQUARE_SIZE) { return ci; } } else { // assume this means that the first 3 makes a position float3 cp(c.params[0], c.params[1], c.params[2]); float3 c2p(c2.params[0], c2.params[1], c2.params[2]); if ((cp - c2p).SqLength2D() < (17.0f * 17.0f)) { return ci; } } } } } return q.end(); }
long esweep_toPolar(esweep_data *a) { Complex *complex; Polar *polar; if ((a==NULL) || ((*a).data==NULL) || ((*a).size<=0)) return ERR_EMPTY_CONTAINER; switch ((*a).type) { case COMPLEX: complex=(Complex*) (*a).data; polar=(Polar*) (*a).data; c2p(polar, complex, (*a).size); /* complex2polar */ (*a).type=POLAR; break; case WAVE: case POLAR: case SURFACE: case AUDIO: default: return ERR_NOT_ON_THIS_TYPE; } return ERR_OK; }
// ----------------------------------------------------------------------- // Is called when the combobox changes between mag/deg and real/imag. void MatchDialog::slotChangeMode(int Index) { if(Index) { // polar ? S11sLabel->setText("/"); S12sLabel->setText("/"); S21sLabel->setText("/"); S22sLabel->setText("/"); S11uLabel->setText(QString::fromUtf8("°")); S12uLabel->setText(QString::fromUtf8("°")); S21uLabel->setText(QString::fromUtf8("°")); S22uLabel->setText(QString::fromUtf8("°")); double Real = S11magEdit->text().toDouble(); double Imag = S11degEdit->text().toDouble(); c2p(Real, Imag); S11magEdit->setText(QString::number(Real)); S11degEdit->setText(QString::number(Imag)); Real = S12magEdit->text().toDouble(); Imag = S12degEdit->text().toDouble(); c2p(Real, Imag); S12magEdit->setText(QString::number(Real)); S12degEdit->setText(QString::number(Imag)); Real = S21magEdit->text().toDouble(); Imag = S21degEdit->text().toDouble(); c2p(Real, Imag); S21magEdit->setText(QString::number(Real)); S21degEdit->setText(QString::number(Imag)); Real = S22magEdit->text().toDouble(); Imag = S22degEdit->text().toDouble(); c2p(Real, Imag); S22magEdit->setText(QString::number(Real)); S22degEdit->setText(QString::number(Imag)); } else { // cartesian S11sLabel->setText("+j"); S12sLabel->setText("+j"); S21sLabel->setText("+j"); S22sLabel->setText("+j"); S11uLabel->setText(" "); S12uLabel->setText(" "); S21uLabel->setText(" "); S22uLabel->setText(" "); double Mag = S11magEdit->text().toDouble(); double Phase = S11degEdit->text().toDouble(); p2c(Mag, Phase); S11magEdit->setText(QString::number(Mag)); S11degEdit->setText(QString::number(Phase)); Mag = S12magEdit->text().toDouble(); Phase = S12degEdit->text().toDouble(); p2c(Mag, Phase); S12magEdit->setText(QString::number(Mag)); S12degEdit->setText(QString::number(Phase)); Mag = S21magEdit->text().toDouble(); Phase = S21degEdit->text().toDouble(); p2c(Mag, Phase); S21magEdit->setText(QString::number(Mag)); S21degEdit->setText(QString::number(Phase)); Mag = S22magEdit->text().toDouble(); Phase = S22degEdit->text().toDouble(); p2c(Mag, Phase); S22magEdit->setText(QString::number(Mag)); S22degEdit->setText(QString::number(Phase)); } }
// if png_flag is true, outputs a PNG. if false, outputs a jpeg static void patchToRGBImage(char *outname, int png_flag) { update_status("Generating %s", outname); if (!quietflag) printf(" Outputting Debugging image '%s'...\n",outname); // input name is just the output name with ".img" char *polar_name = MALLOC((strlen(outname)+20)*sizeof(char)); sprintf(polar_name, "%s_polar.img", outname); // will multilook, as well as conver to polar, generates a 2-band // file (amplitude is band 1, phase is band 2) c2p(outname,polar_name,FALSE,TRUE); // prepare for RGB conversion int i,j; meta_parameters *meta = meta_read(polar_name); int nl = meta->general->line_count; int ns = meta->general->sample_count; float *amp = MALLOC(sizeof(float)*ns); float *phase = MALLOC(sizeof(float)*ns); unsigned char *red = MALLOC(sizeof(unsigned char)*ns); unsigned char *grn = MALLOC(sizeof(unsigned char)*ns); unsigned char *blu = MALLOC(sizeof(unsigned char)*ns); FILE *fp = fopenImage(polar_name, "rb"); const double TWOPI=2.*PI; const double PIOVER3=PI/3.; int n=0; // first/second passes are stats gathering asfPrintStatus("Gathering stats...\n"); double avg=0, stddev=0; for (i=0; i<nl; i+=3) { get_float_line(fp,meta,i,amp); for (j=0; j<ns; j+=3) { avg += amp[j]; ++n; } asfPercentMeter((float)i/((float)nl*2.)); } avg /= (double)n; for (i=0; i<nl; i+=3) { get_float_line(fp,meta,i,amp); for (j=0; j<ns; j+=3) { stddev += (amp[j]-avg)*(amp[j]-avg); } asfPercentMeter((float)(i+nl)/((float)nl*2.)); } asfPercentMeter(1); stddev = sqrt(stddev/(double)n); double min = avg - 2*stddev; double max = avg + 2*stddev; // open up PNG/JPEG output file FILE *ofp=NULL; struct jpeg_compress_struct cinfo; png_structp png_ptr; png_infop png_info_ptr; char *jpgname = NULL; char *pngname = NULL; if (png_flag) { asfPrintStatus("Generating debug image (PNG)...\n"); pngname = appendExt(outname, ".png"); initialize_png_file(pngname,meta,&ofp,&png_ptr,&png_info_ptr,TRUE); } else { asfPrintStatus("Generating debug image (JPEG)...\n"); jpgname = appendExt(outname, ".jpg"); initialize_jpeg_file(jpgname,meta,&ofp,&cinfo,TRUE); } // now read in the polar image, calculate RGB values, write to jpeg/png for (i=0; i<nl; ++i) { get_band_float_line(fp,meta,0,i,amp); get_band_float_line(fp,meta,1,i,phase); for (j=0; j<ns; ++j) { // scale to 2-sigma, to get brightness of the pixel unsigned char intensity; //=(unsigned char)(amp[j] * 128./(float)avg * 41./255.); if (amp[j]<=min) intensity=0; else if (amp[j]>=max) intensity=255; else intensity=(unsigned char)((amp[j]-min)/(max-min)*255.); // color of the pixel is determined by the phase unsigned char r=0,g=0,b=0; if (phase[j]<-PI) phase[j]+=TWOPI; // ensure [-PI, PI) if (phase[j]>=PI) phase[j]-=TWOPI; int range = (int)((phase[j]+PI)/PIOVER3); // will be 0-6 (and rarely 6) switch (range) { case 0: r=1; break; case 1: r=1; g=1; break; case 2: g=1; break; case 3: g=1; b=1; break; case 4: b=1; break; case 5: r=1; b=1; break; case 6: break; // left black default: printf("phase: %f, range: %d\n", phase[j], range); assert(FALSE); break; } red[j] = r*intensity; grn[j] = g*intensity; blu[j] = b*intensity; } // write the line if (png_flag) write_rgb_png_byte2byte(ofp,red,grn,blu,png_ptr,png_info_ptr,ns); else write_rgb_jpeg_byte2byte(ofp,red,grn,blu,&cinfo,ns); // keep the user interested! asfPercentMeter((float)i/((float)nl)); } asfPercentMeter(1.0); // clean up FCLOSE(fp); FREE(amp); FREE(phase); FREE(red); FREE(grn); FREE(blu); meta_free(meta); if (png_flag) finalize_png_file(ofp,png_ptr,png_info_ptr); else finalize_jpeg_file(ofp,&cinfo); FREE(jpgname); FREE(pngname); clean(polar_name); FREE(polar_name); }
int esweep_div(esweep_object *a, const esweep_object *b) { Wave *wave_a, *wave_b; Complex *cpx_a, *cpx_b; Polar *polar_a, *polar_b; Surface *surf; int i, N; Real tmp, denom; // necessary for *_DIV macros ESWEEP_OBJ_NOTEMPTY(a, ERR_EMPTY_OBJECT); ESWEEP_OBJ_NOTEMPTY(b, ERR_EMPTY_OBJECT); ESWEEP_SAME_MAPPING(a, b, ERR_DIFF_MAPPING); switch (a->type) { case WAVE: wave_a=(Wave*) a->data; switch (b->type) { case WAVE: wave_b=(Wave*) b->data; if (b->size == 1) { for (i=0; i < a->size; i++) { wave_a[i] /= wave_b[0]; } } else { N=a->size > b->size ? b->size : a->size; for (i=0; i < N; i++) { wave_a[i] /= wave_b[i]; } } break; case COMPLEX: ESWEEP_CONV_WAVE2COMPLEX(a, cpx_a); cpx_b=(Complex*) b->data; CC(DIV, cpx_a, cpx_b, a->size, b->size, N); break; case POLAR: ESWEEP_CONV_WAVE2POLAR(a, polar_a); polar_b=(Polar*) b->data; PP(DIV, polar_a, polar_b, a->size, b->size, N); break; default: ESWEEP_NOT_THIS_TYPE(b->type, ERR_NOT_ON_THIS_TYPE); } break; case COMPLEX: cpx_a=(Complex*) a->data; switch (b->type) { case WAVE: wave_b=(Wave*) b->data; CR(DIV, cpx_a, wave_b, a->size, b->size, N); break; case COMPLEX: cpx_b=(Complex*) b->data; CC(DIV, cpx_a, cpx_b, a->size, b->size, N); break; case POLAR: polar_a=(Polar*) cpx_a; c2p(polar_a, cpx_a, a->size); polar_b=(Polar*) b->data; PP(DIV, polar_a, polar_b, a->size, b->size, N); p2c(cpx_a, polar_a, a->size); break; default: ESWEEP_NOT_THIS_TYPE(b->type, ERR_NOT_ON_THIS_TYPE); } break; case POLAR: polar_a=(Polar*) a->data; switch (b->type) { case WAVE: wave_b=(Wave*) b->data; PR(DIV, polar_a, wave_b, a->size, b->size, N); break; case COMPLEX: cpx_b=(Complex*) b->data; polar_b=(Polar*) b->data; c2p(polar_b, cpx_b, b->size); PP(DIV, polar_a, polar_b, a->size, b->size, N); p2c(cpx_b, polar_b, b->size); break; case POLAR: polar_b=(Polar*) b->data; PP(DIV, polar_a, polar_b, a->size, b->size, N); break; default: ESWEEP_NOT_THIS_TYPE(b->type, ERR_NOT_ON_THIS_TYPE); } break; case SURFACE: switch (b->type) { case WAVE: ESWEEP_ASSERT(b->size == 1, ERR_SIZE_MISMATCH); wave_b=(Wave*) b->data; surf=(Surface*) a->data; N=surf->xsize*surf->ysize; for (i=0; i < N; i++) { (surf->z)[i]*=wave_b[0]; } break; default: ESWEEP_NOT_THIS_TYPE(b->type, ERR_NOT_ON_THIS_TYPE); } break; default: ESWEEP_NOT_THIS_TYPE(a->type, ERR_NOT_ON_THIS_TYPE); } ESWEEP_ASSERT(correctFpException(a), ERR_FP); return ERR_OK; }