No description
Find a file
2025-06-09 10:21:23 +02:00
data an example shape from opengl docs, may be instructive for testing different winding rules 2015-10-02 13:56:20 -05:00
pybind11 vendor pybind11 2025-06-07 20:04:41 +02:00
.gitattributes stop files in data/ from appearing in language summary 2016-01-27 20:45:45 -06:00
.gitignore skeleton python build 2025-06-07 20:05:02 +02:00
CMakeLists.txt skeleton python build 2025-06-07 20:05:02 +02:00
contours_and_segments.hh Switch data types from double to float (via a new typedef) 2023-12-21 20:44:13 -06:00
dash.py pydashing: It's useful now! 2025-06-08 18:02:43 +02:00
dashing.cc get rid of need for boost, but require c++20 2024-12-26 20:05:58 -06:00
dashing.hh dashing::Dash: provide constructor 2025-06-09 10:20:43 +02:00
dashing_F.hh Switch data types from double to float (via a new typedef) 2023-12-21 20:44:13 -06:00
LICENSE.md initial commit 2015-08-19 19:53:52 -05:00
main.cc finish getting rid of boost 2024-12-26 20:07:33 -06:00
Makefile skeleton python build 2025-06-07 20:05:02 +02:00
parse_numbers.hh finish getting rid of boost 2024-12-26 20:07:33 -06:00
pydashing.cc pydashing: Add PSMatrix, Dash and extend HatchPattern. 2025-06-09 10:21:23 +02:00
pyproject.toml skeleton python build 2025-06-07 20:05:02 +02:00
README.md Document the hatch pattern syntax a bit 2025-06-08 17:59:49 +02:00
setup.py skeleton python build 2025-06-07 20:05:02 +02:00
splitall.py my somewhat arty scriptsplitall.py 2025-06-08 20:23:45 +02:00

dashing - a library for autocad-style hatch patterns

License: permissive (zlib); see source files for additional details.

On a i5-1235U in multithreaded benchmark mode, it runs at over 3.3 billion dashes per second:

$ time ./dashing.omp -b -s .002 data/HWOOD6E1.pat  data/sf.seg
2822685873
real	0m0.851s

Example image

Development status

The author (@jepler) is not actively using or developing this project. Issues and pull requests are not likely to be acted on. I would be interested in passing this project to a new maintainer.

Usage

API

xyhatch(const HatchPattern&, It start, It end, Cb cb, Wr wr): Iterators start..end define a range of segments, which must define a set of closed contours. The winding rule wr defines which regions are in the interior of the contours. For each dash or dot in the resulting hatch, cb is called with the output segment.

xyhatch(const HatchPattern&, const C &segments, Cb cb, Wr wr): The container C holds segments which must define a set of closed contours. The winding rule wr defines which regions are in the interior of the contours. For each dash or dot in the resulting hatch, cb is called with the output segment.

xyhatch(const HatchPattern&, const C &segments, Cb cb, const char *wr): The container C holds segments which must define a set of closed contours. The winding rule wr defines which regions are in the interior of the contours. For each dash or dot in the resulting hatch, cb is called with the output segment.

HatchPattern::FromFile: Read a hatch pattern from a file.

parse_numbers(std::string line): Read a comma and/or space-separated sequence of numbers into a vector

SegmentsFromFile, ContoursFromFile, ContourToSegments, ContoursToSegments: Read and convert segments and contours

Useful winding rules include:

  • [](int i) { return i % 2 != 0; }, the even-odd winding rule
  • [](int i) { return i != 0;}, the non-zero winding rule
  • [](int i) { return i > 0;}, the greater-than-zero winding rule

but any predicate of a single integer may be used.

Parallel API

These APIs are available if built with -fopenmp -DDASHING_OMP

xyhatch_omp(const HatchPattern&, It start, It end, Cb cb, Wr wr): Iterators start..end define a range of segments, which must define a set of closed contours. The winding rule wr defines which regions are in the interior of the contours. For each dash or dot in the resulting hatch, cb is called with the output segment and the thread ID.

xyhatch_omp(const HatchPattern&, const C &segments, Cb cb, Wr wr): The container C holds segments which must define a set of closed contours. The winding rule wr defines which regions are in the interior of the contours. For each dash or dot in the resulting hatch, cb is called with the output segment and the thread ID.

Other APIs

Other items in the header files are implementation details.

Demo program

The demo program, which compiles to dashing with make, reads a dash pattern file and a segment list file and produces a svg file on the output which visualizes the result of the hatch operation.

A segment list file consists of a closed contour on each line specified as a series of x,y coordinates. For instance, this segment list is a simple box:

-100 -100 100 -100 100 100 -100 100

The first point is -100 -100.

It accepts several commandline parameters:

-b: Benchmark mode: print only the number of dashes that would have been
    generated

-j: Apply a jitter to all coordinates in the segment list file

-s: scale the dash pattern file by a given factor

-r rulename: select the given rulename, one of the following: odd nonzero positive negative abs_geq_two

Hatch pattern files

The syntax of hatch pattern files is based on public documentation of Autocad.

A file consists of:

  • A line with a star followed by arbitrary, ignored text (the pattern name)
  • A series of lines which specify individual dash patterns

The dash-pattern lines consist of comma-separated values. The first five values have a set meaning:

  • The dash angle in degrees
  • The X dash origin
  • The Y dash origin
  • The X dash repeat distance
  • The Y dash repeat distance

The remaining values are alternating positive and negative nonzero values, giving the length of marked (positive) and skipped (negative) portions of the dash. In dashing, the number of values must be even, the first value must be positive, and the signs must strictly alternate.

If there are no dash/space lengths specified, the entire line is stroked.