public void OnDeserialize() { GetEdgeCoordinates(); for (int i = 0; i < SourceFigures.Size(); i++) { Primitives.Add(SourceFigures.Item(i).Copy()); } GetRelativeCoords(); }
private void GetEdgeCoordinates() { if (SourceFigures.Size() > 0) { MinX = SourceFigures.Item(0).X1; for (int i = 0; i < SourceFigures.Size(); i++) { if (SourceFigures.Item(i).X1 < MinX) { MinX = SourceFigures.Item(i).X1; } if (SourceFigures.Item(i).X2 < MinX) { MinX = SourceFigures.Item(i).X2; } } MinY = SourceFigures.Item(0).Y1; for (int i = 0; i < SourceFigures.Size(); i++) { if (SourceFigures.Item(i).Y1 < MinY) { MinY = SourceFigures.Item(i).Y1; } if (SourceFigures.Item(i).Y2 < MinY) { MinY = SourceFigures.Item(i).Y2; } } MaxX = SourceFigures.Item(0).X2; for (int i = 0; i < SourceFigures.Size(); i++) { if (SourceFigures.Item(i).X2 > MaxX) { MaxX = SourceFigures.Item(i).X2; } if (SourceFigures.Item(i).X1 > MaxX) { MaxX = SourceFigures.Item(i).X1; } } MaxY = SourceFigures.Item(0).Y2; for (int i = 0; i < SourceFigures.Size(); i++) { if (SourceFigures.Item(i).Y2 > MaxY) { MaxY = SourceFigures.Item(i).Y2; } if (SourceFigures.Item(i).Y1 > MaxY) { MaxY = SourceFigures.Item(i).Y1; } } } }
private void GetRelativeCoords() { for (int i = 0; i < Primitives.Size(); i++) { Primitives.Item(i).X1 = X1 + (SourceFigures.Item(i).X1 - MinX) * (X2 - X1) / (MaxX - MinX); Primitives.Item(i).Y1 = Y1 + (SourceFigures.Item(i).Y1 - MinY) * (Y2 - Y1) / (MaxY - MinY); Primitives.Item(i).X2 = X1 + (SourceFigures.Item(i).X2 - MinX) * (X2 - X1) / (MaxX - MinX); Primitives.Item(i).Y2 = Y1 + (SourceFigures.Item(i).Y2 - MinY) * (Y2 - Y1) / (MaxY - MinY); } }