Beispiel #1
0
dsdict_node* dsdict_find(dsdict* dict, dstring* value, dsdict_node* iterator) {
	dsdict_node* node;

	if (iterator) {
		node = iterator->next;
	} else {
		node = dict->front;
	}

	while(node) {
		if (dcmp(node->value, value) == 0) {
			return node;
		}
		node = node->next;
	}

	return NULL;
}
Beispiel #2
0
int PhaseII(int n, int m, double *c, double a[maxn][maxn],
    double *rhs, double &ans, int PivotIndex)
{
    int i,j,k,l; double tmp;
    while(k=Pivot(n,m,c,a,rhs,i,j),k==PIVOT_OK || PivotIndex)
    {
        if( PivotIndex ) { j=0; i=PivotIndex; PivotIndex=0; }
        basic[row[i]]=0; col[row[i]]=0; basic[j]=1; col[j]=i; row[i]=j; 
        tmp=a[i][j]; for(k=0;k<=n;k++) a[i][k]/=tmp; rhs[i]/=tmp;
        for(k=1;k<=m;k++) if(k!=i && dcmp(a[k][j]))
        {
            tmp = -a[k][j]; for(l=0;l<=n;l++) a[k][l]+=tmp*a[i][l];
            rhs[k] += tmp*rhs[i];
        }
        tmp=-c[j]; for(l=0;l<=n;l++) c[l]+=a[i][l]*tmp; ans-=tmp*rhs[i];
    }   
    return k;
}
Beispiel #3
0
int dlist_equals(const dstrlist* l1, const dstrlist* l2) {
	dstrnode *n1, *n2;
	if (l1->size != l2->size) {
		return 0;
	}
	
	n1 = l1->front;
	n2 = l2->front;
	
	while(n1) {
		if (dcmp(n1->string, n2->string) != 0) {
			return 0;
		}
		
		n1 = n1->next;
		n2 = n2->next;
	}
	
	return 1;
}
Beispiel #4
0
double getArea(const Point &a, const Point &b, const double &r) {
	double dA = dot(a, a), dB = dot(b, b), dC = getPointDist(a, b), ans = 0.0;
	if (dcmp(dA - r * r) <= 0 && dcmp(dB - r * r) <= 0) return det(a, b) / 2.0;
	Point tA = a / dist(a) * r;
	Point tB = b / dist(b) * r;
	if (dcmp(dC - r) > 0) return getSectorArea(tA, tB, r);
	std::pair<Point, Point> ret = getIntersection(a, b, r);
	if (dcmp(dA - r * r) > 0 && dcmp(dB - r * r) > 0) {
		ans += getSectorArea(tA, ret.first, r);
		ans += det(ret.first, ret.second) / 2.0;
		ans += getSectorArea(ret.second, tB, r);
		return ans;
	}
	if (dcmp(dA - r * r) > 0) return det(ret.first, b) / 2.0 + getSectorArea(tA, ret.first, r);
	else return det(a, ret.second) / 2.0 + getSectorArea(ret.second, tB, r);
}
 void bfs()
 {
     CLR(vis,0);
     front = tail = 0;
     d[t] = 0;
     vis[t] = true;
     que[tail++] = t;
     while(front < tail)
     {
         int u = que[front++];
         for(int v = head[u]; v != -1; v = next[v])
         {
             edge & e = edges[v^1];
             if(dcmp(e.cap-e.flow) > 0 && !vis[e.from]) //对处于残余网络中的弧且没访问过的节点处理
             {
                 d[e.from] = d[u] + 1;
                 vis[e.from] = true;
                 que[tail++] = e.from;
             }
         }
     }
 }
