src/linetypes/circularprimitive.cpp

changeset 1399
f52ea4078f5d
parent 1398
1c70d3447d20
child 1400
ae83213bdd63
--- a/src/linetypes/circularprimitive.cpp	Sun Jun 10 16:50:14 2018 +0300
+++ b/src/linetypes/circularprimitive.cpp	Sun Jun 10 17:17:42 2018 +0300
@@ -17,18 +17,14 @@
 
 	simplify(numerator, denominator);
 
-	switch (m_type)
+	// Ensure that the denominator is at least 4, expand if necessary
+	if (denominator < 4)
 	{
-	case PrimitiveModel::Cylinder:
-		return format("%1%2-%3cyli.dat", prefix, numerator, denominator);
+		numerator = static_cast<int>(round(numerator * 4.0 / denominator));
+		denominator = 4;
+	}
 
-	case PrimitiveModel::Circle:
-		return format("%1%2-%3edge.dat", prefix, numerator, denominator);
-
-	default:
-		Q_ASSERT(false);
-		return "";
-	}
+	return format("%1%2-%3%4.dat", prefix, numerator, denominator, stem());
 }
 
 LDCircularPrimitive::LDCircularPrimitive(
@@ -70,7 +66,10 @@
 	}
 }
 
-bool LDCircularPrimitive::isRasterizable() const { return true; }
+bool LDCircularPrimitive::isRasterizable() const
+{
+	return true;
+}
 
 void LDCircularPrimitive::rasterize(
 	DocumentManager* context,
@@ -137,6 +136,27 @@
 	primitive.generateBody(model);
 }
 
+QString LDCircularPrimitive::stem() const
+{
+	switch (m_type)
+	{
+	case PrimitiveModel::Cylinder:
+		return "cyli";
+
+	case PrimitiveModel::Circle:
+		return "edge";
+
+	case PrimitiveModel::Disc:
+		return "disc";
+
+	case PrimitiveModel::DiscNegative:
+		return "ndis";
+
+	default:
+		throw std::logic_error("Bad primitive type to LDCircularPrimitive");
+	}
+}
+
 QString LDCircularPrimitive::objectListText() const
 {
 	QString result = format(

mercurial