Exemplo n.º 1
0
	void ShapeMaker::doSetup(double _x, double _y, bool hasMoveTo, int _fillStyle0, int _fillStyle1, int _lineStyle) {
		// append shapesetup (whithout styles, this is glyph only for now)
		ShapeSetup *setup = new ShapeSetup;


		if (_fillStyle0 != -1) {
			setup->setfillStyle0(_fillStyle0);
			setup->sethasFillStyle0(1);
		}
		if (_fillStyle1 != -1) {
			setup->setfillStyle1(_fillStyle1);
			setup->sethasFillStyle1(1);
		}
		if (_lineStyle != -1) {
			setup->setlineStyle(_lineStyle);
			setup->sethasLineStyle(1);
		}

		if (hasMoveTo) {
			roundReset();
			int x = roundX(factorx * (_x));
			int y = roundY(factory * (_y));

			diffx = diffy = 0;

			setup->setxybits(SWFMaxBitsNeeded(true, 2, x, y));

			setup->sethasMoveTo(1);
			setup->setx(x);
			setup->sety(y);

			minmax(x, y);

			lastx = _x; lasty = _y;
			lastsetupx = _x; lastsetupy = _y;
		}

		edges->append(setup);
	}
Exemplo n.º 2
0
void midGrayThreshold( const cv::Mat& src, cv::Mat& dst, int windowSize ,int c)
{
  cv::Mat min, max;
#ifdef USE_OPENCV
  cv::Mat kernel(cv::Size(windowSize, windowSize),CV_8UC1,cv::Scalar(1));
  cv::erode(src, min, kernel);
  cv::dilate(src, max, kernel);
#else
  minmax(src,min,max,windowSize);
#endif
  
  dst = cv::Mat( src.size(), src.type() );
  
  for( int j = 0; j < dst.rows; ++j ) {
    for( int i = 0; i < dst.cols; ++i ) 
    {
      //pixel = ( pixel > ( ( max + min ) / 2 ) - c ) ? object : background
      dst.at<uchar>(j,i) = ( src.at<uchar>(j,i) > ( ( max.at<uchar>(j,i) + min.at<uchar>(j,i) ) / 2 ) - c ) ? 255 : 0;
    }
  }
  return;
}
Exemplo n.º 3
0
void Analysis::outputHistogramOfPosWithLimits(double pop, int axis, double minLimit, double maxLimit)
{
	vector<double> position(3,0);
	vector<vector<double> > *block = new vector<vector<double> > (this->number_cells, position);
	vector<vector<double> > *positions;

	for (int i=0; i<this->number_sweeps; i++) {
		if (!this->binary_position_input)
			this->getBlock(block);
		else
			this->getBlockBinary(block);
		positions = new vector<vector<double> > (this->cell_classes[pop].size(),position);
		for (int j=0; j<this->cell_classes[pop].size(); j++) {
			positions->at(j)[0] = block->at(cell_classes[pop][j])[0];
			positions->at(j)[1] = block->at(cell_classes[pop][j])[1];
			positions->at(j)[2] = block->at(cell_classes[pop][j])[2];
		}
		vector<double> minmax(2);
		minmax[0] = minLimit;
		minmax[1] = maxLimit;

		int num_bins = (int)((minmax[1]-minmax[0])/this->bin_width)+1;

		vector<double> histogramvec;
		histogramvec.resize(num_bins+1);

		this->generateHistogramXPos(positions, histogramvec, minmax[0]);
		generateHistogramPos(positions, histogramvec, minmax[0],axis);

		cout << "# time: " << (i+1)*this->output_interval << endl;
		for (int i=0; i<histogramvec.size(); i++)
			cout << minmax[0]+i*bin_width+0.5*bin_width << " " << histogramvec[i] << endl;
		cout << endl << endl;
		delete positions;
	}


}
Exemplo n.º 4
0
void CowichanTBB::norm(PointVector pointsIn, PointVector pointsOut) {

  MinMaxReducer minmax(pointsIn);

  // find min/max coordinates
  parallel_reduce(Range(0, n), minmax, auto_partitioner());

  Point minPoint = minmax.getMinimum();
  Point maxPoint = minmax.getMaximum();

  // compute scaling factors
  real xfactor = (real)((maxPoint.x == minPoint.x) ?
      0.0 : 1.0 / (maxPoint.x - minPoint.x));
  real yfactor = (real)((maxPoint.y == minPoint.y) ?
      0.0 : 1.0 / (maxPoint.y - minPoint.y));

  Normalizer normalizer(pointsIn, pointsOut, minPoint.x, minPoint.y, xfactor,
      yfactor);

  // normalize the vector
  parallel_for(Range(0, n), normalizer, auto_partitioner());

}
Exemplo n.º 5
0
void edit_day()
{

	short item_hit;
	Str255 sign_text;
	location view_loc;


	make_cursor_sword();
	
	cd_create_dialog(917,mainPtr);
		
	sprintf((char *) sign_text,"%d",(short) ( ((univ.party.age) / 3700) + 1));
	cd_set_text_edit_str(917,2,(char *) sign_text);
	
	item_hit = cd_run_dialog();
	
	cd_kill_dialog(917);
	
	dialog_answer = minmax(0,500,dialog_answer);
	
	univ.party.age = (long long) (3700) * (long long) (dialog_answer);
}
Exemplo n.º 6
0
void edit_gold_or_food(short which_to_edit)
//0 - gold 1 - food
{

	short item_hit;
	Str255 sign_text;
	location view_loc;

	store_which_to_edit = which_to_edit;

	make_cursor_sword();
	cd_create_dialog((which_to_edit == 0) ? 1012 : 947, mainPtr);
	sprintf((char *) sign_text,"%d",(short) ((which_to_edit == 0) ? univ.party.gold : univ.party.food));
	cd_set_text_edit_str((which_to_edit == 0) ? 1012 : 947,2,(char *) sign_text);
	
	item_hit = cd_run_dialog();
	cd_kill_dialog((which_to_edit == 0) ? 1012 : 947);
	dialog_answer = minmax(0,25000,dialog_answer);
	if (which_to_edit == 0)
		univ.party.gold = dialog_answer;
	else
		univ.party.food = dialog_answer;
}
Exemplo n.º 7
0
String BZ2Compress(String s, Gate2<int, int> progress)
{
	if(s.IsEmpty())
		return s;
	bz_stream z;
	Zero(z);
	z.bzalloc = bzalloc_new;
	z.bzfree = bzfree_new;
	z.opaque = 0;
	if(BZ2_bzCompressInit(&z, 9, 0, 30) != BZ_OK)
		return String::GetVoid();
	int buf_size = minmax(s.GetLength(), 1024, 65536);
	Buffer<char> output(buf_size);
	z.next_in = (char *)s.Begin();
	z.avail_in = s.GetLength();
	z.next_out = output;
	z.avail_out = buf_size;

	String out;
	int res;
	while((res = BZ2_bzCompress(&z, z.avail_in ? BZ_RUN : BZ_FINISH)) == BZ_RUN_OK || res == BZ_FINISH_OK)
	{
		out.Cat(output, buf_size - z.avail_out);
		z.next_out = output;
		z.avail_out = buf_size;
		if(progress((int)(uintptr_t)((const char *)z.next_in - ~s), s.GetLength()))
		{
			BZ2_bzCompressEnd(&z);
			return String::GetVoid();
		}
	}
	out.Cat(output, buf_size - z.avail_out);
	BZ2_bzCompressEnd(&z);
	if(res != BZ_STREAM_END)
		out = String::GetVoid();
	return out;
}
Exemplo n.º 8
0
int godep(float *x, int n, float w, float **bins, float **freq) {
	float x1, x2;
	float xt;
	int i,j;

	/* Find x1, x2  as w multiple */
	minmax(x, n, &x1, &x2);

	for (xt = 0.0;xt <= x1; xt += w);
	x1 = xt - w;
	for (xt = 0.0 ;xt <= x2; xt += w);
	x2 = xt;

	/* Create bins */
	int nb = ((x2 - x1) / w);

	*bins = malloc(sizeof(float) * nb);
	*freq = malloc(sizeof(float) * nb);

	for(i=0; i<nb;  i++) (*bins)[i] = x1 + i*w;

	for(i=0; i < nb; i++) {
		float w1 = (*bins)[i];
		float w2 = (*bins)[i] + w;
		(*freq)[i] = 0;
		for(j=0;j<n;j++)
			if (x[j] >= w1 && x[j] <= w2) (*freq)[i] += 1;
	}

	for(i=0; i < nb; i++) {
		if ((*freq)[i] > 0)
			(*freq)[i] = log10((*freq)[i]);
	}

	return nb;
}
Exemplo n.º 9
0
NAMESPACE_UPP

#define LTIMING(x) // RTIMING(x)
#define LLOG(x)

