Skip to content

Commit e05d614

Browse files
zachelnetDeepSeek V4
andcommitted
docs: maintainability comments + low-hanging cleanup
- sample_bilinear_rgba: document alpha interpolation approach (M6) - ROTATE_CURSOR_MAP: document ring structure and fallback (M7) - rotate_sprite_expand_top_left: avoid cloning empty sprite (L1) - RenderControlsPanel: reuse currentDeg for slider value, eliminating double Number.parseFloat (L2) - TextBlockLayer: avoid rotate(-0deg) in number badge (L7) Co-authored-by: DeepSeek V4 <deepseek@v4.ai>
1 parent 413f39e commit e05d614

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

crates/koharu-app/src/renderer.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ fn rotate_sprite_expand_top_left(src: &RgbaImage, angle_rad: f32) -> (RgbaImage,
10581058
let src_w = src.width();
10591059
let src_h = src.height();
10601060
if src_w == 0 || src_h == 0 {
1061-
return (src.clone(), 0.0, 0.0);
1061+
return (RgbaImage::new(0, 0), 0.0, 0.0);
10621062
}
10631063

10641064
// Fast path: exact 90° multiples — direct integer pixel rearrangement,
@@ -1150,6 +1150,13 @@ fn rotate_point_top_left(x: f32, y: f32, cos: f32, sin: f32) -> (f32, f32) {
11501150
(cos * x - sin * y, sin * x + cos * y)
11511151
}
11521152

1153+
/// Bilinear sample of an RGBA sprite.
1154+
///
1155+
/// Interpolates RGB in premultiplied-alpha space and alpha in straight-alpha
1156+
/// space, then un-premultiplies once at the end. This is mathematically
1157+
/// equivalent to the standard "premultiply all four channels, interpolate,
1158+
/// un-premultiply" approach but avoids premultiplying alpha (which is
1159+
/// invariant under premultiplication) through the interpolation step.
11531160
fn sample_bilinear_rgba(src: &RgbaImage, x: f32, y: f32) -> Rgba<u8> {
11541161
let max_x = src.width() as f32 - 1.0;
11551162
let max_y = src.height() as f32 - 1.0;

ui/components/canvas/TextBlockLayer.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ type BoxGeometry = {
2424
height: number
2525
}
2626

27-
/** Rotate a CSS resize-cursor name by the given degrees (snapped to 45° steps). */
27+
/**
28+
* Maps CSS resize cursors through 45° rotation steps.
29+
*
30+
* Each entry is a ring of 8 cursor names at 0°, 45°, 90°, …, 315°.
31+
* - Index 0: 0° (identity)
32+
* - Index 1: 45°
33+
* - Index 2: 90°
34+
* - …
35+
* - Index 7: 315°
36+
*
37+
* Unknown cursors fall back to the original name (see `rotateCursor`).
38+
*/
2839
const ROTATE_CURSOR_MAP: Record<string, readonly string[]> = {
2940
'ns-resize': ['ns-resize', 'nesw-resize', 'ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize', 'ew-resize', 'nwse-resize'],
3041
'ew-resize': ['ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize', 'ew-resize', 'nwse-resize', 'ns-resize', 'nesw-resize'],
@@ -281,7 +292,7 @@ function TextBlockItem({
281292
className={`pointer-events-none absolute -top-1.5 -left-1.5 flex h-4 w-4 items-center justify-center rounded-full text-[9px] font-semibold text-white shadow ${
282293
selected ? 'bg-primary' : 'bg-rose-400'
283294
}`}
284-
style={{ transform: `rotate(${-(t.rotationDeg ?? 0)}deg)` }}
295+
style={{ transform: `rotate(${t.rotationDeg ? -t.rotationDeg : 0}deg)` }}
285296
>
286297
{index + 1}
287298
</div>

ui/components/panels/RenderControlsPanel.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,7 @@ export function RenderControlsPanel() {
846846
max={String(MAX_ROTATION_DEG)}
847847
step='1'
848848
disabled={!selectedNode}
849-
value={
850-
rotationDraft != null && Number.isFinite(Number.parseFloat(rotationDraft))
851-
? String(clampRotationDeg(Number.parseFloat(rotationDraft)))
852-
: String(selectedNode?.transform.rotationDeg ?? 0)
853-
}
849+
value={String(currentDeg)}
854850
onChange={(event) => {
855851
setRotationDraft(event.target.value)
856852
}}

0 commit comments

Comments
 (0)