UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ImageDimensions.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "VectorTypes.h"
6#include "IntVectorTypes.h"
7
8namespace UE
9{
10namespace Geometry
11{
12
18{
19protected:
22
23public:
28
31 {
32 check(WidthIn >= 0 && HeightIn >= 0);
33 Width = WidthIn;
35 }
36
38 int32 GetWidth() const { return Width; }
40 int32 GetHeight() const { return Height; }
42 int64 Num() const { return (int64)Width * (int64)Height; }
43
45 bool IsSquare() const { return Width == Height; }
46
48 bool IsValidCoords(const FVector2i& Coords) const
49 {
50 return (Coords.X >= 0 && Coords.X < Width && Coords.Y >= 0 && Coords.Y < Height);
51 }
52
54 void Clamp(int32& X, int32& Y) const
55 {
56 X = FMath::Clamp(X, 0, Width - 1);
57 Y = FMath::Clamp(Y, 0, Height - 1);
58 }
59
61 void Clamp(FVector2i& Coords) const
62 {
63 Coords.X = FMath::Clamp(Coords.X, 0, Width - 1);
64 Coords.Y = FMath::Clamp(Coords.Y, 0, Height - 1);
65 }
66
69 {
70 return (int64) Y * Width + X;
71 }
72
74 int64 GetIndex(const FVector2i& Coords) const
75 {
76 checkSlow(IsValidCoords(Coords));
77 return ((int64)Coords.Y * (int64)Width) + (int64)Coords.X;
78 }
79
81 int64 GetIndexMirrored(const FVector2i& Coords, bool bFlipX, bool bFlipY) const
82 {
83 checkSlow(IsValidCoords(Coords));
84 int64 UseX = (bFlipX) ? (Width - 1 - Coords.X) : Coords.X;
85 int64 UseY = (bFlipY) ? (Height - 1 - Coords.Y) : Coords.Y;
86 return (UseY * (int64)Width) + UseX;
87 }
88
90 FVector2i GetCoords(int64 LinearIndex) const
91 {
92 checkSlow(LinearIndex >= 0 && LinearIndex < Num());
93 return FVector2i((int32)(LinearIndex % (int64)Width), (int32)(LinearIndex / (int64)Width));
94 }
95
98 {
99 return FVector2d(1.0 / (double)Width, 1.0 / (double)Height);
100 }
101
103 FVector2d GetTexelUV(const FVector2i& Coords) const
104 {
105 return FVector2d(
106 ((double)Coords.X + 0.5) / (double)Width,
107 ((double)Coords.Y + 0.5) / (double)Height);
108 }
109
111 FVector2d GetTexelUV(int64 LinearIndex) const
112 {
113 return GetTexelUV(GetCoords(LinearIndex));
114 }
115
118 {
119 FVector2d TexelDistance = P - Q;
122 return TexelDistance;
123 }
124
127 {
130 return FVector2i(X, Y);
131 }
132
135 {
136 double PixelX = (UVPosition.X * (double)Width /*- 0.5*/);
137 double PixelY = (UVPosition.Y * (double)Height /*- 0.5*/);
139 }
140
142 {
143 return Width == Other.Width && Height == Other.Height;
144 }
145
147 {
148 return !(*this == Other);
149 }
150};
151
152
153} // end namespace UE::Geometry
154} // end namespace UE
155
156
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define X(Name, Desc)
Definition FormatStringSan.h:47
UE::Math::TVector2< double > FVector2d
Definition MathFwd.h:61
Definition ImageDimensions.h:18
bool operator==(const FImageDimensions &Other) const
Definition ImageDimensions.h:141
int32 GetHeight() const
Definition ImageDimensions.h:40
bool IsValidCoords(const FVector2i &Coords) const
Definition ImageDimensions.h:48
void Clamp(int32 &X, int32 &Y) const
Definition ImageDimensions.h:54
FVector2d GetTexelUV(const FVector2i &Coords) const
Definition ImageDimensions.h:103
int64 Num() const
Definition ImageDimensions.h:42
FImageDimensions(int32 WidthIn=0, int32 HeightIn=0)
Definition ImageDimensions.h:24
bool IsSquare() const
Definition ImageDimensions.h:45
FVector2d GetTexelSize() const
Definition ImageDimensions.h:97
FVector2d GetTexelUV(int64 LinearIndex) const
Definition ImageDimensions.h:111
int32 GetWidth() const
Definition ImageDimensions.h:38
void Clamp(FVector2i &Coords) const
Definition ImageDimensions.h:61
int32 Height
Definition ImageDimensions.h:21
int32 Width
Definition ImageDimensions.h:20
FVector2i GetCoords(int64 LinearIndex) const
Definition ImageDimensions.h:90
FVector2d GetTexelDistance(const FVector2d &P, const FVector2d Q) const
Definition ImageDimensions.h:117
void SetDimensions(int32 WidthIn, int32 HeightIn)
Definition ImageDimensions.h:30
bool operator!=(const FImageDimensions &Other) const
Definition ImageDimensions.h:146
int64 GetIndex(const FVector2i &Coords) const
Definition ImageDimensions.h:74
int64 GetIndex(int32 X, int32 Y) const
Definition ImageDimensions.h:68
FVector2i UVToCoords(const FVector2d &UVPosition) const
Definition ImageDimensions.h:134
int64 GetIndexMirrored(const FVector2i &Coords, bool bFlipX, bool bFlipY) const
Definition ImageDimensions.h:81
FVector2i PixelToCoords(const FVector2d &PixelPosition) const
Definition ImageDimensions.h:126
Definition AdvancedWidgetsModule.cpp:13
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
Definition IntVectorTypes.h:20
int32 X
Definition IntVectorTypes.h:25
int32 Y
Definition IntVectorTypes.h:25
T X
Definition Vector2D.h:49