Design Pro

All generations.

time complexitySun, 12 Feb 2023

2OMath_Selection() Dim oRng As Range Dim oStory As Range Dim sText As String Dim oOMath As OMath Dim oOMathPara As OMathPara Set oStory = ActiveDocument.StoryRanges(wdMainTextStory) With oStory.Find .ClearFormatting .Text = "\$(.*?)\$" .Replacement.ClearFormatting .Format = False .MatchWildcards = True .Execute Do While .Found Set oRng = oStory.Duplicate oRng.Collapse wdCollapseEnd sText = .Text Set oOMath = oRng.OMaths.Add Set oOMathPara = oOMath.Functions.Add(oFunCluster) oOMathPara.Range.Text = sText ActiveDocument.OMaths(1).BuildUp .Execute Loop End With End Sub

O(n^2)

time complexitySun, 12 Feb 2023

def strassen(A, B): n = len(A) # Base case if n == 1: return A[0][0] * B[0][0] # Divide matrix A into quadrants a11 = A[:n//2][:n//2] a12 = A[:n//2][n//2:] a21 = A[n//2:][:n//2] a22 = A[n//2:][n//2:] # Divide matrix B into quadrants b11 = B[:n//2][:n//2] b12 = B[:n//2][n//2:] b21 = B[n//2:][:n//2] b22 = B[n//2:][n//2:] # Calculate p1 to p7 p1 = strassen(a11, subtract_matrices(b12, b22)) p2 = strassen(add_matrices(a11, a12), b22) p3 = strassen(add_matrices(a21, a22), b11) p4 = strassen(a22, subtract_matrices(b21, b11)) p5 = strassen(add_matrices(a11, a22), add_matrices(b11, b22)) p6 = strassen(subtract_matrices(a12, a22), add_matrices(b21, b22)) p7 = strassen(subtract_matrices(a11, a21), add_matrices(b11, b12)) # Calculate c21, c21, c11, and c22 c12 = add_matrices(p3, p5) c21 = add_matrices(p2, p4) c11 = subtract_matrices(subtract_matrices(add_matrices(p5, p4), p2), p6) c22 = subtract_matrices(subtract_matrices(add_matrices(p1, p2), p3), p7) # Group the results in a single matrix C = [[0 for j in range(n)] for i in range(n)] C[:n//2][:n//2] = c11 C[:n//2][n//2:] = c12 C[n//2:][:n//2] = c21 C[n//2:][n//2:] = c22 return C

O(n)

fix invalid codeSun, 12 Feb 2023

Acad::ErrorStatus CustomLine::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es; // Call the parent class es = AcDbEntity::dwgOutFields(pFiler); if (es != Acad::eOk) return es; // Write data members if ((es = pFiler->writeItem(mStartPoint)) != Acad::eOk) return es; if ((es = pFiler->writeItem(mEndPoint)) != Acad::eOk) return es; if ((es = pFiler->writeItem(mLength)) != Acad::eOk) return es; if ((es = pFiler->writeString(mText)) != Acad::eOk) return es; return Acad::eOk; } // List the data in the entity /* * This function lists the data in the entity */ void CustomLine::list() const { assertReadEnabled(); AcDbEntity::list(); // Print text at midpoint of line AcGePoint3d midPoint = (mStartPoint + mEndPoint) / 2; ads_printf("\nText = %s\n", mText); ads_printf("Mid Point = (%lf, %lf, %lf)\n", midPoint.x, midPoint.y, midPoint.z); }

- [ ] add a test - [ ] add a demo - [ ] add a blog - [ ] add a video

fix invalid codeSun, 12 Feb 2023

