Skip to content

Commit

Permalink
Fix bug in label rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
MuTsunTsai committed May 21, 2024
1 parent dc57bb5 commit a9c5f9d
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Change log

## v4.1.1

Fix bug in label rendering.

## v4.1.0

If a line is later only used to make one intersection, we render it as a pinch instead of a whole line.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><title>ReferenceFinder</title><meta charset="UTF-8"><meta name="viewport" content="initial-scale=1,maximum-scale=5,width=device-width"><meta name="description" content="Find reference points and lines in crease patterns."><link rel="icon" href="/reference-finder/favicon.ico"/><script async src="https://www.googletagmanager.com/gtag/js?id=G-GG1TEZGBCQ"></script><script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),"localhost"!=location.hostname&&gtag("config","G-GG1TEZGBCQ",{page_title:document.title,page_path:"/reference-finder/"});const settings=localStorage.getItem("settings");settings&&0!=JSON.parse(settings).state.theme||!matchMedia("(prefers-color-scheme: dark)").matches||(document.documentElement.dataset.bsTheme="dark"),"serviceWorker"in navigator&&"31213"!=location.port&&navigator.serviceWorker.register("/reference-finder/service-worker.js",{scope:"/reference-finder/"})</script><script defer="defer" src="/reference-finder/static/js/react.37377712.js"></script><script defer="defer" src="/reference-finder/static/js/rabbit-ear.cee198ed.js"></script><script defer="defer" src="/reference-finder/static/js/vendor.8f6bc5de.js"></script><script defer="defer" src="/reference-finder/static/js/index.08916983.js"></script><link href="/reference-finder/static/font/fa-solid-900.6691c62b.woff2" rel="preload" as="font" crossorigin=""><link href="/reference-finder/static/css/index.f2332736.css" rel="stylesheet"></head><body><noscript class="p-3">You need to enable JavaScript to run this app.</noscript><div id="root" class="d-flex flex-column h-100"></div></body></html>
<!doctype html><html lang="en"><head><title>ReferenceFinder</title><meta charset="UTF-8"><meta name="viewport" content="initial-scale=1,maximum-scale=5,width=device-width"><meta name="description" content="Find reference points and lines in crease patterns."><link rel="icon" href="/reference-finder/favicon.ico"/><script async src="https://www.googletagmanager.com/gtag/js?id=G-GG1TEZGBCQ"></script><script>function gtag(){dataLayer.push(arguments)}window.dataLayer=window.dataLayer||[],gtag("js",new Date),"localhost"!=location.hostname&&gtag("config","G-GG1TEZGBCQ",{page_title:document.title,page_path:"/reference-finder/"});const settings=localStorage.getItem("settings");settings&&0!=JSON.parse(settings).state.theme||!matchMedia("(prefers-color-scheme: dark)").matches||(document.documentElement.dataset.bsTheme="dark"),"serviceWorker"in navigator&&"31213"!=location.port&&navigator.serviceWorker.register("/reference-finder/service-worker.js",{scope:"/reference-finder/"})</script><script defer="defer" src="/reference-finder/static/js/react.37377712.js"></script><script defer="defer" src="/reference-finder/static/js/rabbit-ear.cee198ed.js"></script><script defer="defer" src="/reference-finder/static/js/vendor.8f6bc5de.js"></script><script defer="defer" src="/reference-finder/static/js/index.50aa57ff.js"></script><link href="/reference-finder/static/font/fa-solid-900.6691c62b.woff2" rel="preload" as="font" crossorigin=""><link href="/reference-finder/static/css/index.f2332736.css" rel="stylesheet"></head><body><noscript class="p-3">You need to enable JavaScript to run this app.</noscript><div id="root" class="d-flex flex-column h-100"></div></body></html>
2 changes: 1 addition & 1 deletion docs/service-worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/static/js/index.08916983.js

This file was deleted.

1 change: 1 addition & 0 deletions docs/static/js/index.50aa57ff.js

