<feed xmlns='http://www.w3.org/2005/Atom'>
<title>puzzles/drawing.c, branch devel</title>
<subtitle>My sgt-puzzles tree</subtitle>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/'/>
<entry>
<title>Fall back to &lt;math.h&gt; if &lt;tgmath.h&gt; doesn't work.</title>
<updated>2023-04-06T06:08:04+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2023-04-06T06:07:30+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=3b9cafa09f783ccadda14d11fc8b73dc496368c0'/>
<id>3b9cafa09f783ccadda14d11fc8b73dc496368c0</id>
<content type='text'>
This fixes a build failure introduced by commit 2e48ce132e011e8
yesterday.

When I saw that commit I expected the most likely problem would be in
the NestedVM build, which is currently the thing with the most most
out-of-date C implementation. And indeed the NestedVM toolchain
doesn't have &lt;tgmath.h&gt; - but much more surprisingly, our _Windows_
builds failed too, with a compile error inside &lt;tgmath.h&gt; itself!

I haven't looked closely into the problem yet. Our Windows builds are
done with clang, which comes with its own &lt;tgmath.h&gt; superseding the
standard Windows one. So you'd _hope_ that clang could make sense of
its own header! But perhaps the problem is that this is an unusual
compile mode and hasn't been tested.

My fix is to simply add a cmake check for &lt;tgmath.h&gt; - which doesn't
just check the file's existence, it actually tries compiling a file
that #includes it, so it will detect 'file exists but is mysteriously
broken' just as easily as 'not there at all'. So this makes the builds
start working again, precisely on Ben's theory of opportunistically
using &lt;tgmath.h&gt; where possible and falling back to &lt;math.h&gt;
otherwise.

It looks ugly, though! I'm half tempted to make a new header file
whose job is to include a standard set of system headers, just so that
that nasty #ifdef doesn't have to sit at the top of almost all the
source files. But for the moment this at least gets the build working
again.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This fixes a build failure introduced by commit 2e48ce132e011e8
yesterday.

When I saw that commit I expected the most likely problem would be in
the NestedVM build, which is currently the thing with the most most
out-of-date C implementation. And indeed the NestedVM toolchain
doesn't have &lt;tgmath.h&gt; - but much more surprisingly, our _Windows_
builds failed too, with a compile error inside &lt;tgmath.h&gt; itself!

I haven't looked closely into the problem yet. Our Windows builds are
done with clang, which comes with its own &lt;tgmath.h&gt; superseding the
standard Windows one. So you'd _hope_ that clang could make sense of
its own header! But perhaps the problem is that this is an unusual
compile mode and hasn't been tested.

My fix is to simply add a cmake check for &lt;tgmath.h&gt; - which doesn't
just check the file's existence, it actually tries compiling a file
that #includes it, so it will detect 'file exists but is mysteriously
broken' just as easily as 'not there at all'. So this makes the builds
start working again, precisely on Ben's theory of opportunistically
using &lt;tgmath.h&gt; where possible and falling back to &lt;math.h&gt;
otherwise.

It looks ugly, though! I'm half tempted to make a new header file
whose job is to include a standard set of system headers, just so that
that nasty #ifdef doesn't have to sit at the top of almost all the
source files. But for the moment this at least gets the build working
again.
</pre>
</div>
</content>
</entry>
<entry>
<title>Replace &lt;math.h&gt; with &lt;tgmath.h&gt; throughout</title>
<updated>2023-04-04T20:43:25+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-04-04T20:43:25+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=2e48ce132e011e83517a9fc4905edcc8f9a5ef58'/>
<id>2e48ce132e011e83517a9fc4905edcc8f9a5ef58</id>
<content type='text'>
C89 provided only double-precision mathematical functions (sin() etc),
and so despite using single-precision elsewhere, those are what Puzzles
has traditionally used.  C99 introduced single-precision equivalents
(sinf() etc), and I hope it's been long enough that we can safely use
them.  Maybe they'll even be faster.

Rather than directly use the single-precision functions, though, we use
the magic macros from &lt;tgmath.h&gt; that automatically choose the precision
of mathematical functions based on their arguments.  This has the
advantage that we only need to change which header we include, and thus
that we can switch back again if some platform has trouble with the new
header.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
C89 provided only double-precision mathematical functions (sin() etc),
and so despite using single-precision elsewhere, those are what Puzzles
has traditionally used.  C99 introduced single-precision equivalents
(sinf() etc), and I hope it's been long enough that we can safely use
them.  Maybe they'll even be faster.

