[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libgeometry/Range2d.h testsuite...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libgeometry/Range2d.h testsuite... |
Date: |
Fri, 08 Dec 2006 11:07:41 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 06/12/08 11:07:41
Modified files:
. : ChangeLog
libgeometry : Range2d.h
testsuite/libgeometry: Range2dTest.cpp
Log message:
* libgeometry/Range2d.h: implemented cast between range types,
with float=>{int,unsigned int} cast ensuring resulting range
is not smaller then original.
* testsuite/libgeometry/Range2dTest.cpp: added tests for
Range2d type cast.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1888&r2=1.1889
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/Range2d.h?cvsroot=gnash&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libgeometry/Range2dTest.cpp?cvsroot=gnash&r1=1.3&r2=1.4
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1888
retrieving revision 1.1889
diff -u -b -r1.1888 -r1.1889
--- ChangeLog 8 Dec 2006 10:10:17 -0000 1.1888
+++ ChangeLog 8 Dec 2006 11:07:40 -0000 1.1889
@@ -1,5 +1,13 @@
2006-12-08 Sandro Santilli <address@hidden>
+ * libgeometry/Range2d.h: implemented cast between range types,
+ with float=>{int,unsigned int} cast ensuring resulting range
+ is not smaller then original.
+ * testsuite/libgeometry/Range2dTest.cpp: added tests for
+ Range2d type cast.
+
+2006-12-08 Sandro Santilli <address@hidden>
+
* libgeometry/Range2d.h: changed scale() functions to take a float,
to allow for fractional scales; implemented specializations
for int and unsigned int types to ensure rounding doesn't make
Index: libgeometry/Range2d.h
===================================================================
RCS file: /sources/gnash/gnash/libgeometry/Range2d.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- libgeometry/Range2d.h 8 Dec 2006 10:10:17 -0000 1.6
+++ libgeometry/Range2d.h 8 Dec 2006 11:07:41 -0000 1.7
@@ -19,7 +19,7 @@
//
-/* $Id: Range2d.h,v 1.6 2006/12/08 10:10:17 strk Exp $ */
+/* $Id: Range2d.h,v 1.7 2006/12/08 11:07:41 strk Exp $ */
#ifndef GNASH_RANGE2D_H
#define GNASH_RANGE2D_H
@@ -80,12 +80,22 @@
T scaleMin(T min, float scale)
{
- return (T)((float)min*scale);
+ return roundMin((float)min*scale);
}
T scaleMax(T max, float scale)
{
- return (T)((float)max*scale);
+ return roundMax((float)max*scale);
+ }
+
+ T roundMin(float v)
+ {
+ return (T)v;
+ }
+
+ T roundMax(float v)
+ {
+ return (T)v;
}
public:
@@ -173,6 +183,22 @@
// .. or should we raise an exception .. ?
}
+ /// Templated copy constructor, for casting between range types
+ template <typename U>
+ Range2d(const Range2d<U>& from)
+ {
+ if ( from.isWorld() ) {
+ setWorld();
+ } else if ( from.isNull() ) {
+ setNull();
+ } else {
+ _xmin = roundMin(from.getMinX());
+ _ymin = roundMin(from.getMinY());
+ _xmax = roundMax(from.getMaxX());
+ _ymax = roundMax(from.getMaxY());
+ }
+ }
+
/// Returns true if this is the NULL Range2d
bool isNull() const
{
@@ -706,48 +732,47 @@
}
-/// Specialization of minimum value scale for int type.
+/// Specialization of minimum value rounding for int type.
//
-/// Use floor when rounding values back
+/// Use floor.
///
template <> int
-Range2d<int>::scaleMin(int min, float factor)
+Range2d<int>::roundMin(float min)
{
- return (int)(floor((float)min*factor));
+ return (int)floor(min);
}
-/// Specialization of minimum value scale for unsigned int type.
+/// Specialization of minimum value rounding for unsigned int type.
//
-/// Use floor when rounding values back
+/// Use floor.
///
template <> unsigned int
-Range2d<unsigned int>::scaleMin(unsigned int min, float factor)
+Range2d<unsigned int>::roundMin(float min)
{
- return (unsigned int)(floor((float)min*factor));
+ return (unsigned int)floor(min);
}
-/// Specialization of maximum value scale for int type.
+/// Specialization of maximum value rounding for int type.
//
-/// Use ceil when rounding values back
+/// Use ceil.
///
template <> int
-Range2d<int>::scaleMax(int max, float factor)
+Range2d<int>::roundMax(float max)
{
- return (int)(ceil((float)max*factor));
+ return (int)ceil(max);
}
-/// Specialization of maximum value scale for unsigned int type.
+/// Specialization of maximum value rounding for unsigned int type.
//
-/// Use ceil when rounding values back
+/// Use ceil.
///
template <> unsigned int
-Range2d<unsigned int>::scaleMax(unsigned int max, float factor)
+Range2d<unsigned int>::roundMax(float max)
{
- return (unsigned int)(ceil((float)max*factor));
+ return (unsigned int)ceil((float)max);
}
-
} // namespace gnash::geometry
} // namespace gnash
Index: testsuite/libgeometry/Range2dTest.cpp
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libgeometry/Range2dTest.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- testsuite/libgeometry/Range2dTest.cpp 8 Dec 2006 10:10:17 -0000
1.3
+++ testsuite/libgeometry/Range2dTest.cpp 8 Dec 2006 11:07:41 -0000
1.4
@@ -263,5 +263,13 @@
Range2d<unsigned short>(2, 2, 5, 5)),
true
);
+
+ //
+ // Test Range2d<float> to Range2d<int> cast
+ //
+
+ check_equals( (Range2d<int>)Range2d<float>(-0.1, 0.1, 10.1, 10.2),
+ Range2d<int>(-1, 0, 11, 11) );
+
}