改造一些

This commit is contained in:
2026-08-12 00:06:44 +08:00
parent aca480d988
commit abd1b595c7
57 changed files with 883 additions and 732 deletions
+64 -41
View File
@@ -9,6 +9,26 @@
#include <vector>
namespace renderive {
namespace {
template <class Axis_Type>
concept Legacy_Axis_Property_Api = requires(Axis_Type& axis) {
axis.x();
axis.set_x(0);
axis.coord_range();
axis.set_coord_range(Range{});
};
template <class Axis_Type>
concept Legacy_Time_Axis_Property_Api = requires(Axis_Type& axis) {
axis.visible_time_point_count();
axis.set_visible_time_point_count(1);
axis.time_format();
axis.set_time_format({});
};
static_assert(!Legacy_Axis_Property_Api<Axis>);
static_assert(!Legacy_Axis_Property_Api<Time_Axis>);
static_assert(!Legacy_Time_Axis_Property_Api<Time_Axis>);
TEST(Renderive_Core2, RootIdentityAndRefreshDiagnosticsComeFromKernelState) {
Plot_Core plot;
plot.init();
@@ -104,10 +124,10 @@ TEST(Renderive_Core2, KernelSceneRendersBusinessObjectsIntoBlend2DFrame) {
.set_pixel_length(270)
.set_coord_range({88.0, 108.0})
.build();
frequency_axis->set_locale({','});
frequency_axis->set_label_rotation_degrees(15);
frequency_axis->set<&Axis_Base_Properties::locale>(Number_Locale{','});
frequency_axis->set<&Axis_Base_Properties::label_rotation_degrees>(15);
EXPECT_EQ(frequency_axis->tick_label(88.5), "88,5 Hz");
frequency_axis->set_label_precision(4);
frequency_axis->set<&Axis_Properties::precision>(4);
EXPECT_EQ(frequency_axis->tick_label(1'234'567.0), "1,2346 MHz");
auto power_axis = Axis::Builder(root, Orientation::Vertical)
.set_x(32)
@@ -147,14 +167,14 @@ TEST(Renderive_Core2, KernelSceneRendersBusinessObjectsIntoBlend2DFrame) {
EXPECT_FALSE(plot.render_frame());
spectrum->update_samples(samples);
EXPECT_TRUE(plot.render_frame());
frequency_axis->set_use_wheel(true);
const Range before_zoom = frequency_axis->coord_range();
frequency_axis->set<&Axis_Properties::wheel>(true);
const Range before_zoom = frequency_axis->get<&Axis_Properties::coordinates>();
Wheel_Event wheel;
wheel.position = {160.0, 150.0};
wheel.angle_delta_y = 120.0;
plot.dispatch_event(wheel);
EXPECT_TRUE(wheel.is_accepted());
EXPECT_LT(frequency_axis->coord_range().size(), before_zoom.size());
EXPECT_LT(frequency_axis->get<&Axis_Properties::coordinates>().size(), before_zoom.size());
EXPECT_TRUE(plot.render_frame());
plot.remove_renderable(spectrum);
EXPECT_TRUE(plot.render_frame(true));
@@ -172,9 +192,8 @@ TEST(Renderive_Core2, TimeAxisUsesOneFontStateAndFormatsConfiguredLabels) {
ASSERT_TRUE(axis);
const int tick = axis->append_time(Time_Of_Day{3'723'045});
EXPECT_EQ(axis->tick_label(tick), "01-02-03.045");
EXPECT_EQ(axis->font(), (Font{18.0, 700, true}));
EXPECT_EQ(axis->unit_text_font(), axis->font());
EXPECT_EQ(axis->tick_label_spacing_px(), 17);
EXPECT_EQ(axis->get<&Axis_Base_Properties::unit_text_font>(), (Font{18.0, 700, true}));
EXPECT_EQ(axis->get<&Time_Axis_Properties::tick_label_spacing_px>(), 17);
}
TEST(Renderive_Core2, PerformanceOverlayConsumesKernelFrameDiagnostics) {
Plot_Core plot;
@@ -260,32 +279,35 @@ TEST(Renderive_Core2, RetainedAxisAndTimeAxisApisRoundTripWithoutWebAdapters) {
.set_use_drag(true)
.build();
ASSERT_TRUE(axis);
EXPECT_EQ(axis->x(), 31);
EXPECT_EQ(axis->y(), 17);
EXPECT_EQ(axis->orientation(), Orientation::Vertical);
EXPECT_EQ(axis->pixel_length(), 240U);
EXPECT_EQ(axis->tick_length(), 13);
EXPECT_EQ(axis->sub_tick_length(), 7);
EXPECT_EQ(axis->color(), (Color{10, 20, 30, 255}));
EXPECT_EQ(axis->unit_text(), "dB");
EXPECT_EQ(axis->unit_text_font(), (Font{15.0, 650, true}));
EXPECT_EQ(axis->unit_text_pen(), (Pen{Color{40, 50, 60, 255}, 2.0}));
EXPECT_EQ(axis->unit_text_background_brush(),
EXPECT_EQ(axis->get<&Axis_Base_Properties::x>(), 31);
EXPECT_EQ(axis->get<&Axis_Base_Properties::y>(), 17);
EXPECT_EQ(axis->get<&Axis_Base_Properties::orientation>(), Orientation::Vertical);
EXPECT_EQ(axis->get<&Axis_Base_Properties::pixel_length>(), 240U);
EXPECT_EQ(axis->get<&Axis_Base_Properties::tick_length>(), 13);
EXPECT_EQ(axis->get<&Axis_Base_Properties::sub_tick_length>(), 7);
EXPECT_EQ(axis->get<&Axis_Base_Properties::color>(), (Color{10, 20, 30, 255}));
EXPECT_EQ(axis->get<&Axis_Base_Properties::unit_text>(), "dB");
EXPECT_EQ(axis->get<&Axis_Base_Properties::unit_text_font>(), (Font{15.0, 650, true}));
EXPECT_EQ(axis->get<&Axis_Base_Properties::unit_text_pen>(), (Pen{Color{40, 50, 60, 255}, 2.0}));
EXPECT_EQ(axis->get<&Axis_Base_Properties::unit_text_background_brush>(),
(Brush{Color{3, 4, 5, 255}, Brush_Style::Solid}));
EXPECT_EQ(axis->label_rotation_degrees(), 27);
EXPECT_EQ(axis->coord_range(), (Range{-120.0, -20.0}));
EXPECT_EQ(axis->label_precision(), 4);
EXPECT_TRUE(axis->use_wheel());
EXPECT_TRUE(axis->use_drag());
axis->set_locale({','});
axis->set_coord_start(-100.0);
axis->set_coord_length(80.0);
EXPECT_EQ(axis->locale(), (Number_Locale{','}));
EXPECT_EQ(axis->coord_range(), (Range{-100.0, -20.0}));
EXPECT_DOUBLE_EQ(axis->pixel_to_coord(axis->coord_to_pixel(-60.0)), -60.0);
EXPECT_GT(axis->pixel_sample_count(), 0);
EXPECT_GT(axis->tick_step(axis->coord_range()), 0.0);
EXPECT_GE(axis->sub_tick_count(axis->tick_step(axis->coord_range())), 0);
EXPECT_EQ(axis->get<&Axis_Base_Properties::label_rotation_degrees>(), 27);
EXPECT_EQ(axis->get<&Axis_Properties::coordinates>(), (Range{-120.0, -20.0}));
EXPECT_EQ(axis->get<&Axis_Properties::precision>(), 4);
EXPECT_TRUE(axis->get<&Axis_Properties::wheel>());
EXPECT_TRUE(axis->get<&Axis_Properties::drag>());
EXPECT_THROW(axis->set<&Axis_Properties::precision>(13), std::out_of_range);
EXPECT_THROW(axis->set<&Axis_Properties::coordinates>(Range{1.0, 1.0}),
std::invalid_argument);
axis->set<&Axis_Base_Properties::locale>(Number_Locale{','});
axis->set<&Axis_Properties::coordinates>(Range{-100.0, -20.0});
EXPECT_EQ(axis->get<&Axis_Base_Properties::locale>(), (Number_Locale{','}));
EXPECT_EQ(axis->get<&Axis_Properties::coordinates>(), (Range{-100.0, -20.0}));
const Axis_Transform numeric_transform = axis->transform();
EXPECT_DOUBLE_EQ(numeric_transform.pixel_to_coord(numeric_transform.coord_to_pixel(-60.0)), -60.0);
EXPECT_GT(static_cast<int>(numeric_transform.pixel_length) + 1, 0);
EXPECT_GT(axis->tick_step(numeric_transform.coordinate_range), 0.0);
EXPECT_GE(axis->sub_tick_count(axis->tick_step(numeric_transform.coordinate_range)), 0);
const auto time_axis = Time_Axis::Builder(root, Orientation::Horizontal)
.set_x(12)
.set_y(280)
@@ -299,11 +321,12 @@ TEST(Renderive_Core2, RetainedAxisAndTimeAxisApisRoundTripWithoutWebAdapters) {
ASSERT_TRUE(time_axis);
const int first = time_axis->append_time({3'723'004});
const int second = time_axis->append_time({3'724'005});
EXPECT_EQ(time_axis->visible_time_point_count(), 32);
EXPECT_EQ(time_axis->tick_label_spacing_px(), 19);
EXPECT_EQ(time_axis->time_format(), "hh:mm:ss.zzz");
EXPECT_EQ(time_axis->font(), (Font{16.0, 700, true}));
EXPECT_TRUE(time_axis->newest_at_axis_start());
EXPECT_EQ(time_axis->get<&Time_Axis_Properties::visible_count>(), 32);
EXPECT_EQ(time_axis->get<&Time_Axis_Properties::tick_label_spacing_px>(), 19);
EXPECT_EQ(time_axis->get<&Time_Axis_Properties::format>(), "hh:mm:ss.zzz");
EXPECT_EQ(time_axis->get<&Axis_Base_Properties::unit_text_font>(), (Font{16.0, 700, true}));
EXPECT_TRUE(time_axis->get<&Time_Axis_Properties::newest_at_start>());
EXPECT_THROW(time_axis->set<&Time_Axis_Properties::visible_count>(1), std::out_of_range);
EXPECT_EQ(time_axis->time_point_count(), 2U);
EXPECT_EQ(time_axis->tick_to_time(first), (Time_Of_Day{3'723'004}));
EXPECT_EQ(time_axis->tick_to_time(second), (Time_Of_Day{3'724'005}));
@@ -542,8 +565,8 @@ TEST(Renderive_Core2, RetainedSelectionAndConstellationApisDriveInteractionAndLa
constellation->append_point({-0.5, 0.5});
EXPECT_EQ(constellation->point_count(), 2U);
constellation->fit_square_to_axes();
EXPECT_EQ(horizontal->coord_range(), (Range{-3.0, 3.0}));
EXPECT_EQ(vertical->coord_range(), (Range{3.0, -3.0}));
EXPECT_EQ(horizontal->get<&Axis_Properties::coordinates>(), (Range{-3.0, 3.0}));
EXPECT_EQ(vertical->get<&Axis_Properties::coordinates>(), (Range{3.0, -3.0}));
EXPECT_TRUE(plot.render_frame(true));
}
TEST(Renderive_Core2, PlottablePropertiesPublishOnlyAtFrameBoundary) {