예제 #1
0
int main(int argc, char *argv[]) {
  Point myPoint = point_new(0.0, 0.0);
  Vector unitX = vector_new(1.0, 0.0);
  Vector unitY = vector_new(0.0, 1.0);

  printf("%s + %s + %s = ", point_toString(myPoint),
                            vector_toString(unitX),
                            vector_toString(unitY) );

  point_addVector(myPoint, unitX);
  point_addVector(myPoint, unitY);

  printf("As a tuple: %s\n", tuple_toString((Tuple)myPoint));
  printf("As a point: %s\n", point_toString(myPoint));

  printf( "After scaling unitX by -0.5: %s\n",
	  vector_toString(vector_scale(unitX, -0.5))
	);
  printf("unitX has length %lf\n", vector_length(unitX));

  vector_delete(unitX);
  vector_delete(unitY);
  point_delete(myPoint);

  return 0;
}
예제 #2
0
int main(int argc, char *argv[]) {
  Point myPoint = point_new(0.0, 0.0);
  Vector unitX = vector_new(1.0, 0.0);
  Vector unitY = vector_new(0.0, 1.0);

  printf("%s + %s + %s = ", point_toString(myPoint),
                            vector_toString(unitX),
                            vector_toString(unitY) );

  point_addVector(&myPoint, unitX);
  point_addVector(&myPoint, unitY);

  printf("%s\n", point_toString(myPoint));

  return 0;
}
예제 #3
0
extern void function_printAsKarnaugh(Function* f, FILE* out) {
	int rows, cols;
	char * rowsVars, * colsVars;
	Points * colsP, * rowsP;
	PointItem * rowPointItem, * colPointItem;
	rows = function_getVarsLength(f) / 2;
	cols = function_getVarsLength(f) - rows;
	
	rowsVars = calloc(rows+1, sizeof(char));
	colsVars = calloc(cols+1, sizeof(char));
	
	// Variable names
	memcpy(colsVars, f->vars, cols);
	colsVars[cols] = '\0';
	memcpy(rowsVars, &(f->vars[cols]), rows);
	rowsVars[cols] = '\0';
	
	colsP = points_grayCode(cols);
	rowsP = points_grayCode(rows);
	// Column
	fprintf(out, "%-*s%s\n", cols+2, colsVars,
		str_strips(points_toString(colsP),"(),") );
	// Rows
	fprintf(out, "%s\n", rowsVars);
	
	// Rows line by line
	rowPointItem = rowsP->point;
	do {
		// Row value
		fprintf(out, "%-*s", cols+2, str_strips(point_toString(rowPointItem->p),"(),") );
		
		// Columns
		colPointItem = colsP->point;
		do {
			fprintf(out, "%-*d ", cols, function_eval(f, point_concat(colPointItem->p, rowPointItem->p) ) );
			
			colPointItem = colPointItem->next;
		} while (colPointItem != 0);
		
		fprintf(out, "\n");
		
		rowPointItem = rowPointItem->next;
	} while(rowPointItem != 0);
}
예제 #4
0
char * points_toString(Points* points) {
    PointItem* pointItem;
    char * out, * pointStr;
    int outLen = 3; // +1 the null terminator, +2 the ", "

    pointItem = points->point;
    out = strdup("");
    if (pointItem == 0) return out;

    do {
        pointStr = point_toString(pointItem->p);
        out = realloc(out, outLen + strlen(pointStr) * sizeof(char));
        if (outLen != 3) {
            strcat(out, ", ");
            outLen+=2;
        }
        strcat(out,pointStr);
        outLen += strlen(pointStr);
        pointItem = pointItem->next;
    } while (pointItem != 0);
    
    return out;
}
예제 #5
0
extern void function_printEvalPoint(Function* f, Point p, FILE* out) {
  char * sfree;
  fprintf(out, "%s%s = %d\n", f->symbol, sfree = point_toString(p), function_eval(f,p) );
  if (sfree != 0) free(sfree);
}