Rather than directly use the single-precision functions, though, we use
the magic macros from &lt;tgmath.h&gt; that automatically choose the precision
of mathematical functions based on their arguments.  This has the
advantage that we only need to change which header we include, and thus
that we can switch back again if some platform has trouble with the new
header.
</pre>
</div>
</content>
</entry>
<entry>
<title>Convert a lot of floating-point constants to single precision</title>
<updated>2023-02-19T12:41:13+00:00</updated>
<author>
<name>Ben Harris</name>
<email>bjh21@bjh21.me.uk</email>
</author>
<published>2023-02-18T18:52:21+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6'/>
<id>e8ac0381f976f2dfd70fbe52e0ec59c1a8da9df6</id>
<content type='text'>
For reasons now lost to history, Puzzles generally uses single-precision
floating point.  However, C floating-point constants are by default
double-precision, and if they're then operated on along with a
single-precision variable the value of the variable gets promoted to
double precision, then the operation gets done, and then often the
result gets converted back to single precision again.

This is obviously silly, so I've used Clang's "-Wdouble-promotion" to
find instances of this and mark the constants as single-precision as
well.  This is a bit awkward for PI, which ends up with a cast.  Maybe
there should be a PIF, or maybe PI should just be single-precision.

This doesn't eliminate all warnings from -Wdouble-promotion.  Some of
the others might merit fixing but adding explicit casts to double just
to shut the compiler up would be going too far, I feel.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
For reasons now lost to history, Puzzles generally uses single-precision
floating point.  However, C floating-point constants are by default
double-precision, and if they're then operated on along with a
single-precision variable the value of the variable gets promoted to
double precision, then the operation gets done, and then often the
result gets converted back to single precision again.

This is obviously silly, so I've used Clang's "-Wdouble-promotion" to
find instances of this and mark the constants as single-precision as
well.  This is a bit awkward for PI, which ends up with a cast.  Maybe
there should be a PIF, or maybe PI should just be single-precision.

This doesn't eliminate all warnings from -Wdouble-promotion.  Some of
the others might merit fixing but adding explicit casts to double just
to shut the compiler up would be going too far, I feel.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add 'const' to the draw_polygon coords array parameter.</title>
<updated>2021-09-13T10:04:59+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2021-09-13T10:04:59+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=88358f064351e867c73e46783a239265ff9fef7a'/>
<id>88358f064351e867c73e46783a239265ff9fef7a</id>
<content type='text'>
Thanks to Mouse for spotting that it was missing.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Thanks to Mouse for spotting that it was missing.
</pre>
</div>
</content>
</entry>
<entry>
<title>Adopt C99 bool in the printing API.</title>
<updated>2018-11-13T21:48:24+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2018-11-13T21:38:53+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=f6965b92e1915c9f49fafbadf603b4fd0da735bd'/>
<id>f6965b92e1915c9f49fafbadf603b4fd0da735bd</id>
<content type='text'>
Not many changes here: the 'dotted' flag passed to print_line_dotted
is bool, and so is the printing_in_colour flag passed to
print_get_colour. Also ps_init() takes a bool.

line_dotted is also a method in the drawing API structure, but it's
not actually filled in for any non-print-oriented implementation of
that API. So only front ends that do platform-specific _printing_
should need to make a corresponding change. In-tree, for example,
windows.c needed a fix because it prints via Windows GDI, but gtk.c
didn't have to do anything, because its CLI-based printing facility
just delegates to ps.c.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Not many changes here: the 'dotted' flag passed to print_line_dotted
is bool, and so is the printing_in_colour flag passed to
print_get_colour. Also ps_init() takes a bool.

line_dotted is also a method in the drawing API structure, but it's
not actually filled in for any non-print-oriented implementation of
that API. So only front ends that do platform-specific _printing_
should need to make a corresponding change. In-tree, for example,
windows.c needed a fix because it prints via Windows GDI, but gtk.c
didn't have to do anything, because its CLI-based printing facility
just delegates to ps.c.
</pre>
</div>
</content>
</entry>
<entry>
<title>Assorted char * -&gt; const char * API changes.</title>
<updated>2017-10-01T15:35:00+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2017-10-01T13:04:47+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=3276376d1be74b66970b88c3e941dcedf8d22474'/>
<id>3276376d1be74b66970b88c3e941dcedf8d22474</id>
<content type='text'>
I went through all the char * parameters and return values I could see
in puzzles.h by eye and spotted ones that surely ought to have been
const all along.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I went through all the char * parameters and return values I could see
in puzzles.h by eye and spotted ones that surely ought to have been
const all along.
</pre>
</div>
</content>
</entry>
<entry>
<title>draw_thick_line: Bound thickness by 1.0 below</title>
<updated>2017-09-29T16:01:41+00:00</updated>
<author>
<name>Ian Jackson</name>
<email>ijackson@chiark.greenend.org.uk</email>
</author>
<published>2017-09-29T13:29:56+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=a0435df8aa30af4ea24b4b375bc1e37600bc19fe'/>
<id>a0435df8aa30af4ea24b4b375bc1e37600bc19fe</id>
<content type='text'>
A line less than 1 pixel wide may not be visible.  So if a backend
wants to draw a line whose width scaled by the window size, that line
thickness ought to be at least 1.0.

