// *************************************************************************
//
// Graphisoft Geometry Library의
// InitPolygon2Ddata와 ValidatePolygon2Ddata를 사용하는 예제
// (c) Graphisoft 2003
//
// *************************************************************************
// *************************************************************************
#include "BM.hpp"
#include "Polygon2DData.h"
// 단순성을 위해 오류 검사를 누락하였습니다.
void Example01 ()
{
Geometry::Polygon2DData polygon;
// (호를 가지고) {(10.0,10.0); (20.0, 20.0)} 직사각형을 초기화함
long defaultVertexInfo = 0;
long defaultInhEdgeInfo = 0;
long defaultUniqEdgeInfo = 0;
long defaultContourInfo = 0;
long defaultUniqPolygonInfo = 0;
Geometry::InitPolygon2DData (&polygon,
sizeof (long), reinterpret_cast<GSPtr> (&defaultVertexInfo), // 정점 정보
sizeof (long), reinterpret_cast<GSPtr> (&defaultInhEdgeInfo), // 모서리 정보
sizeof (long), reinterpret_cast<GSPtr> (&defaultUniqEdgeInfo), // 모서리 정보
sizeof (long), reinterpret_cast<GSPtr> (&defaultContourInfo), // 외곽 정보
sizeof (long),
sizeof (long), reinterpret_cast<GSPtr> (&defaultUniqPolygonInfo)); // 폴리곤 정보
// 1개의 외곽과 1개의 구멍을 갖고 있음
polygon.nContours = 2;
polygon.contourEnds = reinterpret_cast<UIndex**> (BMhAll (3 * sizeof (UIndex)));
polygon.contourInfos = BMhAll (3 * sizeof (long));
(*polygon.contourEnds)[0] = 0; // 사용하지 않음, 0이어야 함
reinterpret_cast<long*>(*polygon.contourInfos)[0] = 'C-uu';
(*polygon.contourEnds)[1] = 5; // 1번째 (메인) 외곽의 마지막 정점의 인덱스
reinterpret_cast<long*>(*polygon.contourInfos)[1] = 'C-01';
(*polygon.contourEnds)[2] = 9; // 2번째 외곽(1번째 구멍)의 마지막 정점의 인덱스
reinterpret_cast<long*>(*polygon.contourInfos)[2] = 'C-02';
polygon.nVertices = 9; // 외곽의 처음 정점과 마지막 정점은 겹침 (그러나 사용하지 않는 것은 세지 말 것)
polygon.vertices = reinterpret_cast<Coord**> (BMhAll (10 * sizeof (Coord)));
polygon.vertexInfos = BMhAll (10 * sizeof (long));
polygon.inhEdgeInfos = BMhAll (10 * sizeof (long));
polygon.uniqEdgeInfos = BMhAll (10 * sizeof (long));
// 고의로 역방향
(*polygon.vertices)[0] = Geometry::SetCoord ( 0.0, 0.0); // 사용하지 않음, 0이어야 함
reinterpret_cast<long*>(*polygon.vertexInfos)[0] = 'V-uu';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[0] = 'I-uu';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[0] = 'U-uu';
(*polygon.vertices)[1] = Geometry::SetCoord (10.0, 10.0);
reinterpret_cast<long*>(*polygon.vertexInfos)[1] = 'V-01';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[1] = 'I-01';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[1] = 'U-01';
(*polygon.vertices)[2] = Geometry::SetCoord (10.0, 20.0);
reinterpret_cast<long*>(*polygon.vertexInfos)[2] = 'V-02';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[2] = 'I-02';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[2] = 'U-02';
(*polygon.vertices)[3] = Geometry::SetCoord (20.0, 20.0);
reinterpret_cast<long*>(*polygon.vertexInfos)[3] = 'V-03';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[3] = 'I-03';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[3] = 'U-03';
(*polygon.vertices)[4] = Geometry::SetCoord (20.0, 10.0);
reinterpret_cast<long*>(*polygon.vertexInfos)[4] = 'V-04';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[4] = 'I-04';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[4] = 'U-04';
(*polygon.vertices)[5] = Geometry::SetCoord (10.0, 10.0); // 메인 외곽의 1번째 정점과 같음
reinterpret_cast<long*>(*polygon.vertexInfos)[5] = 'V-05';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[5] = 'I-05';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[5] = 'U-05';
(*polygon.vertices)[6] = Geometry::SetCoord (15.0, 15.0); // 구멍의 1번째 정점
reinterpret_cast<long*>(*polygon.vertexInfos)[6] = 'V-06';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[6] = 'I-06';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[6] = 'U-06';
(*polygon.vertices)[7] = Geometry::SetCoord (18.0, 15.0);
reinterpret_cast<long*>(*polygon.vertexInfos)[7] = 'V-07';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[7] = 'I-07';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[7] = 'U-07';
(*polygon.vertices)[8] = Geometry::SetCoord (15.0, 18.0);
reinterpret_cast<long*>(*polygon.vertexInfos)[8] = 'V-08';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[8] = 'I-08';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[8] = 'U-08';
(*polygon.vertices)[9] = Geometry::SetCoord (15.0, 15.0); // 구멍의 1번째 정점과 같음
reinterpret_cast<long*>(*polygon.vertexInfos)[9] = 'V-09';
reinterpret_cast<long*>(*polygon.inhEdgeInfos)[9] = 'I-09';
reinterpret_cast<long*>(*polygon.uniqEdgeInfos)[9] = 'U-09';
// 1번째와 2번째 정점 사이에 호를 추가함 (1번째 모서리)
polygon.nArcs = 1;
polygon.arcs = reinterpret_cast<PolyArcRec**> (BMhAll (2 * sizeof (PolyArcRec)));
(*polygon.arcs)[0].arcAngle = 0.0; // 사용하지 않음, 0이어야 함
(*polygon.arcs)[0].begIndex = 0;
(*polygon.arcs)[0].endIndex = 0;
(*polygon.arcs)[1].arcAngle = 0.4; // radian 단위의 뷰 각도
(*polygon.arcs)[1].begIndex = 1;
(*polygon.arcs)[1].endIndex = 2; // 다음 정점이어야 함
Geometry::ValidatePolygon2DData (&polygon);
// 안전을 위해 확인함
Geometry::CheckPolygon2DDataIntegrity (polygon);
// TODO:
// 폴리곤으로 아무 작업을 수행함
// 청소
Geometry::FreePolygon2DData (&polygon);
}