#include <stdio.h>
typedef struct point {
int x, y;
} POINT;
typedef struct rect {
int left, top, right, bottom;
} RECT;
void Swap(int *x, int *y);
void PrintRect(const char* title, const RECT *rt); //직사각형 정보를 출력
int NormalizeRect(int x, int y);
int IsPointInRect(RECT rc, POINT pt);
int main(void)
{
RECT rect1= { 0 };
POINT pt;
printf("좌상단점/우하단점의 좌표를 입력하세요(left, top, right, bottom 순)\n");
scanf_s("%d %d %d %d", &rect1.left, &rect1.top, &rect1.right, &rect1.bottom);
/*printf("입력된 직사각형", &rect1);
if (NormalizeRect())
{
PrintRect("정규화된 직사각형", &rect1);
}*/
printf("한점의 좌표를 입력하세요(x,y) : ");
scanf_s("%d %d", &pt.x, &pt.y);
printf("(%d, %d)는 ", pt.x, pt.y);
if (IsPointInRect(rect1, pt) ==1)
printf("직사각형 내부에 있습니다.\n");
else
printf("직사각형 외부에 있습니다.\n");
return 0;
}
void Swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
void PrintRect(const char *title, const RECT *rt)
{
printf("%s : 좌상단점 = (%d, %d), 우하단점 = (%d, %d)\n",
title, rt->left, rt->top, rt->right, rt->bottom);
}
/*int NormalizeRect(int x, int y)
{
int result = 0;
//
//
//
//
return result; // NormalizeRect 되면 1, 아니면 0을 리턴한다
}*/
int IsPointInRect(RECT rc, POINT pt)
{
if (rc.left <= pt.x && pt.x <= rc.right && pt.y <= rc.top && rc.bottom <= pt.y)
{
return 1;
}
return 0;
}
나머지는 다 이해했는데 이 정규화 원리를 도통 이해하지 못하겠습니다.
NormalizeRect 조건이
직사각형의 좌상단점(left, top)은 항상 우하단점인(right, bottom)보다 작거나 같아야하며
즉 left <= right, top <= bottom이 항상 성립해야합니다.
rect구조체를 인자로 전달해서
좌상단점이 우하단점의 좌표보다 작거나 같도록 만드는 NormalizeRect 함수를 정의해야하는데
도통 이해하지 못하겠습니다 원리설명좀 부탁드립니다.
니가 예제에 올린건 작거나 같도록 만드는게 아니라 작거나 같으면 true 아니면 false 를 리턴하는 검사함수인데?
검사함수와 정규화변환 함수를 구별해야지.