2 Commits 34dd5a3aa4 ... 7f62190e4e

Author SHA1 Message Date
  namark 7f62190e4e minor concession, 1 month ago
  namark b3b15771b3 kiss 1 month ago
3 changed files with 35 additions and 7 deletions
  1. 8 2
      source/simple/geom/algorithm.hpp
  2. 12 5
      source/simple/geom/segment.hpp
  3. 15 0
      unit_tests/segment.cpp

+ 8 - 2
source/simple/geom/algorithm.hpp

@@ -155,11 +155,17 @@ namespace simple::geom
 	}
 
 	template <typename T, size_t D, typename O>
+	[[nodiscard]] constexpr auto column(const vector<T,D,O>& one)
+	{
+		return one.transformed([](const auto &x) {return vector(x);}); // 1xD
+	}
+
+	template <typename T, size_t D, typename O>
 	[[nodiscard]] constexpr vector<vector<T,D,O>, D,O> expand(const vector<T,D,O>& one, const vector<T,D,O>& other)
 	{
 		const auto row = vector(one); // Dx1
-		const auto column = other.transformed([](const auto &x) {return vector(x);}); // 1xD
-		return row(column); // Dx1 * 1xD = DxD
+		const auto col = column(other); // 1xD
+		return row(col); // Dx1 * 1xD = DxD
 	}
 
 	//FIXME: don't think this actually works for rotation and such

+ 12 - 5
source/simple/geom/segment.hpp

@@ -15,7 +15,10 @@ namespace simple::geom
 		using range = support::range<Type>;
 
 		[[nodiscard]]
-		constexpr operator range() const
+		constexpr operator range() const { return to_range(); }
+
+		[[nodiscard]]
+		constexpr auto to_range() const
 		{
 			return range{position, position + size};
 		}
@@ -34,11 +37,15 @@ namespace simple::geom
 		AnchorType anchor;
 
 		[[nodiscard]]
-		constexpr operator typename base::range() const
+		// NOTE: maybe return range<common type <Type, AnchorType>> if range<Type> doesn't work??
+		// gotta have an actual use case to make it worth it though
+		constexpr operator typename base::range() const { return to_range(); }
+
+		[[nodiscard]]
+		constexpr auto to_range() const
 		{
-			auto lower = this->position -
-				static_cast<Type>(anchor * static_cast<AnchorType>(this->size));
-			return typename base::range{lower, lower + this->size};
+			auto lower = this->position - anchor * this->size;
+			return support::range{lower, lower + this->size};
 		}
 
 		[[nodiscard]]

+ 15 - 0
unit_tests/segment.cpp

@@ -166,10 +166,25 @@ void Conversions()
 	assert(( ra == anchored_rect::range{vector{6,6}, {16,16}}) );
 }
 
+void IfItWorksItWorks()
+{
+	anchored_segment ar{ segment{vector{11.f,12.f}, vector{13.f,14.f}}, 0.5f };
+	auto ra = decltype(ar)::range{};
+
+	ra = ar;
+	assert(( ra == decltype(ra){vector{7.5f, 8.f}, vector{18.5f, 20.f}} ));
+
+	ar = anchored_segment{ segment{vector{11.f,12.f}, vector{0.f,0.f}}, 0.5f };
+
+	ra = ar;
+	assert(( ra == decltype(ra){vector{-5.5f, -6.f}, vector{5.5f, 6.f}} ));
+}
+
 int main()
 {
 	Initialization();
 	Equality();
 	Conversions();
+	IfItWorksItWorks();
 	return 0;
 }