egui/crates/emath/src
zk 27e648a335
Add `Rect::scale_from_center` (#4673)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

I find myself wanting this API quite a lot, and I imagine it'll probably
be useful for others.

# What?

This PR adds `Rect::scale` and `Rect::scale2` functions, which work a
lot like `expand`, but instead multiply by a scale.

i.e.
```rs
rect.scale(2.0); // rect is 2x as big, still in same center
rect.scale2(vec2(1.5, 2.0)); // rect is 1.5x as big on x axis, 2.0x as big on y axis. still in same center
```

# Why?

Before this you either had to write this yourself or use a `expand` in a
cumbersome way:
```rs
rect.expand2(vec2(rect.width() * scale.x / 2.0, rect.height() * scale.y / 2.0));
```

I find myself wanting to scale things up by a factor frequently enough,
and it seems like a useful addition to have a multiply-based variant of
`expand`.

I realise this is pretty minor, but it seems useful enough to me!

---------

Co-authored-by: zkldi <20380519+zkldi@users.noreply.github.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-07-15 19:54:35 +02:00
..
align.rs Add `Align2::anchor_size` (#3863) 2024-01-22 16:47:50 +01:00
easing.rs Easing functions (#4630) 2024-06-06 13:09:52 +02:00
history.rs Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00
lib.rs egui_plot: Improve default formatter of tick-marks (#4738) 2024-06-30 14:20:41 +02:00
numeric.rs Move all crates into a `crates` directory (#1940) 2022-08-20 10:41:49 +02:00
ordered_float.rs Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389) 2024-04-21 20:36:32 +02:00
pos2.rs Make `Debug` format of `Vec2/Pos2/Rot2` respect user precision (#4671) 2024-06-18 23:03:23 +02:00
range.rs Cross-widget text select (#3870) 2024-01-24 15:45:22 +01:00
rect.rs Add `Rect::scale_from_center` (#4673) 2024-07-15 19:54:35 +02:00
rect_transform.rs Use `Self` everywhere (#3787) 2024-01-08 17:41:21 +01:00
rot2.rs Fix docstring 2024-06-26 09:00:11 +02:00
smart_aim.rs Remove `extra_asserts` and `extra_debug_asserts` feature flags (#4478) 2024-05-10 19:39:08 +02:00
ts_transform.rs Add layer transforms, interaction in layer (#3906) 2024-02-17 11:02:56 +01:00
vec2.rs Document Vec2 constants 2024-07-05 11:39:47 +02:00
vec2b.rs A `Window` can now be resizable in only one direction (#4155) 2024-03-11 09:29:48 +01:00