Beispiel #6
0
inline bool cmp2(const int &a,const int &b)
{
    return dcmp(p[a].y,p[b].y)<0;
}
Beispiel #7
0
int main(int argc, char* argv[]) {
	dstring *s1, *s2, *s3, *s4, *s5, *s6;
	
	/* dstring* dnew(); */
	test_start("dnew()");
	s1 = dnew();
	test_assert(s1 != NULL);
	test_assert(s1->data != NULL);
	test_assert(s1->size > 0);
	test_assert(s1->len == 0);
	test_assert(s1->data[0] == 0);
	test_end();
	
	/* dstring* dnewcopy(const dstring* str); */
	test_start("dnewcopy()");
	s2 = dnewcopy(s1);
	test_assert(s2 != NULL);
	test_assert(s2->data != NULL);
	test_assert(s2->size > 0);
	test_assert(s2->len == 0);
	test_assert(s2->data[0] == 0);
	s1->data[0] = 'A';
	s1->data[1] = 0;
	s1->len = 1;
	dfree(s2);
	s2 = dnewcopy(s1);
	test_assert(s2->len == 1);
	test_assert(strcmp(s1->data, s2->data) == 0);
	test_end();
	
	/* void dfree(dstring* str); */
	test_start("dfree()");
	dfree(s1);
	dfree(s2);
	test_assert(1);
	test_end();
	
	/* dstring* dfromc(int chr); */
	test_start("dfromc()");
	s1 = dfromc('X');
	test_assert(s1 != NULL);
	test_assert(s1->len == 1);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "X") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dfromcs(const char* str); */
	test_start("dfromcs()");
	s1 = dfromcs("Hello World!");
	test_assert(s1 != NULL);
	test_assert(s1->len == 12);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dfrommem(const void* mem, size_t size); */
	test_start("dfrommem()");
	s1 = dfrommem("Hello World!", 12);
	test_assert(s1 != NULL);
	test_assert(s1->len == 12);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dcpy(dstring* dst, const dstring* src); */
	test_start("dcpy()");
	s1 = dfromcs("Hello ");
	s2 = dfromcs("World!!!");
	s3 = dcpy(s1, s2);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 8);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "World!!!") == 0);
	dfree(s1);
	dfree(s2);
	test_end();
	
	/* dstring* dcpyc(dstring* dst, int src); */
	test_start("dcpyc()");
	s1 = dfromcs("Hello");
	s2 = dcpyc(s1, '!');
	
	test_assert(s2 == s1);
	test_assert(s1->len == 1);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "!") == 0);
	dfree(s1);
	test_end();

	/* dstring* dcpycs(dstring* dst, const char* src); */
	test_start("dcpycs");
	s1 = dfromcs("Hello");
	s2 = dcpycs(s1, "Hola!");
	
	test_assert(s2 == s1);
	test_assert(s1->len == 5);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Hola!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dcpymem(dstring* dst, const void* mem, size_t size); */
	test_start("dcpymem");
	s1 = dfromcs("Hello");
	s2 = dcpymem(s1, "Foo!", 4);
	
	test_assert(s2 == s1);
	test_assert(s1->len == 4);
	test_assert(s1->data != NULL);
	test_assert(strcmp(s1->data, "Foo!") == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dncpy(dstring* dst, const dstring* src, dstrlen_t n); */
	test_start("dncpy");
	s1 = dfromcs("Hello");
	s2 = dfromcs("World!");
	s1 = dncpy(s1, s2, 5);
	
	test_assert(s1->len == 5);
	test_assert(strcmp(s1->data, "World") == 0);
	
	s1 = dncpy(s1, s2, 20);
	test_assert(s1->len == 6);
	test_assert(strcmp(s1->data, "World!") == 0);
	
	dfree(s1);
	dfree(s2);
	test_end();
	
	/* dstring* dncpycs(dstring* dst, const char* src, dstrlen_t n); */
	test_start("dncpycs");
	s1 = dfromcs("Hello");
	s1 = dncpycs(s1, "World!", 5);
	
	test_assert(s1->len == 5);
	test_assert(strcmp(s1->data, "World") == 0);
	
	s1 = dncpycs(s1, "World!", 20);
	test_assert(s1->len == 6);
	test_assert(strcmp(s1->data, "World!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dcat(dstring* dst, const dstring* src); */
	test_start("dcat");
	s1 = dfromcs("Hello ");
	s2 = dfromcs("World!");
	s3 = dcat(s1, s2);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 12);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	
	dfree(s1);
	dfree(s2);
	test_end();
	
	/* dstring* dcatc(dstring* dst, int src); */
	test_start("dcatc");
	s1 = dfromcs("Hello");
	s3 = dcatc(s1, '!');
	
	test_assert(s1 == s3);
	test_assert(s1->len == 6);
	test_assert(strcmp(s1->data, "Hello!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dcatcs(dstring* dst, const char* src); */
	test_start("dcatcs");
	s1 = dfromcs("Hello ");
	s3 = dcatcs(s1, "World!");
	
	test_assert(s1 == s3);
	test_assert(s1->len == 12);
	test_assert(strcmp(s1->data, "Hello World!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dcatmem(dstring* dst, const void* src, size_t size); */
	test_start("dcatmem");
	s1 = dfromcs("Hello ");
	s3 = dcatmem(s1, "Guys!", 5);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 11);
	test_assert(strcmp(s1->data, "Hello Guys!") == 0);
	
	dfree(s1);
	test_end();
	
	/* dstring* dncat(dstring* dst, const dstring* src, dstrlen_t n); */
	test_start("dncat");
	s2 = dfromcs("Guys!");
	s1 = dfromcs("Hello ");
	s3 = dncat(s1, s2, 4);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 10);
	test_assert(strcmp(s1->data, "Hello Guys") == 0);
	dfree(s1);
	
	s1 = dfromcs("Hello ");
	s3 = dncat(s1, s2, 8);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 11);
	test_assert(strcmp(s1->data, "Hello Guys!") == 0);
	dfree(s1);
	
	dfree(s2);
	test_end();
	
	/* dstring* dncatcs(dstring* dst, const char* src, dstrlen_t n); */
	test_start("dncatcs");
	s1 = dfromcs("Hello ");
	s3 = dncatcs(s1, "Guys!", 4);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 10);
	test_assert(strcmp(s1->data, "Hello Guys") == 0);
	dfree(s1);
	
	s1 = dfromcs("Hello ");
	s3 = dncatcs(s1, "Guys!", 8);
	
	test_assert(s1 == s3);
	test_assert(s1->len == 11);
	test_assert(strcmp(s1->data, "Hello Guys!") == 0);
	dfree(s1);
	test_end();
	
	/* int dcmp(const dstring* a, const dstring* b); */
	test_start("dcmp");
	s1 = dfromcs("ddd");
	s2 = dfromcs("aaa");
	s3 = dfromcs("zzz");
	s4 = dfromcs("bo");
	s5 = dfromcs("aaaa");
	s6 = dfromcs("ddd");
	
	test_assert(dcmp(s1, s2) != 0);
	test_assert(dcmp(s1, s3) != 0);
	test_assert(dcmp(s1, s4) != 0);
	test_assert(dcmp(s1, s5) != 0);
	test_assert(dcmp(s1, s6) == 0);
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	dfree(s4);
	dfree(s5);
	dfree(s6);
	test_end();
	
	/* int dcmpc(const dstring* a, int b); */
	test_start("dcmpc");
	s1 = dfromc('X');
	test_assert(dcmpc(s1, 'a') != 0);
	test_assert(dcmpc(s1, 'x') != 0);
	test_assert(dcmpc(s1, 'X') == 0);
	dfree(s1);
	test_end();
	
	/* int dcmpcs(const dstring* a, const char* b); */
	test_start("dcmpcs");
	s1 = dfromcs("Foo");
	test_assert(dcmpcs(s1, "FO") != 0);
	test_assert(dcmpcs(s1, "barr") != 0);
	test_assert(dcmpcs(s1, "Foo") == 0);
	dfree(s1);
	test_end();
	
	/* int dcmpmem(const dstring* a, const void* b, size_t size); */
	test_start("dcmpmem");
	s1 = dfromcs("Foo");
	test_assert(dcmpmem(s1, "FO", 2) != 0);
	test_assert(dcmpmem(s1, "barr", 4) != 0);
	test_assert(dcmpmem(s1, "Foo", 3) == 0);
	dfree(s1);
	test_end();
	
	/* dstring* dsub(const dstring* a, dstrlen_t start, dstrlen_t length); */
	test_start("dsub");
	s1 = dfromcs("hello world!");
	s2 = dsub(s1, 0, 5);
	s3 = dsub(s1, 6, 6);
	s4 = dsub(s1, 6, 12);
	s5 = dsub(s1, 20, 10);
	
	test_assert(dcmpcs(s2, "hello") == 0);
	test_assert(dcmpcs(s3, "world!") == 0);
	test_assert(dcmpcs(s4, "world!") == 0);
	test_assert(dcmpcs(s5, "") == 0);
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	dfree(s4);
	dfree(s5);
	test_end();
	
	/* int dstartswith(const dstring* a, const dstring* b); */
	test_start("dstartswith");
	s1 = dfromcs("Is this ok?");
	s2 = dfromcs("Is");
	s3 = dfromcs("bla");
	
	test_assert(dstartswith(s1, s2));
	test_assert(!dstartswith(s1, s3));
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	test_end();
	
	/* int dstartswithc(const dstring* a, int b); */
	test_start("dstartswithc");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dstartswithc(s1, 'I'));
	test_assert(!dstartswithc(s1, 'O'));
	
	dfree(s1);
	test_end();
	
	/* int dstartswithcs(const dstring* a, const char* b); */
	test_start("dstartswithcs");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dstartswithcs(s1, "Is"));
	test_assert(!dstartswithcs(s1, "is"));
	
	dfree(s1);
	test_end();
	
	/* int dendswith(const dstring* a, const dstring* b); */
	test_start("dendswith");
	s1 = dfromcs("Is this ok?");
	s2 = dfromcs("ok?");
	s3 = dfromcs("Ok?");
	
	test_assert(dendswith(s1, s2));
	test_assert(!dendswith(s1, s3));
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	test_end();
	
	/* int dendswithc(const dstring* a, int b); */
	test_start("dendswithc");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dendswithc(s1, '?'));
	test_assert(!dendswithc(s1, '!'));
	
	dfree(s1);
	test_end();
	
	/* int dendswithcs(const dstring* a, const char* b); */
	test_start("dendswithcs");
	s1 = dfromcs("Is this ok?");
	
	test_assert(dendswithcs(s1, "ok?"));
	test_assert(!dendswithcs(s1, "ok!"));
	
	dfree(s1);
	test_end();
	
	/* int dpos(const dstring* a, const dstring* b, dstrlen_t start); */
	test_start("dpos");
	s1 = dfromcs("this is a good place");
	s2 = dfromcs("is");
	s3 = dfromcs("bla");
	
	test_assert(dpos(s1, s2, 0) == 2);
	test_assert(dpos(s1, s2, 4) == 5);
	test_assert(dpos(s1, s2, 7) == -1);
	test_assert(dpos(s1, s3, 44) == -1);
	
	dfree(s1);
	dfree(s2);
	dfree(s3);
	test_end();
	
	/* int dposc(const dstring* a, int b, dstrlen_t start); */
	test_start("dposc");
	s1 = dfromcs("this is a good place");
	
	test_assert(dposc(s1, 'i', 0) == 2);
	test_assert(dposc(s1, 'i', 4) == 5);
	test_assert(dposc(s1, 'j', 7) == -1);
	test_assert(dposc(s1, 'x', 44) == -1);
	
	dfree(s1);
	test_end();
	
	/* int dposcs(const dstring* a, const char* b, dstrlen_t start); */
	test_start("dposcs");
	s1 = dfromcs("this is a good place");
	
	test_assert(dposcs(s1, "is", 0) == 2);
	test_assert(dposcs(s1, "is", 4) == 5);
	test_assert(dposcs(s1, "is", 7) == -1);
	test_assert(dposcs(s1, "bla", 44) == -1);
	
	dfree(s1);
	test_end();
	
	
	return 0;
}
Beispiel #8
0
int onpara(pt_t a, pt_t b, pt_t c, pt_t d)
{
	double u = cross(b.x - a.x, b.y - a.y, d.x - c.x, d.y - c.y);
	return dcmp(u) == 0;
}
Beispiel #9
0
double getPointDist(const Point &a, const Point &b) {
	Point d = b - a;
	int sA = dcmp(dot(a, d)), sB = dcmp(dot(b, d));
	if (sA * sB <= 0) return det(a, b) / dist(a, b);
	else return std::min(dist(a), dist(b));
}
Beispiel #10
0
int __eqdf2(double a, double b)
{
	return dcmp(a,b);
}
Beispiel #11
0
	bool Pair_Comp(const Point &a, const Point &b) {
		if (dcmp(a.x - b.x) < 0) return true;
		if (dcmp(a.x - b.x) > 0) return false;
		return dcmp(a.y - b.y) < 0;
	}