That way if the scale is small, but still big enough that there is a
straightforward interpretation of the drawing primitives which is
legible, we implement that interpretation.

If a frontend draws a narrower line, making it wider might cause
drawing anomalies, due to the line now having a bigger bounding box.
These anomalies should occur only at small scales where currently the
display is not legible, and we should fix them as we notice them.

Signed-off-by: Ian Jackson &lt;ijackson@chiark.greenend.org.uk&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
A line less than 1 pixel wide may not be visible.  So if a backend
wants to draw a line whose width scaled by the window size, that line
thickness ought to be at least 1.0.

That way if the scale is small, but still big enough that there is a
straightforward interpretation of the drawing primitives which is
legible, we implement that interpretation.

If a frontend draws a narrower line, making it wider might cause
drawing anomalies, due to the line now having a bigger bounding box.
These anomalies should occur only at small scales where currently the
display is not legible, and we should fix them as we notice them.

Signed-off-by: Ian Jackson &lt;ijackson@chiark.greenend.org.uk&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Patch from Mark Wooding to introduce a draw_thick_line() function in</title>
<updated>2010-05-29T15:43:46+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2010-05-29T15:43:46+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=9cd182ffa92e97609d562883a1c8e74949963ba0'/>
<id>9cd182ffa92e97609d562883a1c8e74949963ba0</id>
<content type='text'>
the drawing API, for use by Loopy. It's optional: drawing.c will
construct an acceptable alternative using a filled polygon if the
front end doesn't provide it.

Net and Netslide previously had static functions called
draw_thick_line(), whose claim to the name is less justified and so
they've been renamed.

[originally from svn r8962]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
the drawing API, for use by Loopy. It's optional: drawing.c will
construct an acceptable alternative using a filled polygon if the
front end doesn't provide it.

Net and Netslide previously had static functions called
draw_thick_line(), whose claim to the name is less justified and so
they've been renamed.

[originally from svn r8962]
</pre>
</div>
</content>
</entry>
<entry>
<title>Introduce, and implement as usefully as I can in all front ends, a</title>
<updated>2009-12-27T10:01:16+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2009-12-27T10:01:16+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=9fbb365684ef662fc183ebd45c2eeb50f40589b5'/>
<id>9fbb365684ef662fc183ebd45c2eeb50f40589b5</id>
<content type='text'>
new function in the drawing API which permits the display of text
from outside basic ASCII. A fallback mechanism is provided so that
puzzles can give a list of strings they'd like to display in order
of preference and the system will return the best one it can manage;
puzzles are required to cope with ASCII-only front ends.

[originally from svn r8793]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
new function in the drawing API which permits the display of text
from outside basic ASCII. A fallback mechanism is provided so that
puzzles can give a list of strings they'd like to display in order
of preference and the system will return the best one it can manage;
puzzles are required to cope with ASCII-only front ends.

[originally from svn r8793]
</pre>
</div>
</content>
</entry>
<entry>
<title>Introduce some infrastructure to permit games' print functions to</title>
<updated>2009-02-22T12:05:38+00:00</updated>
<author>
<name>Simon Tatham</name>
<email>anakin@pobox.com</email>
</author>
<published>2009-02-22T12:05:38+00:00</published>
<link rel='alternate' type='text/html' href='https://www.franklinwei.com/cgit/puzzles/commit/?id=407f29c46f35910ce3d7ddd41f13e94213c2597e'/>
<id>407f29c46f35910ce3d7ddd41f13e94213c2597e</id>
<content type='text'>
draw dotted lines. No puzzle yet uses this, but one's about to.

[originally from svn r8453]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
draw dotted lines. No puzzle yet uses this, but one's about to.

[originally from svn r8453]
</pre>
</div>
</content>
</entry>
</feed>
