Rectangle, Point, and Size need concerted structure #5644

Closed
opened 2026-01-31 00:18:10 +00:00 by claunia · 2 comments
Owner

Originally created by @miniksa on GitHub (Dec 18, 2019).

Originally assigned to: @lhecker on GitHub.

OK, as I'm refactoring, there's a few problems:

  1. There's a lot of conversion on interface boundaries between size_t, long, and SHORT based versions of representations of rectangles, points, and sizes.
  2. There's a bunch of places where we pass a line,column pair as two size_ts because there isn't a size_t version of SIZE. It should probably be passed as one sensible struct because the ordering of these parameters keeps getting reversed too.
  3. Many of our conversions use an assorted mix of either C-cast, static_cast, gsl::narrow, gsl::narrow_cast, or intsafe.h.
  4. We don't distinguish points from sizes in console code. They're both COORD. x is width and y is height for size usage.

We're also going to want to be able to expand most of our values to reach an "infinite" scrollback.

My proposal here would be:

  • In the types library, we should create:
  1. Point
  • Contains x and y like Windows SDK 'POINT' but is size_t.
  • Has conversions to Windows SDK POINT safely.
  • Has conversions to Console's COORD safely.
  1. Size
  • Contains 'cx' and 'cy' like Windows SDK 'SIZE' but is size_t.
  • Has conversions to Windows SDK SIZE safely.
  • Has conversions to Console's COORD safely.
  1. Rectangle
  • Contains a Point and a Size.
  • Has conversions to Windows SDK RECT safely.
  • Has conversions to Console's SMALL_RECT safely.
  1. Viewport
  • Update this guy to be happy with conversions in and out of the above 3.

Then walk through the code and update to use these things.

Originally created by @miniksa on GitHub (Dec 18, 2019). Originally assigned to: @lhecker on GitHub. OK, as I'm refactoring, there's a few problems: 1. There's a lot of conversion on interface boundaries between `size_t`, `long`, and `SHORT` based versions of representations of rectangles, points, and sizes. 2. There's a bunch of places where we pass a line,column pair as two size_ts because there isn't a size_t version of `SIZE`. It should probably be passed as one sensible struct because the ordering of these parameters keeps getting reversed too. 3. Many of our conversions use an assorted mix of either C-cast, static_cast, gsl::narrow, gsl::narrow_cast, or intsafe.h. 4. We don't distinguish points from sizes in console code. They're both `COORD`. x is width and y is height for size usage. We're also going to want to be able to expand most of our values to reach an "infinite" scrollback. My proposal here would be: - In the `types` library, we should create: 1. Point - Contains `x` and `y` like Windows SDK 'POINT' but is `size_t`. - Has conversions to Windows SDK `POINT` safely. - Has conversions to Console's `COORD` safely. 2. Size - Contains 'cx' and 'cy' like Windows SDK 'SIZE' but is `size_t`. - Has conversions to Windows SDK `SIZE` safely. - Has conversions to Console's `COORD` safely. 3. Rectangle - Contains a `Point` and a `Size`. - Has conversions to Windows SDK `RECT` safely. - Has conversions to Console's `SMALL_RECT` safely. 4. Viewport - Update this guy to be happy with conversions in and out of the above 3. Then walk through the code and update to use these things.
Author
Owner

@carlos-zamora commented on GitHub (Jan 30, 2020):

Specific reference from UiaTextRange refactor (PR #4018):
https://github.com/microsoft/terminal/pull/4018/files#r372678719

@carlos-zamora commented on GitHub (Jan 30, 2020): Specific reference from UiaTextRange refactor (PR #4018): https://github.com/microsoft/terminal/pull/4018/files#r372678719
Author
Owner

@miniksa commented on GitHub (Mar 13, 2020):

til::size was implemented in #4850.
til::point was implemented in #4897.
til::rectangle was implemented in #4912.

To replace Viewport, we will still require...

  • Translation of til::rectangle
  • Scaling of til::rectangle
  • Iteration in "walk" directions
  • Move helpers that will translate the contents of a buffer that is analogous to a til::rectangle representation and move it in-place using the "walk" directions for maximum efficiency. (For Scrolling data in storage or rendering buffers.)

This issue also stays open to track the replacements:

  • Of Viewport usages with til::rectangle usages
  • Of RECT and SMALL_RECT usages with til::rectangle except declarations on API boundaries
  • Of COORD and POINT with til::point except declarations on API boundaries
  • Of COORD and SIZE with til::size except declarations on API boundaries
@miniksa commented on GitHub (Mar 13, 2020): `til::size` was implemented in #4850. `til::point` was implemented in #4897. `til::rectangle` was implemented in #4912. To replace `Viewport`, we will still require... - Translation of `til::rectangle` - Scaling of `til::rectangle` - Iteration in "walk" directions - Move helpers that will translate the contents of a buffer that is analogous to a `til::rectangle` representation and move it in-place using the "walk" directions for maximum efficiency. (For Scrolling data in storage or rendering buffers.) This issue also stays open to track the replacements: - Of `Viewport` usages with `til::rectangle` usages - Of `RECT` and `SMALL_RECT` usages with `til::rectangle` except declarations on API boundaries - Of `COORD` and `POINT` with `til::point` except declarations on API boundaries - Of `COORD` and `SIZE` with `til::size` except declarations on API boundaries
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5644