Beispiel #12
0
		bool isVisible(const std::vector<TPoint> &p, const Face &f, const TPoint &a) {
			return dcmp(detdot(p[f.a], p[f.b], p[f.c], a)) > 0;
		}
Beispiel #13
0
int CollateJSON(const sized_buf *buf1,
                const sized_buf *buf2,
                CollateJSONMode mode)
{
    const char* str1 = buf1->buf;
    const char* str2 = buf2->buf;
    int depth = 0;

    do {
        /* Get the types of the next token in each string: */
        ValueType type1 = valueTypeOf(*str1);
        ValueType type2 = valueTypeOf(*str2);
        /* If types don't match, stop and return their relative ordering: */
        if (type1 != type2) {
            if (mode != kCollateJSON_Raw)
                return cmp(type1, type2);
            else
                return cmp(kRawOrderOfValueType[type1], kRawOrderOfValueType[type2]);

        /* If types match, compare the actual token values: */
        } else switch (type1) {
            case kNull:
            case kTrue:
                str1 += 4;
                str2 += 4;
                break;
            case kFalse:
                str1 += 5;
                str2 += 5;
                break;
            case kNumber: {
                char* next1, *next2;
                int diff;
                if (depth == 0) {
                    /* At depth 0, be careful not to fall off the end of the
                       input, because there won't be any delimiters (']' or
                       '}') after the number! */
                    diff = dcmp( readNumber(str1, buf1->buf + buf1->size, &next1),
                                 readNumber(str2, buf2->buf + buf2->size, &next2) );
                } else {
                    diff = dcmp( strtod(str1, &next1), strtod(str2, &next2) );
                }
                if (diff)
                    return diff; /* Numbers don't match */
                str1 = next1;
                str2 = next2;
                break;
            }
            case kString: {
                int diff;
                if (mode == kCollateJSON_Unicode)
                    diff = compareStringsUnicode(&str1, &str2);
                else
                    diff = compareStringsASCII(&str1, &str2);
                if (diff)
                    return diff; /* Strings don't match */
                break;
            }
            case kArray:
            case kObject:
                ++str1;
                ++str2;
                ++depth;
                break;
            case kEndArray:
            case kEndObject:
                ++str1;
                ++str2;
                --depth;
                break;
            case kComma:
            case kColon:
                ++str1;
                ++str2;
                break;
            case kIllegal:
                return 0;
        }
    /* Keep going as long as we're inside an array or object */
    } while (depth > 0);
    return 0;
}
Beispiel #14
0
float betweenangle(vector2D &v1, vector2D&v2) {
	float f = abs(v1)*abs(v2);
	if (!dcmp(f)) f = eps;
	return acos(dot(v1, v2) / f);
}
Beispiel #15
0
bool checkAnswer(const double &answer) {
	Point relativeTarget;
	if (dcmp(answer - tMax) <= 0) relativeTarget = target - windPrevSpeed * answer;
	else relativeTarget = target - windPrevSpeed * tMax - windSuccSpeed * (answer - tMax);
	return dcmp((relativeTarget - source).dist() - vMax * answer) <= 0;
}
Beispiel #16
0
std::pair<double, double> getSolution(const double &a, const double &b, const double &c) {
	double delta = b * b - 4.0 * a * c;
	if (dcmp(delta) < 0) return std::make_pair(0, 0);
	else return std::make_pair((-b - sqrt(delta)) / (2.0 * a), (-b + sqrt(delta)) / (2.0 * a));
}
Beispiel #17
0
int online(pt_t a, pt_t b, pt_t c, pt_t d)
{
	double u = cross(c.x - a.x, c.y - a.y, d.x - c.x, d.y - c.y);
	double v = cross(d.x - b.x, d.y - b.y, c.x - d.x, c.y - d.y);
	return dcmp(u) == 0 && dcmp(v) == 0;
}
 bool tangency(const Circle& rhs) const
 { return dcmp(Length(c-rhs.c) - r - rhs.r) == 0; }
