Files
envi-code/SourceCode/Code2026/tg_shs/shs_subgeLib/TPGeExtend.cpp
T
2026-09-28 15:28:50 +08:00

134 lines
2.8 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TPGeExtend Àà
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TPGeExtend ¶¨Òå
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TPGeExtend.h"
TPGeExtend::TPGeExtend(double min,double max):m_fMin(min),m_fMax(max)
{
}
TPGeExtend::~TPGeExtend()
{
}
void TPGeExtend::SetRange(double min,double max)
{
m_fMin = min;
m_fMax = max;
}
double TPGeExtend::GetMin() const
{
return m_fMin;
}
double TPGeExtend::GetMax() const
{
return m_fMax;
}
double TPGeExtend::GetLength() const
{
return m_fMax - m_fMin;
}
double TPGeExtend::GetCenter() const
{
return (m_fMax + m_fMin) / 2;
}
bool TPGeExtend::IsValid() const
{
return UPEQUAL_ZEROD(GetLength());
}
bool TPGeExtend::operator == (const TPGeExtend& ext) const
{
return EQUALD(GetMin(),ext.GetMin()) && EQUALD(GetMax(),ext.GetMax());
}
bool TPGeExtend::operator != (const TPGeExtend& ext) const
{
return !(*this == ext);
}
bool TPGeExtend::operator > (const TPGeExtend& ext) const
{
return UP_ZEROD(GetMin() - ext.GetMax());
}
bool TPGeExtend::operator >= (const TPGeExtend& ext) const
{
return UPEQUAL_ZEROD(GetMin() - ext.GetMax());
}
bool TPGeExtend::operator < (const TPGeExtend& ext) const
{
return ext > *this;
}
bool TPGeExtend::operator <= (const TPGeExtend& ext) const
{
return ext >= *this;
}
bool TPGeExtend::IsInside(double x) const
{
return UP_ZEROD(x - m_fMin) && DOWN_ZEROD(x - m_fMax);
}
bool TPGeExtend::IsInside(const TPGeExtend& ext) const
{
return DOWN_ZEROD(GetMin() - ext.GetMin()) && UP_ZEROD(GetMax() - ext.GetMax());
}
bool TPGeExtend::IsInclude(double x) const
{
return UPEQUAL_ZEROD(x - m_fMin) && DOWNEQUAL_ZEROD(x - m_fMax);
}
bool TPGeExtend::IsInclude(const TPGeExtend& ext) const
{
return DOWNEQUAL_ZEROD(GetMin() - ext.GetMin()) && UPEQUAL_ZEROD(GetMax() - ext.GetMax());
}
bool TPGeExtend::IsIntersect(const TPGeExtend& ext) const
{
return !(*this > ext) && !(*this < ext);
}
bool TPGeExtend::IsConnect(const TPGeExtend&ext) const
{
return !(*this >= ext) && !(*this <= ext);
}
TPGeExtend TPGeExtend::operator & (const TPGeExtend& ext) const
{
return TPGeExtend(Max2(GetMin(),ext.GetMin()),Min2(GetMax(),ext.GetMax()));
}
TPGeExtend TPGeExtend::operator + (const TPGeExtend &ext) const
{
return TPGeExtend(Min2(GetMin(),ext.GetMin()),Max2(GetMax(),ext.GetMax()));
}
TPGeExtend& TPGeExtend::operator += (const TPGeExtend& ext)
{
SetRange(Min2(GetMin(),ext.GetMin()),Max2(GetMax(),ext.GetMax()));
return *this;
}
void TPGeExtend::Inflate(double d)
{
m_fMin -= d;
m_fMax += d;
}