這份作業主要由國立臺北科技大學 109 資工系黃漢軒所命題,若有任何的問題,非常歡迎使用以下的聯絡方式提問:
Email: t109590031@ntut.org.tw/MS Teams: 黃漢軒/Telegram: @xuan910625
⚠️ Due: 11:59 p.m., 19 / 12 / 2023 ⚠️
這份作業主要統整前面幾次的課程內容,並製成一份模擬期末考。
請清掉前一次的作業,確認提交是否符合以下的檔案架構,否則無法進行評分。
在這份功課中,我們嘗試描述一個繪圖系統(GraphicSystem)。
我們想要實作一個繪圖系統,在這個繪圖系統中,你可以畫圓形也可以畫正方形。
對於每一個圖形,我們有所謂的碰撞箱(BoxContainer),你可以把它想成一個形狀可以被矩形包起來,方便我們計算疊加,如下圖的黑線。
你將設計一個繪圖系統,能夠支援在一張無限大的畫布上畫上圖形,我們期望這個繪圖系統具有以下的功能:
你也同時需要處理以下的情況。
Square
、Circle
兩種形狀Circle
Circle(Location location, int radius)
location
為圓心,radius
為圓半徑。Location GetCenterOfCircle()
Location
int GetRadius()
Square
Square(Location location, int edge)
location
為方形左上角,edge
為方形的邊長。int GetEdge()
IDrawable
介面上double GetArea()
bool IsInShape(Point point)
ShapeHelper.hpp
裡面的一些 function 來幫助你完成。bool IsOverlap(std::shared_ptr<IDrawable> drawable)
ShapeHelper.hpp
裡面的一些 function 來幫助你完成。Point GetLeftTopPoint()
BoxContainer GetBoxContainer()
BoxContainer.hpp
,其中碰撞箱中的 x 與 y 成員為碰撞箱左上角的點。GraphicSystem
GraphicSystem(std::vector<std::shared_ptr<IDrawable>> drawables)
GraphicSystem
中。std::logic_error
例外。void AddShape(std::shared_ptr<IDrawable> drawable)
GraphicSystem
的動態陣列尾端。std::logic_error
例外。std::shared_ptr<IDrawable> GetShape(unsigned int index)
i
個圖形。i
超出陣列長度,你需要拋出例外。std::shared_ptr<IDrawable> GetShape(unsigned int x, unsigned int y)
double CalculateTotalArea()
int Size()
std::logic_error
ShapeHelper.h
或 ShapeHelper.cpp
,只需理解如何使用。nullptr
,這個特殊的指標可用於指向不存在的東西。ASSERT_EQ
來測試不會有精度誤差的值(例如:整數、字串等)ASSERT_NEAR
來測試具有精度的值ASSERT_THROW
來測試該函數會不會拋出例外ASSERT_FALSE
來測試該值是否為 false
bin
資料夾至專案上。
/bin
資料夾至專案庫,編譯結果不應該上傳至專案庫上,若在助教確認功課評分時 /bin
資料夾存在在專案庫中,扣除作業總分 5 分。debugger
工具來進行除錯,有利於尋找漏洞與理解漏洞為何會發生。