Beispiel #19
0
inline bool cmp(const POINT &a,const POINT &b)
{
    return dcmp(a.x,b.x)<0;
}
 bool contain(const Point& p) const
 { return dcmp(Length(c-p) - r) <= 0; }
 bool intersect(const Circle& rhs) const
 { return dcmp(Length(c-rhs.c) - r - rhs.r) < 0; }
 bool contain(const Circle& rhs) const
 { return dcmp(Length(c-rhs.c) + rhs.r - r) <= 0; }
bool operator == (const Point& a, const Point& b)
{ return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0; }
bool solve()
{
    if(IsOnlyOnePoint()) return true;
    memset(del, false, sizeof(del));
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
        {
            if(del[j] || i == j) continue;
            if(cir[i].contain(cir[j]))
            {
                del[i] = true;
                break;
            }
        }
    double ans = 0.0;
    for(int i = 0; i < n; ++i)
    {
        if(del[i]) continue;
        last->clear();
        Point p1, p2;
        for(int j = 0; j < n; ++j)
        {
            if(del[j] || i == j) continue;
            if(!cir[i].intersect(cir[j])) return false;
            cur->clear();
            IntersectionPoint(cir[i], cir[j], p1, p2);
            double rs = Angle(p2 - cir[i].c);
            double rt = Angle(p1 - cir[i].c);
            if(dcmp(rs) < 0) rs += 2 * PI;
            if(dcmp(rt) < 0) rt += 2 * PI;
            if(last->n == 0)
            {
                if(dcmp(rt - rs) < 0)
                {
                    cur->add(Region(rs, 2*PI));
                    cur->add(Region(0,  rt));
                }
                else cur->add(Region(rs, rt));
            }
            else
            {
                for(int k = 0; k < last->n; ++k)
                {
                    if(dcmp(rt - rs) < 0)
                    {
                        if(dcmp(last->v[k].st-rt) >= 0 && dcmp(last->v[k].ed-rs) <= 0) continue;
                        if(dcmp(last->v[k].st-rt) < 0) cur->add(Region(last->v[k].st, std::min(last->v[k].ed, rt)));
                        if(dcmp(last->v[k].ed-rs) > 0) cur->add(Region(std::max(last->v[k].st, rs), last->v[k].ed));
                    }
                    else
                    {
                        if(dcmp(rt-last->v[k].st <= 0 || dcmp(rs-last->v[k].ed) >= 0)) continue;
                        cur->add(Region(std::max(rs, last->v[k].st), std::min(rt, last->v[k].ed)));
                    }
                }
            }
            std::swap(cur, last);
            if(last->n == 0) break;
        }
        for(int j = 0; j < last->n; ++j)
        {
            p1 = cir[i].get_point(last->v[j].st);
            p2 = cir[i].get_point(last->v[j].ed);
            ans += Cross(p1, p2) / 2;
            double ang = last->v[j].ed - last->v[j].st;
            ans += cir[i].r * cir[i].r * (ang - sin(ang)) / 2;
        }
    }
    if(dcmp(ans) == 0) return false;
    printf("The total possible area is %.2f.\n", ans);
    return true;
}
Beispiel #25
0
 void operator()(std::vector<ValuePtr> entries) {
     DerefBinaryOp<Compare> dcmp(cmp);
     compat::sort(entries.begin(), entries.end(), dcmp);
     out(std::move(entries));
 }
