Esempio n. 1
0
File: ex3.c Progetto: shiift/CSE4095
int main()
{
    Poly* p1 = readPoly();
    Poly* p2 = readPoly();
    Poly* sum;

    /* 
    printPoly(p1);
    printPoly(p2);
    printf("\n\n\n");
    */

    if( (p1 == NULL) && (p2 == NULL) )
    {
        fprintf(stderr, "Could not allocate memory\n");
        return 1;
    }

    printPoly( sum = addPoly( p1, p2 ) );

    freePoly(p1);
    freePoly(p2);
    freePoly(sum);

    return 0;
}
Esempio n. 2
0
void
PCLoaderXML::myStartElement(int element,
                            const SUMOSAXAttributes& attrs) {
    if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) {
        return;
    }
    bool ok = true;
    // get the id, report an error if not given or empty...
    std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
    std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, myOptions.getString("type"));
    if (!ok) {
        return;
    }
    // patch the values
    bool discard = myOptions.getBool("discard");
    if (myTypeMap.has(type)) {
        const PCTypeMap::TypeDef& def = myTypeMap.get(type);
        discard = def.discard;
        setDefaults(def.prefix, def.color, def.layer, def.allowFill);
    } else {
        setDefaults(myOptions.getString("prefix"), RGBColor::parseColor(myOptions.getString("color")),
            myOptions.getFloat("layer"), myOptions.getBool("fill"));
    }
    if (!discard) {
        if (element == SUMO_TAG_POI) {
            addPOI(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
        }
        if (element == SUMO_TAG_POLY) {
            addPoly(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
        }
    }
}
Esempio n. 3
0
File: 5.c Progetto: Daehoho/study
int main (void) {
	puts("\n 작성자 : 201121403 한대호");

	ListHead *A, *B, *C;

	A = createLinkedList();
	B = createLinkedList();
	C = createLinkedList();

	addLastNode(A, 4,3);
	addLastNode(A, 3,2);
	addLastNode(A, 5,1);
	printf("\n A(x) = ");
	printPoly(A);

	addLastNode(B, 3,4);
	addLastNode(B, 1,3);
	addLastNode(B, 2,1);
	addLastNode(B, 1,0);
	printf("\n B(x) = ");

	printPoly(B);

	addPoly(A, B, C);
	printf("\n C(x) = ");
	printPoly(C);

	getchar();

	return 0;
}
void testPoly(){
    int coefficientArr[5] = {10, 3, 54, 45, 3};
    int exponentArr[5] = {12, 3, 34, 3, 53};
    
    Poly *p1 = makePoly(coefficientArr, exponentArr, 5);
    Poly *p2 = makePoly(coefficientArr, exponentArr, 5);
    Poly *p = addPoly(p1, p2);
    
    PolyNode *node = p->head;
    while (node = node->next) {
        printf(node->next ? "%dx^%d + " : "%dx^%d\n", node->coefficient, node->exponent);
    }
}
Esempio n. 5
0
void
ShapeHandler::myStartElement(int element,
                             const SUMOSAXAttributes& attrs) {
    try {
        switch (element) {
            case SUMO_TAG_POLY:
                addPoly(attrs);
                break;
            case SUMO_TAG_POI:
                addPOI(attrs);
                break;
            default:
                break;
        }
    } catch (InvalidArgument& e) {
        WRITE_ERROR(e.what());
    }
}
Esempio n. 6
0
void
NLHandler::myStartElement(int element,
                          const SUMOSAXAttributes& attrs) {
    try {
        switch (element) {
            case SUMO_TAG_EDGE:
                beginEdgeParsing(attrs);
                break;
            case SUMO_TAG_LANE:
                addLane(attrs);
                break;
            case SUMO_TAG_POLY:
                addPoly(attrs);
                break;
            case SUMO_TAG_POI:
                addPOI(attrs);
                break;
            case SUMO_TAG_JUNCTION:
                openJunction(attrs);
                initJunctionLogic(attrs);
                break;
            case SUMO_TAG_PHASE:
                addPhase(attrs);
                break;
            case SUMO_TAG_CONNECTION:
                addConnection(attrs);
                break;
            case SUMO_TAG_TLLOGIC:
                initTrafficLightLogic(attrs);
                break;
            case SUMO_TAG_REQUEST:
                addRequest(attrs);
                break;
            case SUMO_TAG_WAUT:
                openWAUT(attrs);
                break;
            case SUMO_TAG_WAUT_SWITCH:
                addWAUTSwitch(attrs);
                break;
            case SUMO_TAG_WAUT_JUNCTION:
                addWAUTJunction(attrs);
                break;
            case SUMO_TAG_E1DETECTOR:
            case SUMO_TAG_INDUCTION_LOOP:
                addE1Detector(attrs);
                break;
            case SUMO_TAG_E2DETECTOR:
            case SUMO_TAG_LANE_AREA_DETECTOR:
                addE2Detector(attrs);
                break;
            case SUMO_TAG_E3DETECTOR:
            case SUMO_TAG_ENTRY_EXIT_DETECTOR:
                beginE3Detector(attrs);
                break;
            case SUMO_TAG_DET_ENTRY:
                addE3Entry(attrs);
                break;
            case SUMO_TAG_DET_EXIT:
                addE3Exit(attrs);
                break;
            case SUMO_TAG_INSTANT_INDUCTION_LOOP:
                addInstantE1Detector(attrs);
                break;
            case SUMO_TAG_VSS:
                myTriggerBuilder.parseAndBuildLaneSpeedTrigger(myNet, attrs, getFileName());
                break;
            case SUMO_TAG_CALIBRATOR:
                myTriggerBuilder.parseAndBuildCalibrator(myNet, attrs, getFileName());
                break;
            case SUMO_TAG_REROUTER:
                myTriggerBuilder.parseAndBuildRerouter(myNet, attrs, getFileName());
                break;
            case SUMO_TAG_BUS_STOP:
                myTriggerBuilder.parseAndBuildBusStop(myNet, attrs);
                break;
            case SUMO_TAG_VTYPEPROBE:
                addVTypeProbeDetector(attrs);
                break;
            case SUMO_TAG_ROUTEPROBE:
                addRouteProbeDetector(attrs);
                break;
            case SUMO_TAG_MEANDATA_EDGE:
                addEdgeLaneMeanData(attrs, SUMO_TAG_MEANDATA_EDGE);
                break;
            case SUMO_TAG_MEANDATA_LANE:
                addEdgeLaneMeanData(attrs, SUMO_TAG_MEANDATA_LANE);
                break;
            case SUMO_TAG_TIMEDEVENT:
                myActionBuilder.addAction(attrs, getFileName());
                break;
            case SUMO_TAG_VAPORIZER:
                myTriggerBuilder.buildVaporizer(attrs);
                break;
            case SUMO_TAG_LOCATION:
                setLocation(attrs);
                break;
            case SUMO_TAG_TAZ:
                addDistrict(attrs);
                break;
            case SUMO_TAG_TAZSOURCE:
                addDistrictEdge(attrs, true);
                break;
            case SUMO_TAG_TAZSINK:
                addDistrictEdge(attrs, false);
                break;
            default:
                break;
        }
    } catch (InvalidArgument& e) {
        WRITE_ERROR(e.what());
    }
    MSRouteHandler::myStartElement(element, attrs);
    if (element == SUMO_TAG_PARAM) {
        addParam(attrs);
    }
}
Esempio n. 7
0
void Printlines::makeLines(const vector<Poly> polys, 
			   const vector<Poly> *clippolys,
			   Vector2d &startPoint,
			   bool displace_startpoint, 
			   double minspeed, double maxspeed, double movespeed, // mm/s
			   double linewidth, double linewidthratio, double optratio,
			   double maxArcAngle, bool linelengthsort,
			   double AOmindistance, double AOspeed,
			   double AOamount, double AOrepushratio)
{
  uint count = polys.size();
  if (polys.size()==0) return;
  int nvindex=-1;
  int npindex=-1;
  uint nindex;
  vector<bool> done(count); // polys not yet handled
  for(size_t q=0;q<count;q++) done[q]=false;
  uint ndone=0;
  double pdist, nstdist;
  //double nlength;
  double lastavlength = -1;
  while (ndone < count) 
    {
      if (linelengthsort && npindex>=0) 
	lastavlength = polys[npindex].averageLinelengthSq();
      nstdist = 1000000;
      for(size_t q=0; q<count; q++) { // find nearest polygon
	if (polys[q].size() == 0) {done[q] = true; ndone++;}
	if (!done[q])
	  {
	    pdist = 1000000;
	    nindex = polys[q].nearestDistanceSqTo(startPoint,pdist);
	    if (pdist<nstdist){
	      npindex = q;      // index of nearest poly in polysleft
	      nstdist = pdist;  // distance of nearest poly
	      nvindex = nindex; // nearest point in nearest poly
	    }
	  }
      }
      // find next nearest polygon, but with similar line length
      if (linelengthsort && lastavlength > 0) { 
	double minavlengthdiff = 10000000;
	for(size_t q=0; q<count; q++) {
	  if (!done[q]) 
	    {
	      nindex = polys[q].nearestDistanceSqTo(startPoint,pdist);
	      if ( pdist < 400 ){ // nearer than 20mm // || 
		//(nstdist==0 && pdist < 10000*linewidth*linewidth) ) {
		double avlength = polys[q].averageLinelengthSq();		
		double avldiff = abs(avlength-lastavlength);
		if (avldiff < minavlengthdiff) {
		  //cerr << npindex << " : " <<avlength << " - " <<avldiff << endl;
		  minavlengthdiff = avldiff;
		  npindex = q;
		  nvindex = nindex;
		}
	      }
	    }
	}
      }
      if (displace_startpoint && ndone==0)  // displace first point
	nvindex = (nvindex+1)%polys[npindex].size();
      if (npindex >= 0 && npindex >=0) {
	addPoly(polys[npindex], nvindex, maxspeed, movespeed);
	done[npindex]=true;
	ndone++;
      }
      if (lines.size()>0)
	startPoint = lastPoint();
    }
  if (count == 0) return;
  setZ(polys.back().getZ());
  clipMovements(clippolys, linewidth/2.);
  optimize(minspeed, maxspeed, movespeed, 
	   linewidth, linewidthratio, optratio, maxArcAngle,
	   AOmindistance, AOspeed, AOamount, AOrepushratio);
}
Esempio n. 8
0
File: Main.c Progetto: tonivi/CIS27
void menu() {
	int option;
	PolyListTonivi poly1 = NULL;
	PolyListTonivi poly2 = NULL;
	PolyListTonivi* result = (PolyListTonivi*)calloc(1, sizeof(PolyListTonivi));

	do {
		printf("\n*************************************"
			"\n*    POLYNOMIAL OPERATIONS          *"
			"\n*   1. Creating polynomials         *"
			"\n*   2. Adding polynomials           *"
			"\n*   3. Multiplying polynomials      *"
			"\n*   4. Displaying polynomials       *"
			"\n*   5. Clearing polynomials         *"
			"\n*   6. Quit                         *"
			"\n*************************************"
			"\nSelect an option (1, 2, 3, 4 ,5 or 6): ");
		scanf_s("%d", &option);
		switch (option) {
		case 1:
			printf("\nCreate Menu \n");
			creationMenu(&poly1, &poly2);
			break;
		case 2:
			if (poly1 && poly2 != NULL) {
				if (result != NULL)
					freePolyList(result);
				printf("\n\tCalling addPoly()\n");
				result = addPoly(poly1, poly2);
			} else if (poly1 != NULL) {
				printf("\n\tRight Polynomial is Missing!");
			} else if (poly2 != NULL) {
				printf("\n\tLeft Polynomial is Missing!");
			} else {
				printf("\n\tBoth Polynomials are Missing!");
			}
			break;
		case 3:
			if (poly1 && poly2 != NULL) {
				if (result != NULL)
					freePolyList(result);
				printf("\n\tCalling MultiplyPoly()\n");
				result = multiplyPoly(poly1, poly2);
			} else if (poly1 != NULL) {
				printf("\n\tRight Polynomial is Missing!");
			} else if (poly2 != NULL) {
				printf("\n\tLeft Polynomial is Missing!");
			} else {
				printf("\n\tBoth Polynomials are Missing!");
			}
			break;
		case 4:
			printf("\nDisplaying all polynomials");
			displayAllPoly(poly1, poly2, *result);
			break;
		case 5:
			printf("\nClearing Menu \n");
			clearingMenu(&poly1, &poly2, result);
			break;
		case 6:
			printf("\nHaving Fun! \n");
			break;
		default:
			printf("\nYou should not be in this class!");
		}
	} while (option != 6);

	freePolyList(&poly1);
	freePolyList(&poly2);
	freePolyList(result);
}
Esempio n. 9
0
void GeomShape::copy( GeomShape *other ) {
	clear();
	for( int i=0; i<other->polyCount(); i++ ) {
		addPoly( other->polys[i], other->holes[i] );
	}
}
Esempio n. 10
0
 void addPoly(QWidget *w, QValidator *v) {
    addPoly(qobject_cast<QLineEdit*>(w), v) ||
          addPoly(qobject_cast<QComboBox*>(w), v) ||
          (static_cast<void>(add(w, v)), true);
 }
Esempio n. 11
0
void SludgeFloorMaker::button1Press(int local_pointx, int local_pointy)
{
    	gboolean keepOn = TRUE;
		int i, xx, yy;

		mouseLoc1x = local_pointx;
		mouseLoc1y = local_pointy;

		xx = (local_pointx+x)*zmul;
		yy = (local_pointy-y)*zmul;
		
		switch (mode) {
		case 0: // Define floor border
			snapToClosest(&xx, &yy, getFloor());
			while (keepOn) {
				keepOn = FALSE;
				i = addVertex(xx, yy, getFloor());
				switch (i) {
					case 1:
						setFileChanged();
						return;
					case 0:
						errorBox("Can't add vertex", "Out of memory.");
						return;
						
					case 3:
						errorBox("Can't add vertex", "That vertex is already used in this polygon, but isn't the start point.");
						return;
						
					case 2:
						if ( askAQuestion("Can't add vertex", "Can't add another vertex as the floor is already complete... do you want to start a NEW polygon at this point?") ) { 
							setFloor( addPoly(getFloor()) );
							keepOn = TRUE;
							setFileChanged();
						} else {
							return;
						}
						break;
				}
			}
			break;
		case 1: // Move vertices
		case 4: // Split lines
		case 5: // Split segments
			if (! snapToClosest(&xx, &yy, getFloor()))
				return;
			
			selx1 = xx;
			sely1 = yy;
			selection = 1;
			awaitButton1Release = TRUE;
				
			break;
		case 2: // Remove vertices
			if (! snapToClosest(&xx, &yy, getFloor()))
				return;
			struct polyList * firstPoly = getFloor();
			
			killVertex(xx, yy, &firstPoly);
			setFloor(firstPoly);
			setFileChanged();
			break;
		}
		lit = snapToClosest(&xx, &yy, getFloor());
		litX = xx; litY = yy;
}