Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: chosing "small 2d graphics library" interface Date: Thu, 02 Apr 2015 10:47:36 -0700 Organization: None to speak of Lines: 62 Message-ID: <87384iifrb.fsf@kst-u.example.com> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="24216"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8nB42nslgjb26ETApPzsz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:UpST+xgX3igeav5ir7V/TYaquZo= sha1:spAWMJIPGpM9OSha/ktwRMja/R0= Xref: csiph.com comp.lang.c:59480 Richard Heathfield writes: [...] > #define NUM_DIMENSIONS 2 > > struct point > { > double dimension[NUM_DIMENSIONS]; > }; > > For notational convenience, let's alias that type: > > typedef struct point Point; [...] > struct edge > { > Point vertex[2]; > }; > > and again, let's alias the type: > > typedef struct edge Edge; > > A "face" is a series of edges that, taken together, mark off a region > of our universe. A face can have many edges, but it turns out to be > convenient to restrict ourselves to three, forming a triangle. Why is > this convenient? Well, firstly, we can use triangles to build up any > other shape we want, so it doesn't cost us much, but more importantly > we can specify exactly 3 of something really easily, whereas > specifying n of anything requires us to play games with dynamic > allocation. We will have to do that anyway at some time, but there's > no need to have that level of complexity at this primitive a > level. So: > > struct face > { > Edge edge[3]; > }; > > typedef struct face Face; [...] With this representation, a Face (representing a triangle) stores each vertex point twice. It can also represent a triangle whose edges are disconnected, which I presume would be invalid. I suggest: struct face { Point vertex[3]; }; And perhaps "struct triangle" would be clearer than "struct face", since you've already decided (reasonably IMHO) that all faces are triangles. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"