Large diffs are not rendered by default.

Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reference-finder",
"version": "4.1.0",
"version": "4.1.1",
"description": "Find reference points and lines in crease patterns.",
"scripts": {
"start": "make && rsbuild dev -o",
Expand Down
22 changes: 12 additions & 10 deletions src/app/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ export function startStatistics(trials: number, callback: typeof statisticsCallb
worker.postMessage([99, trials]);
}

function parseSolution(text: string) {
const solution = JSON.parse(text) as Solution;
const steps = solution.steps;
solution.steps = [];
for(const step of steps) {
if(step.axiom > 0 || step == steps[steps.length - 1]) solution.steps.push(step);
else solution.steps[solution.steps.length - 1].intersection = step;
}
return solution;
}

export function resetWorker(db: DbSettings) {
if(worker) {
worker.terminate();
Expand Down Expand Up @@ -63,16 +74,7 @@ export function resetWorker(db: DbSettings) {
// console.log(text);

if(running) {
// Organize steps
const solution = JSON.parse(text) as Solution;
const steps = solution.steps;
solution.steps = [];
for(const step of steps) {
if(step.axiom > 0 || step == steps[steps.length - 1]) solution.steps.push(step);
else solution.steps[solution.steps.length - 1].intersection = step;
}
solutions.push(solution);

solutions.push(parseSolution(text));
useStore.setState({ solutions: solutions.concat() });
} else if(statisticsRunning) {
statisticsCallback(text);
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/svg/diagram.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
stroke-dasharray: 0.05 0.025;
}

.line-pinch, .line-valley {
.line-pinch,
.line-valley {
stroke: var(--valley);
stroke-width: 0.02;
}
Expand Down
16 changes: 8 additions & 8 deletions src/app/components/svg/diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const OFFSET_SIZE = 0.09;
* Spread out the labels from each other.
*/
function getTextOffset(text: LabelElement, data: DiagramElement[]): IPoint {
const pts = (data.filter(e => e && e.type == ElementType.label && e != text) as LabelElement[])
.map(l => {
// Other labels that are closer have greater weights
const dx = text.pt[0] - l.pt[0];
const dy = text.pt[1] - l.pt[1];
const d = Math.sqrt(dx * dx + dy * dy);
return [dx / d / d, dy / d / d];
});
const otherLabels = data.filter(e => e && e.type == ElementType.label && e != text) as LabelElement[];
const pts = otherLabels.map(l => {
// Other labels that are closer have greater weights
const dx = text.pt[0] - l.pt[0];
const dy = text.pt[1] - l.pt[1];
const d = Math.sqrt(dx * dx + dy * dy);
return [dx / d / d, dy / d / d];
});
if(pts.length == 0) return [0, 0];
const avgX = pts.map(p => p[0]).reduce((x, v) => x + v, 0) / pts.length;
const avgY = pts.map(p => p[1]).reduce((x, v) => x + v, 0) / pts.length;
Expand Down
4 changes: 2 additions & 2 deletions src/core/RFVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ NOTE: Do not edit these directly, as these values now sync with package.json aut
#define APP_FAMILY ReferenceFinder
#define VERSION_MAJOR 4
#define VERSION_MINOR 1
#define VERSION_BUGFIX 0
#define VERSION_BUILD 20240520
#define VERSION_BUGFIX 1
#define VERSION_BUILD 20240521

/******************************************************************************/

Expand Down
5 changes: 4 additions & 1 deletion src/core/class/json/jsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

using namespace std;

JsonObject::JsonObject() : mStarted(false) {}
JsonObject::JsonObject() : mStarted(false) {
// Set the precision so that double numbers are printed with more digits
mStream.precision(15);
}

void JsonObject::add(char const *key, const string &value) {
addKey(key);
Expand Down
9 changes: 8 additions & 1 deletion src/core/class/refLine/refLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ void RefLine::DrawSelf(RefStyle rstyle, short ipass) const {

case PASS_LABELS: {
XYPt mp = MidPoint(op1, op2); // label goes at the midpoint of the line

// We add a tiny offset along the direction of the line,
// to prevent the label from coinciding with other labels,
// causing rendering error.
mp.x += (op1.x - op2.x) * 1e-10;
mp.y += (op1.y - op2.y) * 1e-10;

string sl(1, GetLabel());
switch (rstyle) {
case REFSTYLE_NORMAL:
Expand All @@ -167,7 +174,7 @@ void RefLine::DrawSelf(RefStyle rstyle, short ipass) const {
case REFSTYLE_HILITE:
if (mForMark != NULL) {
RefMark *mark = (RefMark *)mForMark;
moveCloser(mp, mark->p, pinchLength * 1.2);
moveCloser(mp, mark->p, pinchLength * 0.75);
}
sDgmr->DrawLabel(mp, sl, RefDgmr::LABELSTYLE_HILITE);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/core/class/xypt.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "xypt.h"

#include <iomanip>

using namespace std;

/**********
Expand Down
Binary file modified src/lib/ref.wasm
Binary file not shown.

0 comments on commit a9c5f9d

Please sign in to comment.