Monthly Archives: May 2010

General

C++ error messages

OK, one thing I don’t miss about C++ is the error messages. Here’s an incredibly obtuse way to say something:

In file included from /usr/include/c++/4.4/bits/stl_algobase.h:67,
                 from /usr/include/c++/4.4/bits/char_traits.h:41,
                 from /usr/include/c++/4.4/ios:41,
                 from /usr/include/c++/4.4/ostream:40,
                 from /usr/include/c++/4.4/iostream:40,
                 from ../src/Flipper.cpp:1:
/usr/include/c++/4.4/bits/stl_iterator_base_types.h: In instantiation of ‘std::iterator_traits > > >’:
/usr/include/CGAL/centroid.h:833:   instantiated from ‘CGAL::CGALi::Dispatch_centroid > >, CGAL::Point_2 > > >’
../src/Flipper.cpp:102:   instantiated from here
/usr/include/c++/4.4/bits/stl_iterator_base_types.h:127: error: no type named ‘iterator_category’ in ‘class CGAL::Point_2 > >’
/usr/include/c++/4.4/bits/stl_iterator_base_types.h:128: error: no type named ‘value_type’ in ‘class CGAL::Point_2 > >’
/usr/include/c++/4.4/bits/stl_iterator_base_types.h:129: error: no type named ‘difference_type’ in ‘class CGAL::Point_2 > >’
/usr/include/c++/4.4/bits/stl_iterator_base_types.h:130: error: no type named ‘pointer’ in ‘class CGAL::Point_2 > >’
/usr/include/c++/4.4/bits/stl_iterator_base_types.h:131: error: no type named ‘reference’ in ‘class CGAL::Point_2 > >’

Translation: you don’t need to include ‘centroid.h’.

General

Offsetting a polyline

Thanks to a question on StackOverflow, I did some playing with Java’s Graphics2D. Below is some code to generate an offset of a polyline, i.e. given a polyline (a string of connected line segments), generate a polygon that represents a thick version of that line.

Clearly, the Java guys took some shortcuts here, because the polygon ends up including a lot of interior segments that you don’t really want, etc. However, filling it using a nonzero winding rule covers a lot of sins. And I can understand why they committed those sins, since it’s kinda hard to do in general. Read the CGAL page about offsetting for an intro. Sometime I’ll have to investigate the shortcut methods in the OpenJDK source; looking at this output, I’m definitely curious.

Unfilled
Unfilled
Filled
Filled

import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.geom.Path2D;
import java.awt.geom.PathIterator;

public class StrokePath
{
    public static void main(String[] args)
    {
        // set line width to 6, use bevel for line joins
        BasicStroke bs = new BasicStroke(6.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);

        // create a path for the input
        Path2D p = new Path2D.Float();
        p.moveTo(50.0, 50.0);
        p.lineTo(65.0, 100.0);
        p.lineTo(70.0, 60.0);
        p.lineTo(120.0, 65.0);
        p.lineTo(40.0, 200.0);

        // create outline of wide lines by stroking the path with the stroke
        Shape s = bs.createStrokedShape(p);
        // output each of the segments of the stroked path for the output polygon
        PathIterator pi = s.getPathIterator(null);
        while (!pi.isDone())
        {
            pi.next();
            double[] coords = new double[6];
            int type = pi.currentSegment(coords);
            switch (type)
            {
            case PathIterator.SEG_LINETO:
                System.out.println(String.format("SEG_LINETO %f,%f", coords[0], coords[1]));
                break;
            case PathIterator.SEG_CLOSE:
                System.out.println("SEG_CLOSE");
                break;
            case PathIterator.SEG_MOVETO:
                System.out.println(String.format("SEG_MOVETO %f,%f", coords[0], coords[1]));
                break;
            default:
                System.out.println("*** More complicated than LINETO... Maybe should use FlatteningPathIterator? ***");
                break;
            }
        }
    }
}
General

Elicitation

Been playing a little bit on Stack Overflow. Got interested after a few of my web searches ended up there and there were actual answers (if you’ve searched the web for programming questions before, you know the value of the average result on a forum site tends to zero).

Among the other potential positive values of answering questions there, I noticed one today: the process tends to elicit memories of knowledge or talents that I had forgotten that I have. Should be interesting.

General

Is there a word for this?

What’s the word for an answer to a question in an internet forum of the form “Idiot! That’s so easy! Here’s a vague description of an unworkable solution that I clearly haven’t even begun to try myself: …”

I’d figure there’s a one-word description for that since it comprises about 80% of all answers on any given forum.

General

Libraries, a few things I love about

they’re a great place to practice my particular pointillistic style of info-dabbling.
that subliminal feeling of immersion in a physicalized potential-space.
the cohabitation of old and new, from the ancient-obsolete to the fantastic-futuristic.
the quiet. The noise.
the slow unfolding of a hypercompressed universal homunculus.
the smell and security of paper.
knowing that these other people are like me in a certain way.
the uncountable fragments of freedom recoalescing.

General

Computer-generated thingy

I didn’t quite get the effect I was looking for, but I’m kinda done messing with it.

Springy thing

Click for a closer look.

General

Untitled

I don’t know why, but I sorta like this. I better post it before I remember that it’s not very interesting at all…

Click for ghastly detail.

General

Bypasses

There’s the book I was looking for… I looked at this briefly at the library one day, found it intriguing but didn’t really pay a lot of attention to it, then yesterday found myself ‘discovering’ the basic idea of the book again. But having since forgotten the title, and the library having moved the whole section to another place so I couldn’t use place-memory to find it, and failing to find it in the area where I think it should have been moved to, but remembering the general sort of books I was looking for when I did happen upon it, and using the LOC catalog browse-by-call-number feature, I finally found it again: Bypasses.

The basic idea behind the book is that a major problem solving technique that appears in various guises is to transform the problem from one domain to another, solve the transformed problem, then transform the solution back to the original domain. In a pseudo-mathematical manner of speaking: T-1MT. The author gathered examples from different fields and made some arguments about the generalization. Don’t remember a lot about it, but I’m going to find a copy again and read a bit more…