// include header files for AutoCAD #include "acdb.h" #include "dbapserv.h" #include "dbdict.h" #include "dbmain.h" #include "dbmstyle.h" #include "dbsymtb.h" #include "dbents.h" #include "dbidmap.h" #include "rxobject.h" #include "rxregsvc.h" // Custom line entity /* * This class defines the custom line entity which can be used in Autocad */ class CustomLine : public AcDbEntity { public: // Constructor /* * This constructor initializes the class */ ACRX_DECLARE_MEMBERS(CustomLine); CustomLine(); /* * This destructor deallocates the memory */ virtual ~CustomLine(); /* * This function reads data from a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler); /* * This function writes data to a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const; /* * This function lists the data in the entity */ virtual void list() const; // Data members /* * Character pointer to store text */ char* mText; /* * Integer to store length of text */ int mLength; /* * Point to store start point of line */ AcGePoint3d mStartPoint; /* * Point to store end point of line */ AcGePoint3d mEndPoint; }; // Register the custom line entity ACDB_REGISTER_OBJECT_ENTRY_AUTO(CustomLine) // Constructor /* * This constructor initializes the class */ CustomLine::CustomLine() { mText = nullptr; mLength = 0; } // Destructor /* * This destructor deallocates the memory */ CustomLine::~CustomLine() { if (mText) delete[] mText; } // Read data from a DWG file /* * This function reads data from a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ Acad::ErrorStatus CustomLine::dwgInFields(AcDbDwgFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es; // Call the parent class es = AcDbEntity::dwgInFields(pFiler); if (es != Acad::eOk) return es; // Read data members if ((es = pFiler->readItem(&mStartPoint)) != Acad::eOk) return es; if ((es = pFiler->readItem(&mEndPoint)) != Acad::eOk) return es; if ((es = pFiler->readItem(&mLength)) != Acad::eOk) return es; // Allocate memory for text mText = new char[mLength + 1]; // Read text from DWG file if ((es = pFiler->readString(mText, mLength)) != Acad::eOk) return es; return Acad::eOk; } // Write data to a DWG file /* * This function writes data to a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ Acad::ErrorStatus CustomLine::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es; // Call the parent class es = AcDbEntity::dwgOutFields(pFiler); if (es != Acad::eOk) return es; // Write data members if ((es = pFiler->writeItem(mStartPoint)) != Acad::eOk) return es; if ((es = pFiler->writeItem(mEndPoint)) != Acad::eOk) return es; if ((es = pFiler->writeItem(mLength)) != Acad::eOk) return es; if ((es = pFiler->writeString(mText)) != Acad::eOk) return es; return Acad::eOk; } // List the data in the entity /* * This function lists the data in the entity */ void CustomLine::list() const { assertReadEnabled(); AcDbEntity::list(); // Print text at midpoint of line AcGePoint3d midPoint = (mStartPoint + mEndPoint) / 2; ads_printf("\nText = %s\n", mText); ads_printf("Mid Point = (%lf, %lf, %lf)\n", midPoint.x, midPoint.y, midPoint.z); }

fix invalid codeSun, 12 Feb 2023

class CustomLine : public AcDbEntity { public: // Constructor /* * This constructor initializes the class */ ACRX_DECLARE_MEMBERS(CustomLine); CustomLine(); /* * This destructor deallocates the memory */ virtual ~CustomLine(); /* * This function reads data from a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler); /* * This function writes data to a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const; /* * This function lists the data in the entity */ virtual void list() const; // Data members /* * Character pointer to store text */ char* mText; /* * Integer to store length of text */ int mLength; /* * Point to store start point of line */ AcGePoint3d mStartPoint; /* * Point to store end point of line */ AcGePoint3d mEndPoint; }; // Register the custom line entity ACDB_REGISTER_OBJECT_ENTRY_AUTO(CustomLine) // Constructor /* * This constructor initializes the class */ CustomLine::CustomLine() { mText = nullptr; mLength = 0; } // Destructor /* * This destructor deallocates the memory */ CustomLine::~CustomLine() { if (mText) delete[] mText; } // Read data from a DWG file /* * This function reads data from a DWG file * @param pFiler : pointer to the DWG file * @return : Error status */ Acad::ErrorStatus CustomLine::dwgInFields(AcDbDwgFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es; // Call the parent class es = AcDbEntity::dwgInFields(pFiler); if (es != Acad::eOk) return es; // Read data members if ((es = pFiler->readItem(&mStartPoint)) != Acad::eOk) return es; if ((es = pFiler->readItem(&mEndPoint)) != Acad::eOk) return es; if ((es = pFiler->readItem(&mLength)) != Acad::eOk) return es; // Allocate memory for text mText = new char[mLength + 1]; // Read text from DWG file if ((es = pFiler->readString(mText, mLength)) != Acad::eOk) return es; return Acad::eOk; }

Questions about programming?Chat with your personal AI assistant