bramstein / typeset

TeX line breaking algorithm in JavaScript
BSD 2-Clause "Simplified" License
990 stars 74 forks source link

Refactored code for use as a library. #23

Open frobnitzem opened 7 years ago

frobnitzem commented 7 years ago

The main files were moved into the src directory, and Typeset was removed in favor of the classes "LineBreak," "LinkedList," and the function "BreakLines." It seems that LinkedList could be written to use arrays...

Top-level wrapper functions from browser-assist were moved into src/typeset.js which is now called like:

ret = typeset(text, measure_a_line, 'justify', [350], 3);
spans = gen_html(ret)
$('#browser-assist').append(spans[0]);
$('#browser-assist + ul').append(spans[1].map(function(w) {
    return "<li>"+w.toFixed(3)+"</li>";
}).join(""));

ideally, the more advanced ones used in flatland will follow later.

PhilterPaper commented 3 years ago

Do your changes have any effects on reported bugs?

  1. poor line-breaking in flatland demo
  2. line-length setting doesn't seem to work
  3. demerits value 100 or 3000?
alerque commented 3 years ago

I haven't reviewed these in detail @PhilterPaper, but the typical definition of "refactoring" code in programmer jargon would mean that no, this has no affect on reported bugs. When you refactor code you basically shuffle things around to different places or making various structural changes to the code, but the expected input and output is the same.

Of course refactoring can fix bugs (or introduce new ones), but the goal of a refactor is to not change the function while improving the code health.

frobnitzem commented 2 years ago

These are maintainability improvements, so that changes to the codebase can be more isolated and require less working memory for library developers and users.