Changeset 1032 for cpp/frams/model/geometry/geometryutils.cpp
- Timestamp:
- 11/27/20 20:54:50 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/geometry/geometryutils.cpp
r1026 r1032 1 1 // This file is a part of Framsticks SDK. http://www.framsticks.com/ 2 // Copyright (C) 1999-20 15Maciej Komosinski and Szymon Ulatowski.2 // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski. 3 3 // See LICENSE.txt for details. 4 4 … … 369 369 return M_PI * ((3 * (a+b)) - sqrt((3*a + b) * (a + 3*b))); 370 370 } 371 372 double GeometryUtils::calculateSolidVolume(Part * part) 373 { 374 double radiiProduct = part->scale.x * part->scale.y * part->scale.z; 375 switch (part->shape) 376 { 377 case Part::Shape::SHAPE_CUBOID: 378 return 8.0 * radiiProduct; 379 case Part::Shape::SHAPE_CYLINDER: 380 return 2.0 * M_PI * radiiProduct; 381 case Part::Shape::SHAPE_ELLIPSOID: 382 return (4.0 / 3.0) * M_PI * radiiProduct; 383 default: 384 logMessage("GeometryUtils", "calculateSolidVolume", LOG_ERROR, "Unsupported part shape"); 385 return -1; 386 } 387 } 388 389 bool GeometryUtils::isSolidPartScaleValid(const Part::Shape &partShape, const Pt3D &scale) 390 { 391 Part *tmpPart = new Part(partShape); 392 tmpPart->scale = scale; 393 double volume = GeometryUtils::calculateSolidVolume(tmpPart); 394 395 Part_MinMaxDef minP = Model::getMinPart(); 396 Part_MinMaxDef maxP = Model::getMaxPart(); 397 398 if (volume > maxP.volume || minP.volume > volume) 399 return false; 400 if (scale.x < minP.scale.x || scale.y < minP.scale.y || scale.z < minP.scale.z) 401 return false; 402 if (scale.x > maxP.scale.x || scale.y > maxP.scale.y || scale.z > maxP.scale.z) 403 return false; 404 405 if (partShape == Part::Shape::SHAPE_ELLIPSOID && scale.maxComponentValue() != scale.minComponentValue()) // When any radius has a different value than the others 406 return false; 407 if (partShape == Part::Shape::SHAPE_CYLINDER && scale.y != scale.z) // If base radii have different values 408 return false; 409 return true; 410 }
Note: See TracChangeset
for help on using the changeset viewer.