System.Drawing性能与“自己动手”相关几何类 [英] System.Drawing performance vs. "roll your own" geometry classes
问题描述
我一直在制作关于平铺引擎和程序地图生成(地牢/ roguelike)地图/迷宫的教程和示例,我即将使用C#4.0和MonoGame开始我自己的项目。
我想知道是否有更好的信息是否更好地使用由System.Drawing(Rectangle,Point,PointF等)用于描述我的地图(2d数组,tileset,用于提供A *算法的可通过/不可通过的地图)或者如果通过编写自己的基本几何模型(自定义矩形,可以获得更好的性能),矢量,点类等)。我在这里想像Point.GetNeighbours或Rectangle.Inflate,.Offset等方法,例如点和区域的基本几何操作。
一般意见是什么这个 - 使用System.Drawing或滚动我自己的?
对这个相当开放的问题表示歉意!
Glen205 ......
我使用内置类,因为我认为创建样板低级几何对象没有任何好处。但是您可以添加一些扩展方法(GetNeigbours或您想要的)来简化编码。如果您现在不关于扩展方法,请参阅: http://msdn.microsoft.com/en-us /library/bb383977.aspx [ ^
Hi,
I've been working through tutorials and samples on tile engines and procedural map generation(dungeon / roguelike) maps/mazes, and am about to embark on a project of my own, using C#4.0 and MonoGame.
I'm wondering whether there is any information on whether it's better to use the classes provided by System.Drawing (Rectangle, Point, PointF etc) for describing my maps (2d arrays, tilesets, passable/impassable maps for feeding an A* algorithm) or if better performance can be gained by writing your own basic geometry model (custom rectangle, vector, point classes etc). I'm thinking methods like Point.GetNeighbours, or Rectangle.Inflate, .Offset etc here, e.g.basic geometric operations on points and regions.
What's the general opinion on this - Use System.Drawing or "roll my own"?
Apologies for the rather open-ended question!
Glen205...
I'd use the built in classes, cause I see no benefit in creating boilerplate "low level" geometry objects. But you may add some extension methods (GetNeigbours or what you want) to ease your coding. If you don't now about Extension methods see: http://msdn.microsoft.com/en-us/library/bb383977.aspx[^]
这篇关于System.Drawing性能与“自己动手”相关几何类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!