void SetSurface(SystemDraw& w, const Rect& dest, const RGBA *pixels, Size srcsz, Point poff)
{
	Size dsz = dest.GetSize();
	cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, dsz.cx, dsz.cy);
	cairo_surface_flush(surface);
	byte *a = (byte *)cairo_image_surface_get_data(surface);
	int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dsz.cx);
	for(int i = 0; i < dsz.cy; i++) {
		int sl = poff.y + i;
		if(i >= 0 && i < srcsz.cy)
			Copy((RGBA *)a, pixels + srcsz.cx * sl + poff.x,
			     minmax(srcsz.cx - poff.x, 0, min(dsz.cx, srcsz.cx)));
		a += stride;
	}
	cairo_surface_mark_dirty(surface);
	cairo_set_source_surface(w, surface, dest.left, dest.top);
	cairo_paint(w);
	cairo_surface_destroy(surface);
}
Exemplo n.º 10
0
int   LineEdit::GetGPos(int ln, int cl) const {
	ln = minmax(ln, 0, line.GetCount() - 1);
	const String& stxt = line[ln].text;
	const char *s = stxt;
	const char *e = stxt.End();
	const char *b = s;
	int gl = 0;
	int wpos = 0;
	while(s < e) {
		if(*s == '\t')
			gl = (gl + tabsize) / tabsize * tabsize;
		else
		if((byte)*s < 128)
			gl++;
		else {
			WString txt = FromUtf8(s, int(e - s));
			const wchar *b = txt;
			const wchar *e = txt.End();
			const wchar *s = b;
			while(s < e) {
				if(*s == '\t')
					gl = (gl + tabsize) / tabsize * tabsize;
				else
					gl += 1 + IsCJKIdeograph(*s);
				if(cl < gl) break;
				s++;
			}
			wpos = int(s - b);
			break;
		}
		if(cl < gl) break;
		s++;
	}
	
	return GetPos(ln, int(s - b) + wpos);
}
	Color(float x):
	r{minmax(x)},
	g{minmax(x)},
	b{minmax(x)}
	{}
Exemplo n.º 12
0
static void changetypeCB(StorageStructure *ss, int n, Quark **values, void *data)
{
    int i, j;
    double *datap;
    int imin, imax;
    double dmin, dmax, dmean, dsd;
    StorageStructure *sp;
    char buf[32];
    char **cells[MAX_SET_COLS];
    Quark *pset;
    
    sp = (StorageStructure *) data;
    if (sp == NULL) {
        return;
    }
    
    if (n == 1) {
        pset = values[0];
    } else {
        pset = NULL;
    }
    for (i = 0; i < MAX_SET_COLS; i++) {
        datap = set_get_col(pset, i);
        if (datap) {
            minmax(datap, set_get_length(pset), &dmin, &dmax, &imin, &imax);
            stasum(datap, set_get_length(pset), &dmean, &dsd);
            for (j = 0; j < DATA_STAT_COLS; j++) {
                switch (j) {
                case 0:
                    sprintf(buf, "%g", dmin);
                    break;
                case 1:
                    sprintf(buf, "%d", imin);
                    break;
                case 2:
                    sprintf(buf, "%g", dmax);
                    break;
                case 3:
                    sprintf(buf, "%d", imax);
                    break;
                case 4:
                    sprintf(buf, "%g", dmean);
                    break;
                case 5:
                    sprintf(buf, "%g", dsd);
                    break;
                default:
                    strcpy(buf, "");
                    break;
                }
                tui.rows[i][j] = copy_string(tui.rows[i][j], buf);
            }
        } else {
            for (j = 0; j < DATA_STAT_COLS; j++) {
                tui.rows[i][j] = copy_string(tui.rows[i][j], "");
            }
        }
        cells[i] = &tui.rows[i][0];
    }
    TableSetCells(tui.mw, cells);
}
 Volatility AnalyticContinuousFloatingLookbackEngine::volatility() const {
     return process_->blackVolatility()->blackVol(residualTime(), minmax());
 }
Exemplo n.º 14
0
/*
 * arr_bincount is registered as bincount.
 *
 * bincount accepts one, two or three arguments. The first is an array of
 * non-negative integers The second, if present, is an array of weights,
 * which must be promotable to double. Call these arguments list and
 * weight. Both must be one-dimensional with len(weight) == len(list). If
 * weight is not present then bincount(list)[i] is the number of occurrences
 * of i in list.  If weight is present then bincount(self,list, weight)[i]
 * is the sum of all weight[j] where list [j] == i.  Self is not used.
 * The third argument, if present, is a minimum length desired for the
 * output array.
 */