int CollateJSON(void *context, int len1, const void * chars1, int len2, const void * chars2) {
    
    static bool charPriorityMapInitialized = false;
    if(!charPriorityMapInitialized){
        initializeCharPriorityMap();
        charPriorityMapInitialized = true;
    }
    
    const char* str1 = (const char*) chars1;
    const char* str2 = (const char*) chars2;
    int depth = 0;
    
    do {
        
        // Get the types of the next token in each string:
        ValueType type1 = valueTypeOf(*str1);
        ValueType type2 = valueTypeOf(*str2);
        // If types don't match, stop and return their relative ordering:
        if (type1 != type2) {
            if (context != kJsonCollator_Raw)
                return cmp(type1, type2);
            else
                return cmp(kRawOrderOfValueType[type1],
                           kRawOrderOfValueType[type2]);
            
            // If types match, compare the actual token values:
        } else
            switch (type1) {
                case kNull:
                case kTrue:
                    str1 += 4;
                    str2 += 4;
                    break;
                case kFalse:
                    str1 += 5;
                    str2 += 5;
                    break;
                case kNumber: {
                    char* next1, *next2;
                    int diff;
                    if (depth == 0) {
                        diff = dcmp( readNumber(str1, str1 + len1, &next1),
                                    readNumber(str2, str2 + len2, &next2) );
                    } else {
                        diff = dcmp(strtod(str1, &next1), strtod(str2, &next2));
                    }
                    if (diff) {
                        return diff; // Numbers don't match
                    }
                    str1 = next1;
                    str2 = next2;
                    break;
                }
                case kString: {
                    int diff;
                    if (context == kJsonCollator_Unicode)
                        diff = compareStringsUnicode(&str1, &str2);
                    else
                        diff = compareStringsASCII(&str1, &str2);
                    if (diff)
                        return diff; // Strings don't match
                    break;
                }
                case kArray:
                case kObject:
                    ++str1;
                    ++str2;
                    ++depth;
                    break;
                case kEndArray:
                case kEndObject:
                    ++str1;
                    ++str2;
                    --depth;
                    break;
                case kComma:
                case kColon:
                    ++str1;
                    ++str2;
                    break;
                case kIllegal:
                    return 0;
            }
    } while (depth > 0); // Keep going as long as we're inside an array or object
    return 0;
}