From b309c545f511162d1c30d5360f2b0a8ae3412fb7 Mon Sep 17 00:00:00 2001 From: giagitom <giagitom@gmail.com> Date: Wed, 3 May 2023 17:51:02 +0200 Subject: [PATCH] - Fixed dashes spacing - Added changelog entry --- CHANGELOG.md | 2 ++ .../geometry/cylinders/cylinders-builder.ts | 17 ++++++-------- src/mol-geo/geometry/lines/lines-builder.ts | 17 ++++++-------- src/mol-geo/geometry/mesh/builder/cylinder.ts | 22 ++++++++----------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7aa641ca6..a518560fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ Note that since we don't clearly distinguish between a public and private interf ## [Unreleased] +- Enable odd dash count (1,3,5) + ## [v3.33.0] - 2023-04-02 - Handle resizes of viewer element even when window remains the same size diff --git a/src/mol-geo/geometry/cylinders/cylinders-builder.ts b/src/mol-geo/geometry/cylinders/cylinders-builder.ts index aa28124cf..9f0e7f589 100644 --- a/src/mol-geo/geometry/cylinders/cylinders-builder.ts +++ b/src/mol-geo/geometry/cylinders/cylinders-builder.ts @@ -45,24 +45,21 @@ export namespace CylindersBuilder { const addFixedCountDashes = (start: Vec3, end: Vec3, segmentCount: number, radiusScale: number, topCap: boolean, bottomCap: boolean, stubCap: boolean, group: number) => { const d = Vec3.distance(start, end); const isOdd = segmentCount % 2 !== 0; - segmentCount++; - const s = Math.floor(segmentCount / 2); - const step = 1 / segmentCount; - const offset = step / 2; + const s = Math.floor((segmentCount + 1) / 2); + const step = d / (segmentCount + 0.5); - Vec3.sub(tmpDir, end, start); + Vec3.setMagnitude(tmpDir, Vec3.sub(tmpDir, end, start), step); + Vec3.copy(tmpVecA, start); for (let j = 0; j < s; ++j) { - const f = step * (j * 2 + 1) + offset; - Vec3.setMagnitude(tmpDir, tmpDir, d * f); - Vec3.add(tmpVecA, start, tmpDir); + Vec3.add(tmpVecA, tmpVecA, tmpDir); if (isOdd && j === s - 1) { Vec3.copy(tmpVecB, end); if (!stubCap) bottomCap = false; } else { - Vec3.setMagnitude(tmpDir, tmpDir, d * (step * ((j + 1) * 2) + offset)); - Vec3.add(tmpVecB, start, tmpDir); + Vec3.add(tmpVecB, tmpVecA, tmpDir); } add(tmpVecA[0], tmpVecA[1], tmpVecA[2], tmpVecB[0], tmpVecB[1], tmpVecB[2], radiusScale, topCap, bottomCap, group); + Vec3.add(tmpVecA, tmpVecA, tmpDir); } }; diff --git a/src/mol-geo/geometry/lines/lines-builder.ts b/src/mol-geo/geometry/lines/lines-builder.ts index d8d512dd6..2d36442b6 100644 --- a/src/mol-geo/geometry/lines/lines-builder.ts +++ b/src/mol-geo/geometry/lines/lines-builder.ts @@ -52,23 +52,20 @@ export namespace LinesBuilder { const addFixedCountDashes = (start: Vec3, end: Vec3, segmentCount: number, group: number) => { const d = Vec3.distance(start, end); const isOdd = segmentCount % 2 !== 0; - segmentCount++; - const s = Math.floor(segmentCount / 2); - const step = 1 / segmentCount; - const offset = step / 2; + const s = Math.floor((segmentCount + 1) / 2); + const step = d / (segmentCount + 0.5); - Vec3.sub(tmpDir, end, start); + Vec3.setMagnitude(tmpDir, Vec3.sub(tmpDir, end, start), step); + Vec3.copy(tmpVecA, start); for (let j = 0; j < s; ++j) { - const f = step * (j * 2 + 1) + offset; - Vec3.setMagnitude(tmpDir, tmpDir, d * f); - Vec3.add(tmpVecA, start, tmpDir); + Vec3.add(tmpVecA, tmpVecA, tmpDir); if (isOdd && j === s - 1) { Vec3.copy(tmpVecB, end); } else { - Vec3.setMagnitude(tmpDir, tmpDir, d * step * ((j + 1) * 2) + offset); - Vec3.add(tmpVecB, start, tmpDir); + Vec3.add(tmpVecB, tmpVecA, tmpDir); } add(tmpVecA[0], tmpVecA[1], tmpVecA[2], tmpVecB[0], tmpVecB[1], tmpVecB[2], group); + Vec3.add(tmpVecA, tmpVecA, tmpDir); } }; diff --git a/src/mol-geo/geometry/mesh/builder/cylinder.ts b/src/mol-geo/geometry/mesh/builder/cylinder.ts index d432a13a4..76ad187f7 100644 --- a/src/mol-geo/geometry/mesh/builder/cylinder.ts +++ b/src/mol-geo/geometry/mesh/builder/cylinder.ts @@ -101,28 +101,24 @@ export function addDoubleCylinder(state: MeshBuilder.State, start: Vec3, end: Ve export function addFixedCountDashedCylinder(state: MeshBuilder.State, start: Vec3, end: Vec3, lengthScale: number, segmentCount: number, stubCap: boolean, props: BasicCylinderProps) { const d = Vec3.distance(start, end) * lengthScale; const isOdd = segmentCount % 2 !== 0; - segmentCount++; - const s = Math.floor(segmentCount / 2); - const step = 1 / segmentCount; - const offset = step / 2; + const s = Math.floor((segmentCount + 1) / 2); + let step = d / (segmentCount + 0.5); let cylinder = getCylinder(props); - Vec3.sub(tmpCylinderDir, end, start); - + Vec3.setMagnitude(tmpCylinderDir, Vec3.sub(tmpCylinderDir, end, start), step); + Vec3.copy(tmpCylinderStart, start); for (let j = 0; j < s; ++j) { - const f = step * (j * 2 + 1) + offset; - let len = d * step; - Vec3.setMagnitude(tmpCylinderDir, tmpCylinderDir, d * f); - Vec3.add(tmpCylinderStart, start, tmpCylinderDir); - + Vec3.add(tmpCylinderStart, tmpCylinderStart, tmpCylinderDir); if (isOdd && j === s - 1) { if (!stubCap && props.topCap) { props.topCap = false; cylinder = getCylinder(props); } - len /= 2; + step /= 2; } - setCylinderMat(tmpCylinderMat, tmpCylinderStart, tmpCylinderDir, len, false); + setCylinderMat(tmpCylinderMat, tmpCylinderStart, tmpCylinderDir, step, false); MeshBuilder.addPrimitive(state, tmpCylinderMat, cylinder); + + Vec3.add(tmpCylinderStart, tmpCylinderStart, tmpCylinderDir); } } -- GitLab