-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCxMath.cpp
More file actions
32 lines (29 loc) · 895 Bytes
/
Copy pathCxMath.cpp
File metadata and controls
32 lines (29 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// CxMath.cpp
// cppimage
//
// Created by Graham Pentheny on 11/10/12.
// Copyright (c) 2012 Graham Pentheny. All rights reserved.
//
#include "CxMath.h"
namespace CppImage
{
//////////////////////////////////////////////////////////////////////////
/// Returns the intersection crossection with another rectangle or a 0 area
/// rectangle if there is no overlap.
/// @param[in] inRect
Rect2 Rect2::CrossSection(const Rect2& inRect) const
{
Rect2 crossSection(
max(botLeft.x, inRect.botLeft.x),
max(botLeft.y, inRect.botLeft.y),
min(topRight.x, inRect.topRight.x),
min(topRight.y, inRect.topRight.y));
if (crossSection.botLeft.x <= crossSection.topRight.x && crossSection.botLeft.y <= crossSection.topRight.y)
{
return crossSection;
}
// The resulting rect is not valid, so there is no overlap.
return Rect2();
}
}