NPY_NO_EXPORT PyObject *
arr_bincount(PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
{
    PyArray_Descr *type;
    PyObject *list = NULL, *weight=Py_None, *mlength=Py_None;
    PyArrayObject *lst=NULL, *ans=NULL, *wts=NULL;
    npy_intp *numbers, *ians, len , mx, mn, ans_size, minlength;
    npy_intp i;
    double *weights , *dans;
    static char *kwlist[] = {"list", "weights", "minlength", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO",
                kwlist, &list, &weight, &mlength)) {
            goto fail;
    }

    lst = (PyArrayObject *)PyArray_ContiguousFromAny(list, NPY_INTP, 1, 1);
    if (lst == NULL) {
        goto fail;
    }
    len = PyArray_SIZE(lst);
    type = PyArray_DescrFromType(NPY_INTP);

    if (mlength == Py_None) {
        minlength = 0;
    }
    else {
        minlength = PyArray_PyIntAsIntp(mlength);
        if (minlength <= 0) {
            if (!PyErr_Occurred()) {
                PyErr_SetString(PyExc_ValueError,
                                "minlength must be positive");
            }
            goto fail;
        }
    }

    /* handle empty list */
    if (len == 0) {
        if (!(ans = (PyArrayObject *)PyArray_Zeros(1, &minlength, type, 0))){
            goto fail;
        }
        Py_DECREF(lst);
        return (PyObject *)ans;
    }

    numbers = (npy_intp *) PyArray_DATA(lst);
    minmax(numbers, len, &mn, &mx);
    if (mn < 0) {
        PyErr_SetString(PyExc_ValueError,
                "The first argument of bincount must be non-negative");
        goto fail;
    }
    ans_size = mx + 1;
    if (mlength != Py_None) {
        if (ans_size < minlength) {
            ans_size = minlength;
        }
    }
    if (weight == Py_None) {
        ans = (PyArrayObject *)PyArray_Zeros(1, &ans_size, type, 0);
        if (ans == NULL) {
            goto fail;
        }
        ians = (npy_intp *)(PyArray_DATA(ans));
        NPY_BEGIN_ALLOW_THREADS;
        for (i = 0; i < len; i++)
            ians[numbers[i]] += 1;
        NPY_END_ALLOW_THREADS;
        Py_DECREF(lst);
    }
    else {
        wts = (PyArrayObject *)PyArray_ContiguousFromAny(
                                                weight, NPY_DOUBLE, 1, 1);
        if (wts == NULL) {
            goto fail;
        }
        weights = (double *)PyArray_DATA (wts);
        if (PyArray_SIZE(wts) != len) {
            PyErr_SetString(PyExc_ValueError,
                    "The weights and list don't have the same length.");
            goto fail;
        }
        type = PyArray_DescrFromType(NPY_DOUBLE);
        ans = (PyArrayObject *)PyArray_Zeros(1, &ans_size, type, 0);
        if (ans == NULL) {
            goto fail;
        }
        dans = (double *)PyArray_DATA(ans);
        NPY_BEGIN_ALLOW_THREADS;
        for (i = 0; i < len; i++) {
            dans[numbers[i]] += weights[i];
        }
        NPY_END_ALLOW_THREADS;
        Py_DECREF(lst);
        Py_DECREF(wts);
    }
    return (PyObject *)ans;

fail:
    Py_XDECREF(lst);
    Py_XDECREF(wts);
    Py_XDECREF(ans);
    return NULL;
}
Exemplo n.º 15
0
int  SplitterFrame::BoundSize()
{
	int maxsize = max(0, (type == LEFT || type == RIGHT ? parentsize.cx : parentsize.cy) - sizemin);
	return IsShown() ? max(4, minmax(size, minsize - 4, maxsize)) : 0;
}
Exemplo n.º 16
0
void handle_talk_event(POINT p)
{
	short i,j,force_special = 0,get_pc,s1 = -1,s2 = -1,s3 = -1;
	char asked[4];
	char place_string1[256] = "";
	char place_string2[256] = "";

	short a,b,c,d,ttype,which_talk_entry = -1;

	p.x -= 5;
	p.y -= 5;

	if (PtInRect(&talk_help_rect,p)) {
    	if (play_sounds == true) play_sound(37);
		party.help_received[5] = 0;
		give_help(205,6,0);
		return;
		}

	for (i = 0; i < 9; i++)
		if ((PtInRect(&preset_words[i].word_rect,p)) && ((talk_end_forced == false) || (i == 6) || (i == 5))) {
			click_talk_rect((char *) old_str1,(char *) old_str2,preset_words[i].word_rect);
			switch (i) {
				case 0: case 1: case 2: case 7: case 8:
					force_special = i + 1;
					break;
				case 3: case 4:
					force_special = i + 1;
					break;
				case 5: // save
					if (strnum1 <= 0) {
						MessageBeep(MB_OK);
						return;
						}
					for (j = 0; j < 120; j++)
						if ((party.talk_save[j].personality == store_personality) &&
						  (party.talk_save[j].str1 == strnum1) &&
						  (party.talk_save[j].str2 == strnum2)) {
						  	ASB("This is already saved.");
						  	print_buf();
						  	return;
						  	}
					for (j = 0; j < 120; j++)
						if (party.talk_save[j].personality <= 0) {
							give_help(57,0,0);
							play_sound(0);
							party.talk_save[j].personality = store_personality;
							party.talk_save[j].town_num = (unsigned char) c_town.town_num;
							party.talk_save[j].str1 = strnum1;
							party.talk_save[j].str2 = strnum2;
							ASB("Noted in journal.");
							j = 200;
							}
					if (j < 200) {
						MessageBeep(MB_OK);
						ASB("No more room in talking journal.");
						}
					print_buf();
					return;
					break;
				case 6: // quit
					end_talk_mode();

                	if(talk_end_forced == 10){ // party is in inn
                        talk_end_forced = true; // safety set
                        for(j=0; j < 700; j++){
                            party.age++;
                            // Specials countdowns
                            if ((party.age % 500 == 0) && (get_ran(1,0,5) == 3) && (adven.hasAbil(ITEM_DISEASE_PARTY) == true)) {
                                j = 900;
                                adven.disease(2);
                             }
                             // Plants and magic shops
                             if (party.age % 4000 == 0) refresh_store_items();

                             timed_special_happened = special_increase_age(0);//don't delay the trigger of the special, if there's a special

                             if(timed_special_happened && PSD[SDF_COMPATIBILITY_SPECIALS_INTERRUPT_REST] == 1){
                                j = 900;
               			        add_string_to_buf("  Rest interrupted.");
               			        print_buf();
                            }
                         }
                      }
					return;
					break;
				default:
					for (j = 0; j < 4; j++)
						asked[j] = preset_words[i].word[j];
					break;
				}
			i = 100;
			}
	if (i < 100) {
		for (i = 0; i < 50; i++)
			if ((PtInRect(&store_words[i].word_rect,p)) && (talk_end_forced == false)) {
				click_talk_rect((char *) old_str1,(char *) old_str2,store_words[i].word_rect);
				for (j = 0; j < 4; j++)
					asked[j] = store_words[i].word[j];

				i = 100;
				}
		}
    if(strcmp(talk_edit_string,"") != 0){
        for(j = 0; j < 4; j++)
            asked[j] = talk_edit_string[j];
        talk_edit_string[0] = '\0';
        i =  100;
        }

	if (i == 50) // no event
		return;
	if (force_special == 9) {
		get_text_response(1017,place_string1,0);
		asked[0] = place_string1[0];
		asked[1] = place_string1[1];
		asked[2] = place_string1[2];
		asked[3] = place_string1[3];
		}

	if ((asked[0] == 'n') && (asked[1] == 'a') &&(asked[2] == 'm') &&(asked[3] == 'e')) {
		force_special = 2;
		}
	if ((asked[0] == 'l') && (asked[1] == 'o') &&(asked[2] == 'o') &&(asked[3] == 'k')) {
		force_special = 1;
		}
	if (((asked[0] == 'j') && (asked[1] == 'o') &&(asked[2] == 'b')) ||
		((asked[0] == 'w') && (asked[1] == 'o') &&(asked[2] == 'r')&&(asked[3] == 'k')) ) {
		force_special = 3;
		}
	if((asked[0] == 'b') && (asked[1] == 'u') && (asked[2] == 'y'))
	   force_special = 4;
	if((asked[0] == 'b') && (asked[1] == 'y') && (asked[2] == 'e')){
		end_talk_mode();
        return;
        }

	if (force_special > 0) {
		switch (force_special) {
			case 1: case 2: case 3:
				GetIndString(place_string1,120 + ((store_personality - 1) / 10),
				 ((store_personality - 1) % 10) * 3 + 10 + force_special);
				sprintf((char *) place_string1,"%s",data_store3->talk_strs[store_personality % 10 + 10 * force_special]);

				oldstrnum1 = strnum1; oldstrnum2 = strnum2;
				strnum1 =  store_personality % 10 + 10 * force_special;
				strnum2 = 0;
				strcpy((char *) one_back1,(char *) old_str1);
				strcpy((char *) one_back2,(char *) old_str2);
				strcpy((char *) old_str1,(char *) place_string1);
				strcpy((char *) old_str2,(char *) place_string2);
				place_talk_str((char *) place_string1,(char *) place_string2,0,dummy_rect);
				return;
				break;
			case 4: // buy button
				asked[0] = 'p';asked[1] = 'u';asked[2] = 'r';asked[3] = 'c';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 's';asked[1] = 'a';asked[2] = 'l';asked[3] = 'e';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 'h';asked[1] = 'e';asked[2] = 'a';asked[3] = 'l';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 'i';asked[1] = 'd';asked[2] = 'e';asked[3] = 'n';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 't';asked[1] = 'r';asked[2] = 'a';asked[3] = 'i';
				if (scan_for_response(asked) >= 0)
					break;
				break;
			case 5: // sell button
				asked[0] = 's';asked[1] = 'e';asked[2] = 'l';asked[3] = 'l';
				if (scan_for_response(asked) >= 0)
					break;
				break;
			case 8: // back 1
				strnum1 = oldstrnum1; strnum2 = oldstrnum2;
				strcpy((char *) place_string1,(char *) one_back1);
				strcpy((char *) place_string2,(char *) one_back2);
				strcpy((char *) one_back1,(char *) old_str1);
				strcpy((char *) one_back2,(char *) old_str2);
				strcpy((char *) old_str1,(char *) place_string1);
				strcpy((char *) old_str2,(char *) place_string2);
				place_talk_str((char *) place_string1,(char *) place_string2,0,dummy_rect);
				return;
				break;
			}
		}

	which_talk_entry = scan_for_response(asked);
	if ((which_talk_entry < 0) || (which_talk_entry > 59)) {
		strcpy((char *) one_back1,(char *) old_str1);
		strcpy((char *) one_back2,(char *) old_str2);
		sprintf((char *) old_str2,"");
		sprintf((char *) old_str1,"%s",data_store3->talk_strs[store_personality % 10 + 160]);
		if (strlen((char *) old_str1) < 2)
			sprintf((char *) old_str1,"You get no response.");
		place_talk_str((char *) old_str1,(char *) old_str2,0,dummy_rect);
		strnum1 = -1;
		return;
		}

	ttype = talking.talk_nodes[which_talk_entry].type;
	a = talking.talk_nodes[which_talk_entry].extras[0];
	b = talking.talk_nodes[which_talk_entry].extras[1];
	c = talking.talk_nodes[which_talk_entry].extras[2];
	d = talking.talk_nodes[which_talk_entry].extras[3];

	sprintf(place_string1,"%s",data_store3->talk_strs[40 + which_talk_entry * 2]);
	sprintf(place_string2,"%s",data_store3->talk_strs[40 + which_talk_entry * 2 + 1]);

	oldstrnum1 = strnum1; oldstrnum2 = strnum2;
	strnum1 =  40 + which_talk_entry * 2; strnum2 = 40 + which_talk_entry * 2 + 1;

	switch(ttype) {
		case TALK_REGULAR:
			break;
		case TALK_DEP_ON_SDF:
			if (PSD[a][b] > c) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_SET_SDF:
			PSD[a][b] = 1;
			break;
		case TALK_INN:
			if (party.gold < a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
				else {
					talk_end_forced = true;
					party.gold -= a;
					put_pc_screen();
                    if(PSD[SDF_COMPATIBILITY_CHECK_TIMERS_WHILE_RESTING] == 1){
                       talk_end_forced = 10;
                       adven.heal(30 * b);
	                   adven.restoreSP(25 * b);
      				   c_town.p_loc.x = c;
	          		   c_town.p_loc.y = d;
			           center = c_town.p_loc;
                       }
					else{
                    adven.heal(30 * b);
					adven.restoreSP(25 * b);
					party.age += 700;
					c_town.p_loc.x = c;
					c_town.p_loc.y = d;
					center = c_town.p_loc;
                    }
				}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_DEP_ON_TIME:
			if (day_reached((unsigned char) a,0) == true) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_DEP_ON_TIME_AND_EVENT:
			if (day_reached((unsigned char) a,(unsigned char) b) == true) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_DEP_ON_TOWN:
			if (c_town.town_num != a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_BUY_ITEMS:
			c = minmax(1,30,(int)c);
			start_shop_mode(SHOP_MISC_SHOP,b,
				b + c - 1,a, place_string1);
			strnum1 = -1;
			return;
		case TALK_TRAINING:
			if ((get_pc = char_select_pc(1,0,"Train who?")) < 6) {
				strnum1 = -1;
				spend_xp(get_pc,1, 0);
				}
			sprintf(place_string1, "You conclude your training.");
            put_pc_screen();
			return;

		case TALK_BUY_MAGE: case TALK_BUY_PRIEST: case TALK_BUY_ALCHEMY:
			c = minmax(1,30,(int)c);
			start_shop_mode(ttype + 1,b,
				b + c - 1,a, place_string1);
			strnum1 = -1;
			return;
		case TALK_BUY_HEALING: //healer
			start_shop_mode(SHOP_HEALER,0,0,a, place_string1);
			strnum1 = -1;
			return;
			break;
		case TALK_SELL_WEAPONS: // sell weap
			strnum1 = -1;
			stat_screen_mode = 3;
			put_item_screen(stat_window,1);
			give_help(42,43,0);
			break;
		case TALK_SELL_ARMOR: // sell armor
			strnum1 = -1;
			stat_screen_mode = 4;
			put_item_screen(stat_window,1);
			give_help(42,43,0);
			break;
		case TALK_SELL_ITEMS: // sell misc
			strnum1 = -1;
			stat_screen_mode = 5;
			put_item_screen(stat_window,1);
			give_help(42,43,0);
			break;
		case TALK_IDENTIFY: case TALK_ENCHANT: // ident, enchant
            strnum1 = -1;
			stat_screen_mode = (ttype == 16) ? 2 : 6;
			shop_identify_cost = a;
			put_item_screen(stat_window,1);
			give_help(ttype - 16 + 44,0,0);
			break;
		case TALK_BUY_INFO:
			if (party.gold < a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
				else {
					party.gold -= a;
					put_pc_screen();

					}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_BUY_SDF:
			if ((sd_legit(b,c) == true) && (PSD[b][c] == d)) {
				sprintf(place_string1, "You've already learned that.");
				strnum1 = -1;
				}
			else if (party.gold < a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
				else {
					party.gold -= a;
					put_pc_screen();
					if (sd_legit(b,c) == true)
						PSD[b][c] = d;
						else give_error("Invalid Stuff Done flag called in conversation.","",0);
					}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_BUY_SHIP:
			if (party.gold < a) {
				strnum1 = strnum2;
				strnum2 = 0;
				strcpy(place_string1, place_string2);
				sprintf(place_string2,"");
				break;
				}
				else {
					for (i = b; i <= b + c; i++)
						if ((i >= 0) && (i < 30) && (party.boats[i].property == true)) {
							party.gold -= a;
							put_pc_screen();
							party.boats[i].property = false;
							sprintf(place_string2,"");
							strnum2 = 0;
							i = 1000;
							}
					if (i >= 1000)
						break;
					}
			sprintf(place_string1, "There are no boats left.");
			sprintf(place_string2,"");
			strnum1 = -1;
			strnum2 = -1;
			break;
		case TALK_BUY_HORSE:
			if (party.gold < a) {
				strnum1 = strnum2;
				strnum2 = 0;
				strcpy(place_string1, place_string2);
				sprintf(place_string2,"");
				break;
				}
				else {
					for (i = b; i <= b + c; i++)
						if ((i >= 0) && (i < 30) && (party.horses[i].property == true)) {
							party.gold -= a;
							put_pc_screen();
							party.horses[i].property = false;
							sprintf(place_string2,"");
							strnum2 = 0;
							i = 1000;
							}
					if (i >= 1000)
						break;
					}
			sprintf(place_string1, "There are no horses left.");
			sprintf(place_string2,"");
			strnum1 = -1;
			strnum2 = -1;
			break;
		case TALK_BUY_SPEC_ITEM:
			if (party.spec_items[a] > 0) {
				sprintf(place_string1, "You already have it.");
				strnum1 = -1;
				}
			else if (party.gold < b) {
				strcpy(place_string1, place_string2);
				strnum1 = strnum2;
				}
				else {
					party.gold -= b;
					put_pc_screen();
					party.spec_items[a] = 1;
					}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_BUY_JUNK:
			start_shop_mode(SHOP_MAGIC_SHOP_1 + b,0,
				9,a, place_string1);
			strnum1 = -1;
			return;
		case TALK_BUY_TOWN_LOC:
			if (party.can_find_town[b] > 0) {
				}
				else if (party.gold < a) {
					strnum1 = strnum2;
					strcpy(place_string1, place_string2);
					}
					else {
						party.gold -= a;
						put_pc_screen();
						party.can_find_town[b] = 1;
						}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_END_FORCE:
			talk_end_forced = true;
			break;
		case TALK_END_FIGHT:
			c_town.monst.dudes[store_m_num].attitude = 1;
			c_town.monst.dudes[store_m_num].mobile = 1;
			talk_end_forced = true;
			break;
		case TALK_END_ALARM:
			set_town_status(0);
			talk_end_forced = true;
			break;
		case TALK_END_DIE:
			c_town.monst.dudes[store_m_num].active = 0;
            // Special killing effects
            if (sd_legit(c_town.monst.dudes[store_m_num].monst_start.spec1,c_town.monst.dudes[store_m_num].monst_start.spec2) == true)
                party.stuff_done[c_town.monst.dudes[store_m_num].monst_start.spec1][c_town.monst.dudes[store_m_num].monst_start.spec2] = 1;
			talk_end_forced = true;
			break;
		case TALK_CALL_TOWN_SPEC: // town special
			 run_special(SPEC_TALK,2,a,c_town.p_loc,&s1,&s2,&s3);
			// check s1 & s2 to see if we got diff str, and, if so, munch old strs
			if ((s1 >= 0) || (s2 >= 0)) {
				strnum1 = -1;
				strnum2 = -1;
				sprintf(place_string1,"");
				sprintf(place_string2,"");
				}
			 get_strs(place_string1, place_string2,2,s1,s2);
			 if (s1 >= 0) strnum1 = 2000 + s1;
			 if (s2 >= 0) strnum2 = 2000 + s2;
			 put_pc_screen();
			 put_item_screen(stat_window,0);
			 break;
		case TALK_CALL_SCEN_SPEC: // scen special
			 run_special(SPEC_TALK,0,a,c_town.p_loc,&s1,&s2,&s3);
			// check s1 & s2 to see if we got diff str, and, if so, munch old strs
			if ((s1 >= 0) || (s2 >= 0)) {
				strnum1 = -1;
				strnum2 = -1;
				sprintf(place_string1,"");
				sprintf(place_string2,"");
				}
			 get_strs(place_string1, place_string2,0,s1,s2);
			 if (s1 >= 0) strnum1 = 3000 + s1;
			 if (s2 >= 0) strnum2 = 3000 + s2;
			put_pc_screen();
			put_item_screen(stat_window,0);
			break;
		}

	strcpy(one_back1, old_str1);
	strcpy(one_back2, old_str2);
	strcpy(old_str1, place_string1);
	strcpy(old_str2, place_string2);
	place_talk_str(old_str1, old_str2,0,dummy_rect);
}
Exemplo n.º 17
0
void display_pc_info()
{
	short i,store;
	Str255 str;
	short pc;
	char to_draw[60];
	
	short weap1 = 24,weap2 = 24,hit_adj = 0, dam_adj = 0,skill_item;

	pc = store_pc_num;
	
	store = pc_carry_weight(pc);
	i = amount_pc_can_carry(pc);
	sprintf ((char *) to_draw, "%s is carrying %d stones out of %d.",univ.party[pc].name.c_str(),store,i);
	csit(1019,69,(char *) to_draw);

	sprintf((char *) str,"%d out of %d.",
			univ.party[pc].cur_health,univ.party[pc].max_health);
	csit(1019,65,(char *) str);
	sprintf((char *) str,"%d out of %d.",
			univ.party[pc].cur_sp,univ.party[pc].max_sp);
	csit(1019,67,(char *) str);

	for (i = 0; i < 19; i++) {
		cdsin(1019,18 + i * 2,univ.party[pc].skills[i]);
		}
	store = total_encumberance(pc);
	cdsin(1019,62,store);
	csit(1019,9,univ.party[pc].name.c_str());
	cdsin(1019,11,univ.party[pc].level);
	cdsin(1019,13,univ.party[pc].experience);
	cdsin(1019,71,univ.party[pc].skill_pts);
	store = univ.party[pc].level * univ.party[pc].get_tnl();
	cdsin(1019,15,store);
	csp(1019,7,800 + univ.party[pc].which_graphic,PICT_PC);

	// Fight bonuses
	for (i = 0; i < 24; i++)
		if (((univ.party[pc].items[i].variety == 1) || (univ.party[pc].items[i].variety == 2)) &&
			(univ.party[pc].equip[i] == true)) {
					if (weap1 == 24)
						weap1 = i;
						else weap2 = i;
					}
				
	hit_adj = stat_adj(pc,1) * 5 - (total_encumberance(pc)) * 5 
		+ 5 * minmax(-8,8,univ.party[pc].status[1]);
	if ((univ.party[pc].traits[2] == false) && (weap2 < 24))
		hit_adj -= 25;

	dam_adj = stat_adj(pc,0) + minmax(-8,8,univ.party[pc].status[1]);
	if ((skill_item = text_pc_has_abil_equip(pc,37)) < 24) {
		hit_adj += 5 * (univ.party[pc].items[skill_item].item_level / 2 + 1);
		dam_adj += univ.party[pc].items[skill_item].item_level / 2;
		}
	if ((skill_item = text_pc_has_abil_equip(pc,43)) < 24) {
		dam_adj += univ.party[pc].items[skill_item].item_level;
		hit_adj += univ.party[pc].items[skill_item].item_level * 2;
		}

		
	csit(1019,56,"No weapon.");	
	csit(1019,57,"");	
	csit(1019,59,"No weapon.");	
	csit(1019,60,"");	
	if (weap1 < 24) {
		if (!univ.party[pc].items[weap1].ident)
			csit(1019,56,"Not identified.");
			else {
				if (hit_adj + 5 * univ.party[pc].items[weap1].bonus < 0)
					sprintf(to_draw,"Penalty to hit: %%%d",hit_adj + 5 * univ.party[pc].items[weap1].bonus);
					else sprintf(to_draw,"Bonus to hit: +%%%d",hit_adj + 5 * univ.party[pc].items[weap1].bonus);
				csit(1019,56,to_draw);
				sprintf(to_draw,"Damage: (1-%d) + %d",univ.party[pc].items[weap1].item_level
					,dam_adj + univ.party[pc].items[weap1].bonus);
				csit(1019,57,to_draw);

				}
			}
	if (weap2 < 24) {
		if (!univ.party[pc].items[weap2].ident)
			csit(1019,59,"Not identified.");
			else {
				if (hit_adj + 5 * univ.party[pc].items[weap2].bonus < 0)
					sprintf(to_draw,"Penalty to hit: %%%d",hit_adj + 5 * univ.party[pc].items[weap2].bonus);
					else sprintf(to_draw,"Bonus to hit: +%%%d",hit_adj + 5 * univ.party[pc].items[weap2].bonus);
				csit(1019,59,to_draw);
				sprintf(to_draw,"Damage: (1-%d) + %d",univ.party[pc].items[weap2].item_level
					,dam_adj + univ.party[pc].items[weap2].bonus);
				csit(1019,60,to_draw);

				}
			}

}
Exemplo n.º 18
0
/* compute the curvatures using the derivatives 
 * 
 * curvatures are saved into an array: crv_result
 *     in order of: Gauss, Mean, Max, Min
 */
double krv(vector v00, vector Deriv[3][3], real* crv_result)
{
    double x,y,z,d;
    double xu,yu,zu,du, xv,yv,zv,dv;
    double xuu,yuu,zuu,duu, xvv,yvv,zvv,dvv;
    double xuv,yuv,zuv,duv;
    double kes, m1, m2, m3;
    double L, M, N;
    double E, G, F;
    double K, H, Max, Min; // results
    double disc;

	double special_curvature;

    x = v00[0]; y = v00[1];
    z = v00[2]; d = v00[3];

    xu = Deriv[1][0][0]; yu = Deriv[1][0][1];
    zu = Deriv[1][0][2]; du = Deriv[1][0][3];

    xuu = Deriv[2][0][0]; yuu = Deriv[2][0][1];
    zuu = Deriv[2][0][2]; duu = Deriv[2][0][3];

    xv = Deriv[0][1][0]; yv = Deriv[0][1][1];
    zv = Deriv[0][1][2]; dv = Deriv[0][1][3];

    xvv = Deriv[0][2][0]; yvv = Deriv[0][2][1];
    zvv = Deriv[0][2][2]; dvv = Deriv[0][2][3];

    xuv = Deriv[1][1][0]; yuv = Deriv[1][1][1];
    zuv = Deriv[1][1][2]; duv = Deriv[1][1][3];

    L=det4(xuu,yuu,zuu,duu,
             xu,yu,zu,du,
             xv,yv,zv,dv,
             x,y,z,d);
    N=det4(xvv,yvv,zvv,dvv, 
             xu,yu,zu,du,
             xv,yv,zv,dv,
             x,y,z,d);
    M=det4(xuv,yuv,zuv,duv,
             xu,yu,zu,du,
             xv,yv,zv,dv,
             x,y,z,d);

    E = (xu*d-x*du)*(xu*d-x*du) + (yu*d-y*du)*(yu*d-y*du) +
		(zu*d-z*du)*(zu*d-z*du);
    G = (xv*d-x*dv)*(xv*d-x*dv) + (yv*d-y*dv)*(yv*d-y*dv) +
		(zv*d-z*dv)*(zv*d-z*dv);
    F = (xu*d-x*du)*(xv*d-x*dv) + (yu*d-y*du)*(yv*d-y*dv) +
		(zu*d-z*du)*(zv*d-z*dv);

    m1=det3(y,z,d,yu,zu,du,yv,zv,dv);
    m2=det3(x,z,d,xu,zu,du,xv,zv,dv);
    m3=det3(x,y,d,xu,yu,du,xv,yv,dv);
    kes=m1*m1+m2*m2+m3*m3;

	if(0) {//fabs(kes) < tol*tol) {  // temp for Jorg & Kestas & me class A
		K = H = Max = Min = 0;
	}
	else {
		K = d*d*d*d*(L*N-M*M)/(kes*kes);  // Gaussian curvature
		H = d*(L*G-2*M*F+N*E) / sqrt(kes*kes*kes) /2;  // Mean curvature
		disc = H*H - K;
		if (disc < 0) {
			if (disc < -tol)
				printf("[krv] disc %f H %f \n",disc, H);
			Max = Min = H;
		}
		else {
			disc = sqrt(disc);
			Max = H + disc;
			Min = H - disc;
		}
	}

	if(0) {  // scale the result by log?
    	K = scalebylog(K);
    	H = scalebylog(H);
    	Max = scalebylog(Max);
    	Min = scalebylog(Min);
	}

    crv_result[0] = K; // Gaussian curvature
    crv_result[1] = H; // Mean curvature
    crv_result[2] = Max; // max curvature
    crv_result[3] = Min; // min curvature

	// a special 
	special_curvature =  ratio_a*K + ratio_b*H*H;
//	printf("special_curvature : %f\n", special_curvature);

    if( freshObject )
		min_crv_value[4] = max_crv_value[4] = special_curvature;
	else {
		if(special_curvature<min_crv_value[4]) min_crv_value[4] = special_curvature;
		if(special_curvature>max_crv_value[4]) max_crv_value[4] = special_curvature;
	}

	// set the maximum or minimum value of all four curvatures
	minmax(crv_result, GAUSS_CRV, 4);


    return K;
}
Exemplo n.º 19
0
void LineEdit::MoveUpDown(int n, bool sel) {
	int cl = cursor;
	int ln = GetLinePos(cl);
	ln = minmax(ln + n, 0, line.GetCount() - 1);
	PlaceCaretNoG(GetGPos(ln, gcolumn), sel);
}
Exemplo n.º 20
0
HBITMAP KDIB::TransformBitmap(XFORM * xm, COLORREF crBack, int method)
{
	int x0, y0, x1, y1, x2, y2, x3, y3;

	Map(xm, 0,        0,         x0, y0);  // 0    1
	Map(xm, m_nWidth, 0,         x1, y1);  //
	Map(xm, 0,        m_nHeight, x2, y2);  // 2    3
	Map(xm, m_nWidth, m_nHeight, x3, y3);

	int xmin, xmax;
	int ymin, ymax;

	minmax(x0, x1, x2, x3, xmin, xmax);
	minmax(y0, y1, y2, y3, ymin, ymax);

	int destwidth  = xmax - xmin;
	int destheight = ymax - ymin;

	KBitmapInfo dest;
	dest.SetFormat(destwidth, destheight, m_pBMI->bmiHeader.biBitCount, m_pBMI->bmiHeader.biCompression);

	if ( m_nClrUsed )
		memcpy(dest.m_dibinfo.bmiColors, m_pRGBQUAD, sizeof(RGBQUAD) * m_nClrUsed);

	// create destination DIB section
	BYTE * pBits;
	HBITMAP hBitmap = CreateDIBSection(NULL, dest.GetBMI(), DIB_RGB_COLORS, (void **) & pBits, NULL, NULL);
	if ( hBitmap==NULL )
	{
		assert(false);
		return NULL;
	}

	// For testing GDI GetPixel speed, we need a HDC for the source bitmap
	HBITMAP hSrcBmp = NULL;
	HDC     hSrcDC  = NULL;
	HGDIOBJ hSrcOld = NULL;

	if ( method==method_gdi )
	{
		hSrcBmp = CreateDIBSection(NULL, m_pBMI, DIB_RGB_COLORS, (void **) & pBits, NULL, NULL);
		assert(hSrcBmp);

		hSrcDC  = CreateCompatibleDC(NULL);
		hSrcOld = SelectObject(hSrcDC, hSrcBmp);

		// copy pixels from DIB to source DIB section
		DrawDIB(hSrcDC, 0, 0, m_nWidth, m_nHeight, 0, 0, m_nWidth, m_nHeight, SRCCOPY);
	}

	// clear DIB section to background color
	HDC     hDstDC  = CreateCompatibleDC(NULL);
	HGDIOBJ hDstOld = SelectObject(hDstDC, hBitmap);

	HBRUSH hBrush = CreateSolidBrush(crBack);
	RECT rect = { 0, 0,  destwidth, destheight };
	FillRect(hDstDC, & rect, hBrush);
	DeleteObject(hBrush);

	KDIB destDIB;
	destDIB.AttachDIB(dest.GetBMI(), pBits, 0);

	POINT P[3] = { { x0-xmin, y0-ymin }, { x1-xmin, y1-ymin }, { x2-xmin, y2-ymin } };

	dibtick = GetTickCount();
	
	if ( (m_nBitCount<=8) && (method==method_24bpp) )
		method = method_direct;

	switch ( method )
	{
		case method_gdi:
			destDIB.PlgBltGetPixel(P, hSrcDC, 0, 0, m_nWidth, m_nHeight, hDstDC);
			break;   

		case method_direct:	
			destDIB.PlgBlt(P, this, 0, 0, m_nWidth, m_nHeight);
			break;   

		case method_24bpp:
			destDIB.PlgBlt24(P, this, 0, 0, m_nWidth, m_nHeight);
			break;
	}

	dibtick = GetTickCount() - dibtick;

	SelectObject(hDstDC, hDstOld);
	DeleteObject(hDstDC);

	if ( method==method_gdi )
	{
		SelectObject(hSrcDC, hSrcOld);

		DeleteObject(hSrcDC);
		DeleteObject(hSrcBmp);
	}

	return hBitmap;
}
Exemplo n.º 21
0
main() /* program to plot curvature of a rational
	  B-spline curve, expressed in piecewise
 	  rational cubic form. All curvatures are expected
	  in the input file b_kappas.dat. */
{
    FILE *file, *plotfile;

    int i,j,degree,degree1,degree2,istep,tol,buttno,howmany,dense;
    float t,shoulder,width,xmin1,ymin1,xmax1,ymax1,x,y,xx,yy,
          kappa_min, kappa_max, scale_x,scale_y, setline;
    float coeffx[1000],value[4];
    float coeffy[1000];
    float abs();
    char min[20],max[20];

    file = fopen("b_kappas.dat","r");
    plotfile= fopen("psplot.ps","w");
    fscanf(file,"%d", &howmany);
    fscanf(file,"%d", &dense);

    for(i=0; i <= howmany ; i++)
    {
        fscanf(file,"%f",&coeffx[i]);
        fscanf(file,"%f",&coeffy[i]);
    }
    minmax(coeffx,coeffy,howmany,value);
    sprintf(min,"%4.2f",value[2]);
    sprintf(max,"%4.2f",value[3]);
    kappa_max=value[3];
    kappa_min=value[2];

    width=value[3]-value[2];  /*to scale kappa printouts  */




    minmax(coeffx,coeffy,howmany,value); /* Setting the window:   */
    if (value[2] > 0.0) value[2]=0.0;  /* make sure kappa=0 is  */
    if (value[3] < 0.0) value[3]=0.0;  /* drawn. Give some room */
    width=(value[3]-value[2])/20.0;    /* in y-direction.       */
    value[2]=value[2]-width;
    value[3]=value[3]+width;


    degree1 = degree+1;






    /*********************creating a postscript file for the curvatures: *******************/


    /* rotate, so paper is used sideways */

    fprintf(plotfile,"90 rotate\n");
    fprintf(plotfile,"70 -602 translate\n");
    fprintf(plotfile,"10 300 translate\n");

    scale_x=450.0/(value[1]-value[0]);
    scale_y=300.0/(value[3]-value[2]);


    fprintf(plotfile,"0.6 setgray \n");
    fprintf(plotfile,"%f setlinewidth\n",0.1);

    fprintf(plotfile,"%f %f translate\n",
            -1.0*scale_x*value[0], -1.0*scale_y*value[2]);


    fprintf(plotfile,"newpath \n");
    fprintf(plotfile," %f %f moveto\n",
            0.0,0.0);
    fprintf(plotfile," %3.2f %3.2f lineto\n",
            scale_x*value[1],0.0);
    fprintf(plotfile,"stroke\n");

    fprintf(plotfile,"newpath \n");


    fprintf(plotfile," %f %f moveto\n",
            scale_x*value[1],0.0);
    fprintf(plotfile," %f %f lineto\n",
            scale_x*value[0],0.0);
    fprintf(plotfile," %f %f lineto\n",
            scale_x*coeffx[0],scale_y*coeffy[0]);


    for(j=1; j<= howmany; j++)
    {
        fprintf(plotfile," %f %f lineto\n",
                scale_x*coeffx[j], scale_y*coeffy[j]);
    }
    fprintf(plotfile," %f %f lineto\n",
            scale_x*coeffx[howmany],scale_y*coeffy[howmany]);
    fprintf(plotfile,"fill\n");



    /******* plot box : *************/

    fprintf(plotfile,"0.0 setgray\n");
    fprintf(plotfile,"0.3 setlinewidth\n");
    fprintf(plotfile,"newpath\n");
    fprintf(plotfile,"%f %f moveto\n",
            scale_x*value[0],scale_y*value[2]);
    fprintf(plotfile,"%f %f lineto\n",
            scale_x*value[0],scale_y*value[3]);
    fprintf(plotfile,"%f %f lineto\n",
            scale_x*value[1],scale_y*value[3]);
    fprintf(plotfile,"%f %f lineto\n",
            scale_x*value[1],scale_y*value[2]);
    fprintf(plotfile,"%f %f lineto\n",
            scale_x*value[0],scale_y*value[2]);
    fprintf(plotfile,"stroke\n");

    /***** plot markers: ************/

    fprintf(plotfile,"0.0 setgray\n ");

    if(howmany > dense)
        for(j=0; j<= howmany; j=j+dense)
        {
            if(j >= 0) /*to keep numbering right */
                /*			    but to skip first point */
                fprintf(plotfile,"%f %f %f %f %f arc stroke\n",
                        scale_x*coeffx[j], scale_y*coeffy[j],
                        3.0, 0.0, 360.0);
        }

    fprintf(plotfile,"1.0 setgray\n ");

    if(howmany > dense)
        for(j=0; j<= howmany; j=j+dense)
        {
            if(j >= 0)  /* see above  */
                fprintf(plotfile,"%f %f %f %f %f arc fill\n",
                        scale_x*coeffx[j], scale_y*coeffy[j],
                        2.6, 0.0, 360.0);
        }

    /***** print min-max values: *************/

    fprintf(plotfile,"0.0 setgray\n ");

    fprintf(plotfile,"/Times-Roman findfont 15 scalefont setfont\n");

    fprintf(plotfile,"%f %f moveto\n",
            scale_x*value[1]+10, scale_y*kappa_max);

    fprintf(plotfile,"(max: %3.3f)show\n",kappa_max);

    fprintf(plotfile,"%f %f moveto\n",
            scale_x*value[1]+10, scale_y*kappa_min);

    fprintf(plotfile,"(min: %3.3f)show\n",kappa_min);

    fprintf(plotfile,"showpage");
    /*********************************************************************/


    fclose(file);
    fclose(plotfile);
}
Exemplo n.º 22
0
 void max(const Real &e) {
     minmax(e, MAX);
 }
Exemplo n.º 23
0
 void min(const Real &e) {
     minmax(e, MIN);
 }
Exemplo n.º 24
0
/*
* Integrate peaks
*/
void psnd_integrate1d(MBLOCK *mblk, float x1, float x2)
{
    int i;
    int i1 = round(x1);
    int i2 = round(x2);
    int lim1 = min(i1, i2);
    int lim2 = max(i1, i2);    
    int xmin, xmax;
    float sum0, sum1, sum, ymin, ymax, yrange,xx;
    char *label;
    POPUP_INFO *popinf = mblk->popinf + POP_INT1D;
    
    lim1 = max(1, lim1);
    lim2 = max(1, lim2);
    lim1 = min(DAT->isize, lim1);
    lim2 = min(DAT->isize, lim2);

    mblk->int1dinf->left  = min(lim1,lim2);
    mblk->int1dinf->right = max(lim1,lim2);
    update_labels(mblk);

    lim1 = mblk->int1dinf->left;
    lim2 = mblk->int1dinf->right;
    /*
     * ... determine integral over visible area (and min and max)
     */
    for (i=0,sum0=0;i<DAT->isize;i++)
        sum0 += DAT->xreal[i];
    if (sum0 == 0)
        sum0 = 1;
    /*        
     *
     * ... determine integral over selected area (and min and max)
     * ... and draw the intensity lines
     *
     */
    g_append_object(mblk->spar[S_REAL].obj_id);
    g_set_foreground(mblk->spar[S_REAL].color);
    
    for (i=lim1,sum=0,xmin=lim1,xmax=lim1;i<=lim2;i++) {
        sum += DAT->xreal[i-1];
        g_moveto((float) i, DAT->xreal[i-1]);
        g_lineto((float) i, 0.0);
    }
    /*
     *
     * ...  calc integral
     *
     */
    g_set_foreground(mblk->spar[S_REAL].color3);
    minmax(DAT->xreal,DAT->isize,&(DAT->ylimit[0]),&(DAT->ylimit[1]));
    sum1=0;
    yrange = (DAT->ylimit[1] - DAT->ylimit[0])/ sum0;
    for (i=lim1;i<lim2;i++) {
        sum1 += yrange * DAT->xreal[i-1];
        DAT->work1[i-1] = sum1;
    }
    /*
     * Try to move integral on top of peak
     */
    xx=DAT->ylimit[0];
    for (i=lim1;i<lim2;i++) {
        if (xx < (DAT->xreal[i-1]-DAT->work1[i-1]))
            xx = DAT->xreal[i-1]-DAT->work1[i-1];
    }
    /*
     * But not outside window
     */
    if (DAT->work1[lim2-2]+xx>DAT->ylimit[1])
        xx -= -DAT->ylimit[1] + (DAT->work1[lim2-2] + xx);
    xx += (DAT->ylimit[1] - DAT->ylimit[0])/100;
    for (i=lim1;i<lim2;i++) {
        DAT->work1[i-1] += xx;
    }
    /*
     * Draw integral
     */
    g_moveto((float) lim1, DAT->work1[lim1-1]);
    for (i=lim1;i<lim2;i++) {
        g_lineto((float)i, DAT->work1[i-1]);
    }
    /*
     * Print label
     */
    g_moveto((float) lim1, DAT->work1[lim1-1]+(DAT->work1[lim2-2]-DAT->work1[lim1-1])/2);
    label = psnd_sprintf_temp("%.2e", sum);
/*    g_set_motif_realtextrotation(1);
    g_set_textdirection(90);*/
    g_label(label);
/*    g_set_textdirection(0);*/
    g_set_foreground(mblk->spar[S_REAL].color);
    g_close_object(mblk->spar[S_REAL].obj_id);
    g_plotall();
/*    g_set_motif_realtext rotation(0);*/
    mblk->int1dinf->sum = sum;
    if (popinf->visible)
        add_integral(mblk);
    psnd_printf(mblk," Range: %6d%6d Area: %g\n", lim1, lim2, sum);
}
	Color(float a, float b, float c):
	r{minmax(a)},
	g{minmax(b)},
	b{minmax(c)}
	{}
Exemplo n.º 26
0
void LineEdit::SetEditPosSb(const LineEdit::EditPos& pos) {
	SetCursor(pos.cursor);
	sb.SetY(minmax(pos.sby, 0, line.GetCount() - 1));
}
Exemplo n.º 27
0
void set_up_shop_array()
{
	short i,shop_pos = 0;
	Boolean cursed_item = false;
	item_record_type store_i;
	long store_l;

	for (i = 0; i < 30; i++)
		store_shop_items[i] = -1;
	switch (store_shop_type) {
		case SHOP_WEAPON_SHOP: case SHOP_ARMOR_SHOP: case SHOP_MISC_SHOP:
			for (i = store_shop_min; i < store_shop_max + 1; i++) {
				store_shop_items[shop_pos] = i;
				store_i = get_stored_item(store_shop_items[shop_pos]);
				store_shop_costs[shop_pos] = (store_i.charges == 0) ?
				  store_i.value : store_i.value * store_i.charges;
				shop_pos++;
				}
			break;
		case SHOP_HEALER:
			if (adven[current_pc].cur_health < adven[current_pc].max_health) {
				store_shop_items[shop_pos] = 700;
				store_shop_costs[shop_pos] = heal_costs[0];
				shop_pos++;
				}
			if (adven[current_pc].status[STATUS_POISON] > 0) {
				store_shop_items[shop_pos] = 701;
				store_shop_costs[shop_pos] = heal_costs[1];
				shop_pos++;
				}
			if (adven[current_pc].status[STATUS_DISEASE] > 0) {
				store_shop_items[shop_pos] = 702;
				store_shop_costs[shop_pos] = heal_costs[2];
				shop_pos++;
				}
			if (adven[current_pc].status[STATUS_PARALYZED] > 0) {
				store_shop_items[shop_pos] = 703;
				store_shop_costs[shop_pos] = heal_costs[3];
				shop_pos++;
				}
			if (adven[current_pc].status[STATUS_DUMB] > 0) {
				store_shop_items[shop_pos] = 708;
				store_shop_costs[shop_pos] = heal_costs[8];
				shop_pos++;
				}
			for (i = 0; i < 24; i++)
				if ((adven[current_pc].equip[i] == true) && (adven[current_pc].items[i].isCursed()))
					cursed_item = true;
  			if (cursed_item) {
				store_shop_items[shop_pos] = 704;
				store_shop_costs[shop_pos] = heal_costs[4];
				shop_pos++;
				}
			if (adven[current_pc].main_status == MAIN_STATUS_STONE) {
				store_shop_items[shop_pos] = 705;
				store_shop_costs[shop_pos] = heal_costs[5];
				shop_pos++;
				}
			if (adven[current_pc].main_status == MAIN_STATUS_DEAD){
				store_shop_items[shop_pos] = 706;
				store_shop_costs[shop_pos] = heal_costs[6];
				shop_pos++;
				}
			if  (adven[current_pc].main_status == MAIN_STATUS_DUST){
				store_shop_items[shop_pos] = 707;
				store_shop_costs[shop_pos] = heal_costs[7];
				shop_pos++;
				}
			break;
		case SHOP_FOOD:
			break;
		case SHOP_MAGIC_SHOP_1: case SHOP_MAGIC_SHOP_2: case SHOP_MAGIC_SHOP_3: case SHOP_MAGIC_SHOP_4: case SHOP_MAGIC_SHOP_5:
			for (i = 0; i < 10; i++)
				if (party.magic_store_items[store_shop_type - 5][i].variety != ITEM_TYPE_NO_ITEM) {
					store_shop_items[shop_pos] = (store_shop_type - 4) * 1000 + i;
					store_i = party.magic_store_items[store_shop_type - 5][i];
					store_shop_costs[shop_pos] = (store_i.charges == 0) ?
					  store_i.value : store_i.value * store_i.charges;
					shop_pos++;
					}
			break;
		case SHOP_MAGE_SPELLS:
			for (i = store_shop_min; i < store_shop_max + 1; i++)
				if (i == minmax(0,31,(int)i)) {
				store_i = store_mage_spells(i);
				store_shop_costs[shop_pos] = store_i.value;
				store_shop_items[shop_pos] = 800 + i + 30;
				shop_pos++;
				}
			break;
		case SHOP_PRIEST_SPELLS:
			for (i = store_shop_min; i < store_shop_max + 1; i++)
				if (i == minmax(0,31,(int)i)) {
				store_i = store_priest_spells(i);
				store_shop_costs[shop_pos] = store_i.value;
				store_shop_items[shop_pos] = 900 + i + 30;
				shop_pos++;
				}
			break;
		case SHOP_ALCHEMY:
			for (i = store_shop_min; i < store_shop_max + 1; i++)
				if (i == minmax(0,19,(int)i)) {
				store_i = store_alchemy(i);
				store_shop_costs[shop_pos] = store_i.value;
				store_shop_items[shop_pos] = 500 + i;
				shop_pos++;
				}
			break;
		}
	for (i = 0; i < 30; i++)
		if (store_shop_items[i] >= 0) {
			store_l = store_shop_costs[i];
			store_l = (store_l * cost_mult[store_cost_mult]) / 10;
			store_shop_costs[i] = (short) store_l;
			}
  	i = max(0,shop_pos - 8);
    lpsi.nMax = i;
    lpsi.fMask = SIF_RANGE;
    SetScrollInfo(shop_sbar,SB_CTL,&lpsi,false);
	//SetScrollRange(shop_sbar,SB_CTL,0,i,true);

}
Exemplo n.º 28
0
void TopWindow::SerializePlacement(Stream& s, bool reminimize)
{
	GuiLock __;
#ifndef PLATFORM_WINCE
	int version = 1;
	s / version;
	Rect rect = GetRect();
	s % overlapped % rect;
	bool mn = state == MINIMIZED;
	bool mx = state == MAXIMIZED;
	bool fs = fullscreen;	// 12-05-23 Tom added fullscreen serialization
	if(version >= 1)
		s.Pack(mn, mx, fs);		// 12-05-23 Tom changed from: s.Pack(mn, mx);
	else
		s.Pack(mn, mx);
	LLOG("TopWindow::SerializePlacement / " << (s.IsStoring() ? "write" : "read"));
	LLOG("minimized = " << mn << ", maximized = " << mx << ", fullscreen = " << fs); // 12-05-23 Tom extended with fullscreen
	LLOG("rect = " << rect << ", overlapped = " << overlapped);
	if(s.IsLoading()) {
		rect = overlapped;
		Rect limit = GetVirtualWorkArea();
		Rect outer = rect;
		::AdjustWindowRect(outer, WS_OVERLAPPEDWINDOW, FALSE);
		limit.left   += rect.left   - outer.left;
		limit.top    += rect.top    - outer.top;
		limit.right  += rect.right  - outer.right;
		limit.bottom += rect.bottom - outer.bottom;
		Size sz = min(rect.Size(), limit.Size());
		rect = RectC(
			minmax(rect.left, limit.left, limit.right - sz.cx),
			minmax(rect.top,  limit.top,  limit.bottom - sz.cy),
			sz.cx, sz.cy);

		Overlap();
		SetRect(rect);
		
		if(mn && reminimize){
			state = MINIMIZED;
			//Minimize(); // 12-05-23 Tom removed
		}
		if(mx){
			state = MAXIMIZED;
			//Maximize(); // 12-05-23 Tom removed
		}
		if(IsOpen()) {
			switch(state) {
				case MINIMIZED:
					Minimize();
					break;
				case MAXIMIZED:
					Maximize();
					break;
			}
/*			WINDOWPLACEMENT wp;
			memset(&wp,0,sizeof(WINDOWPLACEMENT));
			wp.length=sizeof(WINDOWPLACEMENT);
			wp.showCmd = state==MINIMIZED ? SW_MINIMIZE : state==MAXIMIZED ? SW_MAXIMIZE : SW_RESTORE;
			wp.rcNormalPosition.left=rect.left;
			wp.rcNormalPosition.top=rect.top;
			wp.rcNormalPosition.right=rect.right;
			wp.rcNormalPosition.bottom=rect.bottom;
			::SetWindowPlacement(GetHWND(),&wp);
*/
			if(fs) {
				Overlap(); // Needed to restore normal position before fullscreen mode
				FullScreen(fs); // 12-05-23 Tom added for fullscreen serialization
			}
		}
		else // 12-05-23 Tom added for fullscreen serialization
			fullscreen=fs; // 12-05-23 Tom added for fullscreen serialization
	}
#endif
}
Exemplo n.º 29
0
static void
laplace (int width, int height, unsigned char *srcPR, unsigned char *destPR)
{
  int         bytes;
  int         current;
  int         gradient;
  unsigned char      *dest, *d;
  unsigned char      *prev_row, *pr;
  unsigned char      *cur_row, *cr;
  unsigned char      *next_row, *nr;
  unsigned char      *tmp;
  int         row, col;
  int         minval, maxval;

  /* image area */

  /* Get the size of the input image. (This will/must be the same
   *  as the size of the output image.
   */
  bytes  = 3;

  /*  allocate row buffers  */
  prev_row = malloc((width + 2) * bytes);
  cur_row  = malloc((width + 2) * bytes);
  next_row = malloc((width + 2) * bytes);
  dest     = malloc(width * bytes);

  pr = prev_row + bytes;
  cr = cur_row + bytes;
  nr = next_row + bytes;

  laplace_prepare_row(srcPR, pr, 0, -1, width, height);
  laplace_prepare_row(srcPR, cr, 0, 0, width, height);

  /*  loop through the rows, applying the laplace convolution  */
  for (row = 0; row < height; row++)
    {
      /*  prepare the next row  */
      laplace_prepare_row (srcPR, nr, 0, row + 1, width, height);
      // dprint("nr %d %d %d", nr[0], nr[1], nr[2]);

      d = dest;

      for (col = 0; col < width * bytes; col++)
        {
          minmax (pr[col], cr[col - bytes], cr[col], cr[col + bytes],
                nr[col], &minval, &maxval); /* four-neighbourhood */

          gradient = (0.5 * MAX ((maxval - cr [col]), (cr[col]- minval)));

          *d++ = (((  pr[col - bytes] + pr[col]       + pr[col + bytes] +
                      cr[col - bytes] - (8 * cr[col]) + cr[col + bytes] +
                      nr[col - bytes] + nr[col]       + nr[col + bytes]) > 0) ?
                    gradient : (128 + gradient));

      /*  store the dest  */
        }
      memcpy(destPR + width*bytes*row, dest, width*bytes);

      /*  shuffle the row pointers  */
      tmp = pr;
      pr = cr;
      cr = nr;
      nr = tmp;
    }


  /* now clean up: leave only edges, but keep gradient value */

  memcpy(srcPR, destPR, width*height*bytes);

  pr = prev_row + bytes;
  cr = cur_row + bytes;
  nr = next_row + bytes;

  laplace_prepare_row (srcPR, pr, 0, -1, width, height);
  laplace_prepare_row (srcPR, cr, 0, 0, width, height);

  /*  loop through the rows, applying the laplace convolution  */
  for (row = 0; row < height; row++)
    {
      /*  prepare the next row  */
      laplace_prepare_row (srcPR, nr, 0, row + 1, width, height);

      d = dest;
      for (col = 0; col < width * bytes; col++)
        {
          current = cr[col];
          current = ((WHITE_REGION (current) &&
                      (BLACK_REGION (pr[col - bytes]) ||
                       BLACK_REGION (pr[col])         ||
                       BLACK_REGION (pr[col + bytes]) ||
                       BLACK_REGION (cr[col - bytes]) ||
                       BLACK_REGION (cr[col + bytes]) ||
                       BLACK_REGION (nr[col - bytes]) ||
                       BLACK_REGION (nr[col])         ||
                       BLACK_REGION (nr[col + bytes]))) ?
                     ((current >= 128) ? (current - 128) : current) : 0);

          *d++ = current;
          if (col % bytes == 2) {
            if (*(d-1) < 15 && *(d-2) < 15 && *(d-3) < 15) {
              *(d-1) = 255;
              *(d-2) = 255;
              *(d-3) = 255;
            }
          }
        }

      /*  store the dest  */
      memcpy(destPR + width*bytes*row, dest, width*bytes);

      /*  shuffle the row pointers  */
      tmp = pr;
      pr = cr;
      cr = nr;
      nr = tmp;

    }

  /*  update the laplaced region  */

  free (prev_row);
  free (cur_row);
  free (next_row);
  free (dest);
}
Exemplo n.º 30
0
bool Thread::Priority(int percent)
{
	ASSERT(IsOpen());
#ifdef PLATFORM_WIN32
	int prior;
	if(percent <= 25)
		prior = THREAD_PRIORITY_LOWEST;
	else if(percent <= 75)
		prior = THREAD_PRIORITY_BELOW_NORMAL;
	else if(percent <= 125)
		prior = THREAD_PRIORITY_NORMAL;
	else if(percent <= 175)
		prior = THREAD_PRIORITY_ABOVE_NORMAL;
	else
		prior = THREAD_PRIORITY_HIGHEST;
	return SetThreadPriority(handle, prior);
#endif
#ifdef PLATFORM_POSIX
	int policy;
	struct sched_param param;
	
	if(pthread_getschedparam(handle, &policy, &param))
		return false;
	int percent_min = 0, percent_max = 200;
	if(percent <= 25) {
		#if defined(SCHED_IDLE)
			policy = SCHED_IDLE;
			percent_min = 0;
			percent_max = 25;
		#elif defined(SCHED_BATCH)
			policy = SCHED_BATCH;
			percent_min = 0;
			percent_max = 75;
		#else
			policy = SCHED_OTHER;
			percent_min = 0;
			percent_max = 125;
		#endif
	}
	else
	if(percent <= 75){
		#if defined(SCHED_IDLE)
			policy = SCHED_BATCH;
			percent_min = 25;
			percent_max = 75;
		#elif defined(SCHED_BATCH)
			policy = SCHED_BATCH;
			percent_min = 0;
			percent_max = 75;
		#else
			policy = SCHED_OTHER;
			percent_min = 0;
			percent_max = 125;
		#endif
	}
	else
	if(percent <= 125){
		policy = SCHED_OTHER;
		#if defined(SCHED_IDLE)
			percent_min = 75;
			percent_max = 125;
		#elif defined(SCHED_BATCH)
			percent_min = 25;
			percent_max = 125;
		#else
			percent_min = 0;
			percent_max = 125;
		#endif
	}
	else
	if(percent <= 175){ // should be the root
		policy = SCHED_FIFO;
		percent_min = 125;
		percent_max = 175;
	}
	else
		policy = SCHED_RR;

	param.sched_priority = (sched_get_priority_max(policy) - sched_get_priority_min(policy))*(minmax(percent, percent_min, percent_max)-percent_min)/(percent_max - percent_min);
	
	if (pthread_setschedparam(handle, policy, &param)) {
		// No privileges? Try maximum possible! Do not use EPERM as not all os support this one
		policy = SCHED_OTHER;
		percent_max = 125;
		percent_min = minmax(percent_min, 0, percent_max);
		param.sched_priority = (sched_get_priority_max(policy) - sched_get_priority_min(policy))*(minmax(percent, percent_min, percent_max)-percent_min)/(percent_max - percent_min);
		if (pthread_setschedparam(handle, policy, &param))
			return false;
	}
	return true;
#endif
}