Gary W. Lucas

Ranch Hand
+ Follow
since Jun 25, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
12
In last 30 days
0
Total given
0
Likes
Total received
20
Received in last 30 days
0
Total given
20
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Gary W. Lucas

You already have the tool you need in terms of the area computation.  I would move the computation into your constructor.   If the area is very close to zero, then you have a degenerate triangle.

Note that the area computation can be positive or negative depending on whether the three vertices specify the triangle boundary in clockwise or counterclockwise order.  So your test would have to include the absolute value method....   Perhaps you could do something like the following (the threshold value 1.0e-9is arbitrary):



3 months ago
Thanks.  CompleteableFuture does look promising.  I've needed that kind of functionality more than once.  I've always coded it "by hand".
4 months ago
Ben, Jason, and Martijn,

The Manning page cites concurrency as one of the topics you cover in your book.  I use multi-threading all the time, but I haven't really followed new developments since Java 1.5.  Is there any newer concurrency feature that you would recommend as especially interesting or useful?

Good luck on your new edition!  It looks like it has a lot of interesting material.  I am particularly looking forward to seeing what you have to say about the JVM in containers (something I am finding challenging).

Gary
4 months ago
As I recall from dusty memories, "to grok" means "to drink".

But, yes, it means to have established a fully internalized, visceral understanding of an idea or a person.  It's from Heinlein's "Stranger in a Strange Land".
5 months ago
As Campbell Ritchie points out, your code example could throw a null pointer exception if one of the strings in your test data set (i.e. "word") happened to be null.

    if(word.equals(target))


One common way to defend against that is to change the order of comparison statements

     if(target.equals(word))

In such a case you could test once at the top of the code to see if target was null and exit early if it is.  The String.equals() method is robust enough to handle a null argument.

That's why you'll often see code that tests for string constants given as

    if("some string".equals(word))  

rather than

  if(word.equals("some string"))


6 months ago
There are lots of ways to do this, but I tend to go with the Java TextLayout class.  The following code draws a number centered in a rectangle.
It uses the text layout to get the rectangular bounds from a TextLayout.  The bounds is based on the idea that the coordinate for the approximate left side of the character is zero and the baseline of the character is also zero.   So the value of the getY() method for the rectangle will be a negative value roughly equal to the height of the letter.

For aesthetic purposes, some characters are allowed to be rendered slightly below the baseline.  The curve for zero, for example goes slightly below the baseline.



One less than wonderful thing about this approach is that the center of a numeric digit might not be quite what you expect.  In the output image, note that the center of the numeral 1 for a sans serif font is not through the main vertical.


7 months ago
I am pleased to announce a new release of the Gridfour free open-source software library. Gridfour provides a set of Java software tools intended to assist in the storage and production of raster data.

The new release, version 1.0.2, adds new utilities and fleshes out a number of API elements. But the feature that may be of most interest to Java developers is that it implements a multi-threaded approach for performing data compression and decompression operations. In our tests with large geophysical data sets, the new multi-threaded options shaved off about 40 percent of the runtime for writing and reading persistent data sets.

If you would like to find out more about the Gridfour project, please visit our wiki pages or our  main repository on Github. The new multi-threaded implementations are described at our Multi-Threading wiki page and project Javadoc is available at the Core 1.0.2 API overview.

Finally, a word of thanks…  Over the years, I’ve gotten a lot of help and useful advice from folks at the Code Ranch. And a fair bit of what I learned here found its way into my work on the Gridfour project. So thank you for all of that.  I wish you well in all of your endeavors.

Gary
9 months ago
Thanks.  Worked like a charm.



10 months ago
I am trying to write an image that features characters like z-bar (z with a bar over it to indicate a mean value).  I've found the unicode value for a bar glyph, but the only way I can get it to combine with a letter is by plotting the two characters in the same location using multiple calls.  Is there a way to combine these into a single string?  Or, did I simply miss something like there being a standard glyph that combines these features?

Here's my sample code


And here's he result (the first line was generated using the "noJoy" text layout, the second line by drawing in the same place twice).

10 months ago
Thanks.  That worked like a charm.  I'm really glad I posted this question.

I'm running under Java 8, which doesn't support the Map.to() method you used. So I had to code it out explicitly.  I also decided to use a subscript of (i,j) rather than zero just to exercise the feature...  The letters i and j came out too close together, so I embedded the unicode characters for "half-wide spaces" \u2009.  



10 months ago
Thanks!   I was so focused on making attributes work that it didn't occur to me to look for an different character.

I adjusted the code to use the string  "x\u2080+2w".   I kept the font attribute to make the zero be a little smaller than the rest of the text.   And I also made the plus sign have a bold attribute so that it wasn't quite so thin.   It worked out pretty well.

Funny thing about the subscript characters in Unicode.  I visited the link you gave me.  They had numerals, plus and minute signs, and parentheses. But they didn't have commas.  That seems like such a strange thing to omit.  




10 months ago
I've been trying to use Java render a string that includes a subscript.  I thought that AttributedString looked like a straightforward solution, but I don't seem to be able to get subscripts to work.  I've tried a bunch of different combinations.  Could somebody point me towards a solution?

Thanks.

Gary


The code below renders to an image.  The results are very attractive (yay Java font rendering!) but for the X-zero term, the zero is not moved to a subscript position.





10 months ago
Ioanna (and others),

You are welcome to take a look at the Tinfour and Gridfour projects on Github and see if there's anything that you find interesting. I am always looking for new ideas.  I have to add the caveat that I haven't had much practice in managing code contributions from other developers, so there would be a certain amount of uncertainty in getting involved.

The project links are

The Gridfour tools for raster data processing
The Tinfour library for Delaunay triangulations
11 months ago
Thank you.  That's a really interesting take on things.   I will have to spend some time to thinking about my own testing from your perspective.
11 months ago
Thanks for your book  on testing Web API's.  It is quite timely for me because my group is just getting started developing data services of this type.

How does one go about making sure that a test is a good reflection of the actual pattern of usage for a Web API?  For that matter, how does one even predict what a pattern of usage would look like?
11 months ago