Article View: comp.lang.c
Article #2229Re: weird symplification
From: fir
Date: Sat, 05 Dec 2026 07:56
Date: Sat, 05 Dec 2026 07:56
77 lines
4023 bytes
4023 bytes
Tristan Wibberley pisze:
> On 03/12/2026 13:38, fir wrote:
>> this one is a code to call frustrum culling on asteroids
>>
>> if(DoFrustumCulling())
>> {
>> if(SphereInCameraFrustum(bag[i].p.pos,bag[i].radius))
>> {
>> DrawAsteroidLib3DPos(0,&bag[i].p,bag[i].scale);
>> if(ctrl_w_toggler)
>> DrawWireSphere(bag[i].p.pos,bag[i].radius,0x00cfcf,12,12,20);
>> }
>> }
>> else
>> {
>> DrawAsteroidLib3DPos(0,&bag[i].p,bag[i].scale);
>> if(ctrl_w_toggler)
>> DrawWireSphere(bag[i].p.pos,bag[i].radius,0x00cfcf,12,12,20);
>>
>> }
>>
>> ai sais its thhe same as
>>
>> if(!DoFrustumCulling() ||
>> SphereInCameraFrustum(bag[i].p.pos,bag[i].radius))
>> {
>> DrawAsteroidLib3DPos(0,&bag[i].p,bag[i].scale);
>> if(ctrl_w_toggler)
>> DrawWireSphere(bag[i].p.pos,bag[i].radius,0x00cfcf,12,12,20);
>> }
>>
>> i gove it as a criptic example
>>
>> must say i still have a serious problem with this ! && || expersions
>> they are not easy to read at all (esp in this simplified form esp as
>> those operators precedences are as many say possibly not quite fit)
>
>
> && and || are conditional sequencing operators more than they are
> logical ones, in your example that is very clear. It's very idiomatic C
> but requires some special experience as a C coder to naturally read.
>
> I might have done (here without having checked I haven't made some dumb
> mistake because I mean just to draft the expressive concept):
>
> const register int cull = DoFrustumCulling();
> int hope = 1;
> hope &= cull && SphereIn...;
> // or ( cull
> // ? 1
> // : SphereIn...
> // );
> if (hope) { DrawAsteroid...; }
>
> The above encodes a progressive trimming of an indicator of whether
> DrawAsteroid has any hope of drawing anything.
>
> if there were more trimming operations then perhaps I would use more
> bits of hope, one for each trimming operation, clearing bits as necessary:
>
> const register int hope
> = ((cull && SphereIn...) << VectorBitSphereIn)
> | ((second_factor ) << VectorBitFactorTwo)
> ;
> if (hope) { DrawAsteroid...; }
>
> of course, maybe the "cull" indicator controls all the operations then
> it can be superior to the union operation in the second snippet but it
> needs to be inferior to the variable definition - while the first form
> lets you use "if (cull) { ... }" around all the modifications of hope.
>
overally those ! && || are far ;ess todescriptive as it should
genrally it showed imo than ifs and those ones in c are flawed and
needs rebuilding
Technical Details
Message-ID:
<11f0g34$2i3gk$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11errdb$cifc$1@dont-email.me> <11f0c44$2gkn0$1@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: fir <profesor.fir@gmail.com> Newsgroups: comp.lang.c Subject: Re: weird symplification Date: Sat, 5 Dec 2026 08:56:18 +0100 Organization: A noiseless patient Spider Lines: 77 Message-ID: <11f0g34$2i3gk$1@dont-email.me> References: <11errdb$cifc$1@dont-email.me> <11f0c44$2gkn0$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 05 Dec 2026 07:56:20 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2690580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4eBM0nZP8/PUjLZVZPdDZXOYUwXDSoYQ="; posting-host="342f4926edf4bd28a33754ba53b7ff2f" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0 SeaMonkey/2.53.24 Cancel-Lock: sha1:4z8FVKQV61R9YhnjeLggRy4Y2QY= sha256:UyhqAHC8EnpNNgUeNL5WPKtV5VXKJ9YaRpB2jQdPRQ8= sha1:+A3nn1Tgn3mb4P0pgFBou82cqCU= sha256:R4AQigZHxs50YE1A6MHnbPFBGS4m6Kz4vy2aZpiGF9A= In-Reply-To: <11f0c44$2gkn0$1@dont-email.me>