void Triangle::SetPoints(const Point& A, const Point& B, const Point& C) { _pointA = A.GetPosition(); _pointB = B.GetPosition(); _pointC = C.GetPosition(); CalculateDimensions(); CalculateArea(); }
A2DE_BEGIN Sector::Sector(double x, double y, double startAngle, double endAngle, double radius, const ALLEGRO_COLOR& color, bool filled) : Shape(x, y, (radius < 0.0 ? 0.0 : radius * 2), (radius < 0.0 ? 0.0 : radius * 2), color, filled), _arc(x, y, startAngle, endAngle, (radius < 0.0 ? 0.0 : radius), color, filled) { _type = Shape::SHAPETYPE_SECTOR; SetAngles(_arc.GetStartAngle(), _arc.GetEndAngle()); CalculateArea(); }
Rectangle& Rectangle::operator=(const Rectangle& rhs) { if(this == &rhs) return *this; Shape::operator=(rhs); CalculateArea(); return *this; }
Triangle::Triangle(const Vector2D& pointOne, const Vector2D& pointTwo, const Vector2D& pointThree, const a2de::Color& color, bool filled) : Shape(), _pointA(pointOne), _pointB(pointTwo), _pointC(pointThree) { if(_pointA == _pointB || _pointA == _pointC || _pointB == _pointC || _pointA == _pointC) throw Exception("Points do not describe a triangle."); _type = Shape::SHAPETYPE_TRIANGLE; _color = color; _filled = filled; CalculateDimensions(); CalculateArea(); }
Sector& Sector::operator=(const Sector& rhs) { if(this == &rhs) return *this; Shape::operator=(rhs); SetAngles(rhs._arc.GetStartAngle(), rhs._arc.GetEndAngle()); CalculateArea(); return *this; }
Triangle& Triangle::operator=(const Triangle& rhs) { if(this == &rhs) return *this; Shape::operator=(rhs); CalculateDimensions(); CalculateArea(); return *this; }
/* ***************************************************************************** **函 数 名:Uint8 GetCycle(Uint8 *p,Uint8 n) **功能描述:算周期 **输 入:Uint8 *p,Uint8 n **输 出: ***************************************************************************** */ Uint8 GetCycle(Uint8 *p,Uint8 n) //算周期 { Uint8 xdata i,j,account,condition,tempMin,posMin,posMax; Uint16 xdata tempMax; Uint8 xdata cycle = 0; condition =(Uint16)(SerialMore(p,n)+SerialLess(p,n))*4/5; for(i=MIN_POINT;i<=MAX_POINT;i++) { CalculateArea(p,i); account=FindLeastValue(GatDat->Area,TOTAL-i); while(account>=3) { tempMin = 0xff; posMin = 0; for(j=0;j<(account-1);j++) { if(abs(GatDat->Num[j+1]-GatDat->Num[j])<tempMin) { tempMin = abs(GatDat->Num[j+1]-GatDat->Num[j]); posMin = j; } } if(tempMin<condition) { if(GatDat->Area[GatDat->Num[posMin]] > GatDat->Area[GatDat->Num[posMin+1]]) DeleteArray(account,posMin); else DeleteArray(account,posMin+1); account --; } else { cycle=DistanceEqu(account); if(cycle) return cycle; else { tempMax = 0; posMax = 0xff; for(j=0;j<account;j++) { if(GatDat->Area[GatDat->Num[j]]>=tempMax) { tempMax = GatDat->Area[GatDat->Num[j]]; posMax = j; } } DeleteArray(account,posMax); account --; } } } } return 0; }
A2DE_BEGIN Triangle::Triangle(double x1, double y1, double x2, double y2, double x3, double y3, const a2de::Color& color, bool filled) : Shape(), _pointA(x1, y1), _pointB(x2, y2), _pointC(x3, y3) { if(_pointA == _pointB || _pointA == _pointC || _pointB == _pointC || _pointA == _pointC) throw Exception("Points do not describe a triangle."); _type = Shape::SHAPETYPE_TRIANGLE; _color = color; _filled = filled; CalculateDimensions(); CalculateArea(); }
void Sector::SetAngles(double startAngle, double endAngle) { _arc.SetAngles(startAngle, endAngle); CalculateArea(); }
Sector::Sector(const Sector& sector) : Shape(sector), _arc(sector._arc) { _type = Shape::SHAPETYPE_SECTOR; SetAngles(sector._arc.GetStartAngle(), sector._arc.GetEndAngle()); CalculateArea(); }
Sector::Sector(const Vector2D& position, double startAngle, double endAngle, double radius, const ALLEGRO_COLOR& color, bool filled) : Shape(position, (radius < 0.0 ? 0.0 : radius * 2), (radius < 0.0 ? 0.0 : radius * 2), color, filled), _arc(position, startAngle, endAngle, (radius < 0.0 ? 0.0 : radius), color, filled) { _type = Shape::SHAPETYPE_SECTOR; SetAngles(_arc.GetStartAngle(), _arc.GetEndAngle()); CalculateArea(); }
void Rectangle::SetHalfExtents(const Vector2D& half_extents) { Shape::SetHalfExtents(half_extents); CalculateArea(); CalculateVerts(); }
Rectangle::Rectangle(const Rectangle& rect) : Shape(rect) { CalculateArea(); }
Triangle::Triangle(const Triangle& triangle) : Shape(triangle), _pointA(triangle.GetPointA()), _pointB(triangle.GetPointB()), _pointC(triangle.GetPointC()) { _type = Shape::SHAPETYPE_TRIANGLE; CalculateDimensions(); CalculateArea(); }
int main (void) { int length = 0; int width = 0; int i = 0; int rectangleList[NUMRECTANGLES][NUMATTRIBUTES]; PrintGreeting(); /* Get input from user */ printf("Please enter the length and width of "); printf("%d", NUMRECTANGLES); printf(" rectangles\n"); printf("in the form of length, width (number comma number)\n"); printf("- one pair on each line\n\n"); /* Read in the length and width values for each rectangle */ /* Store each value in an element of a 2-dimensional array */ for (i = 0; i < NUMRECTANGLES; i++) { /* Read length and width and store in array */ scanf ("%d,%d", &length, &width); rectangleList[i][LENGTH] = length; rectangleList[i][WIDTH] = width; /******************** STEP 3 *********************** * Write a couple lines of code to calculate the * * perimeter and area of the current rectangle, * * and store the perimeter and area in elements 2 * * and 3 of the second dimension of the array. * * * * Use the CalculatePerimeter and CalculateArea * * functions from geometry.h * ***************************************************/ rectangleList[i][PERIMETER] = CalculatePerimeter(length, width); rectangleList[i][AREA] = CalculateArea(length, width); } printf("\nThe properties of the rectangle(s) are:\n\n"); /* The header for a results table */ PrintTableHeader(); /* Print out the length, width, perimeter and area of each rectangle */ /* Print one per line */ /******************* STEP 2 *************************** * Uncomment the following statement to call the * * function which actually print out a table based on * * the values in our array. * * * * Note that we are PASSING the array here! * *****************************************************/ PrintRectangleTable( rectangleList, NUMRECTANGLES ); printf("\n"); return 0; }