dtriangulationDoc.cpp
资源名称:package.rar [点击查看]
上传用户:chinasdcnc
上传日期:2022-07-02
资源大小:2702k
文件大小:2k
源码类别:
分形几何
开发平台:
Visual C++
- // dtriangulationDoc.cpp : CdtriangulationDoc 类的实现
- //
- #include "stdafx.h"
- #include "dtriangulation.h"
- #include "dtriangulationDoc.h"
- #include <cassert>
- #include <stdio.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CdtriangulationDoc
- IMPLEMENT_DYNCREATE(CdtriangulationDoc, CDocument)
- BEGIN_MESSAGE_MAP(CdtriangulationDoc, CDocument)
- END_MESSAGE_MAP()
- // CdtriangulationDoc 构造/析构
- CdtriangulationDoc::CdtriangulationDoc()
- {
- nPoints = 0;
- points = NULL;
- }
- CdtriangulationDoc::~CdtriangulationDoc()
- {
- if (points != NULL)
- delete[] points;
- myDT.destroy();
- }
- BOOL CdtriangulationDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: 在此添加重新初始化代码
- // (SDI 文档将重用该文档)
- return TRUE;
- }
- // CdtriangulationDoc 序列化
- void CdtriangulationDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: 在此添加存储代码
- }
- else
- {
- // TODO: 在此添加加载代码
- }
- }
- Point2d* CdtriangulationDoc::point(int pos) const
- {
- assert(pos >= 0 && pos < nPoints);
- return (points + pos);
- }
- bool CdtriangulationDoc::load(const char* filename)
- {
- FILE* fp;
- fp = fopen(filename, "r");
- if (fp == NULL)
- return false;
- myDT.destroy();
- delete[] points;
- fscanf_s(fp, "%d", &nPoints);
- if (nPoints <= 1)
- {
- points = NULL;
- nPoints = 0;
- fclose(fp);
- return false;
- }
- points = new Point2d[nPoints];
- for (int i = 0; i < nPoints; ++i)
- {
- double x;
- double y;
- fscanf_s(fp, "%lf", &x);
- fscanf_s(fp, "%lf", &y);
- points[i].x = x;
- points[i].y = y;
- }
- fclose(fp);
- return true;
- }
- bool CdtriangulationDoc::save(const char* filename)
- {
- FILE* fp;
- fp = fopen(filename, "w");
- if (fp == NULL)
- return false;
- fprintf(fp, "%dn", nPoints);
- for (int i = 0; i < nPoints; ++i)
- {
- fprintf(fp, "%.15f", points[i].x);
- fprintf(fp, " ");
- fprintf(fp, "%.15f", points[i].y);
- fprintf(fp, "n");
- }
- fclose(fp);
- return true;
- }
- // CdtriangulationDoc 诊断
- #ifdef _DEBUG
- void CdtriangulationDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CdtriangulationDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- // CdtriangulationDoc 命令