Skip to content

Commit f00af5a

Browse files
committed
Fix position math and scaling
1 parent 303129a commit f00af5a

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

rm_lines/headers/advanced/math.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ namespace AdvancedMath {
105105
y *= other.y;
106106
}
107107

108+
void operator*=(const float &other) {
109+
x *= other;
110+
y *= other;
111+
}
112+
108113
void operator/=(const Vector &other) {
109114
x /= other.x;
110115
y /= other.y;

rm_lines/src/renderer/renderer.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,21 +241,7 @@ void Renderer::getFrame(uint32_t *data, const size_t dataSize, Vector position,
241241
const auto lineBuf = &stroker.raster.raster.fill.lineBuffer;
242242
const auto scale = bufferSize / frameSize;
243243

244-
// Align the position to scale properly to the center of the requested frame
245-
// The scale is automatically calculated by the provided bufferSize and frameSize
246-
// In this case the frameSize could be let's say smaller but the buffer is larger and the scale is 2
247-
// To compensate for this we need to align the position to the center of the frame
248-
// If this isn't done the scaling will look as if from the top left corner
249-
250-
// Align to 0, 0
251-
position += frameSize / 2;
252-
position -= bufferSize / 2;
253-
254-
// Align to the scale
255-
position -= Vector(
256-
frameSize.x * (scale.x - 1), // Scale of 1 means no change, so we subtract 1 from the scale
257-
frameSize.y * (scale.y - 1)
258-
) / 2;
244+
position *= -1; // It's technically an offset
259245

260246
stroker.joinStyle = JoinStyle::RoundJoin;
261247
stroker.raster.raster.fill.stroker = &stroker;

tests/draw_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
image.save(output_path, 'PNG')
4040

4141
rect = Rect(0, 0, *paper_size)
42-
combined = Image.new('RGB', (paper_size[0] * 3, paper_size[1]))
42+
tophalf = Rect(0, 0, paper_size[0] // 2, paper_size[1] // 2)
43+
bottomhalf = Rect(paper_size[0] // 2, paper_size[1] // 2, paper_size[0] // 2, paper_size[1] // 2)
44+
combined = Image.new('RGB', (paper_size[0] * 4, paper_size[1]))
4345
print("Creating a scaling combined frame test...")
44-
for i, rect in enumerate((rect.scale_by(2, 2), rect, rect.scale_by(0.5, 0.5))):
46+
for i, rect in enumerate((rect, tophalf, bottomhalf, rect.scale_by(2, 2))):
4547
lib.getFrame(renderer_id, buffer, buffer_size * 4, *rect.topleft, *rect.size, *paper_size, True)
4648
raw_frame = bytes(buffer)
4749
image = Image.frombytes('RGBA', paper_size, raw_frame, 'raw', 'RGBA')

tests/tests_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ def check_decode(raw: bytes, name: str):
8080
lib.setLogger(python_logger)
8181
lib.setErrorLogger(python_error_logger)
8282
lib.setDebugLogger(python_debug_logger)
83+
# lib.setDebugMode(True)

0 commit comments

Comments
 (0)