Removed Point::scale(),translate(),coincides_with(),distance_to(),

distance_to_squared(),perp_distance_to(),negative(),vector_to(),
translate(), distance_to() etc,
replaced with the Eigen equivalents.
This commit is contained in:
bubnikv 2018-08-17 14:14:24 +02:00
parent 3b89717149
commit 1ba64da3fe
45 changed files with 526 additions and 792 deletions

View file

@ -34,11 +34,11 @@ void Bed_2D::repaint()
auto cbb = BoundingBoxf(Pointf(0, 0),Pointf(cw, ch));
// leave space for origin point
cbb.min.translate(4, 0);
cbb.max.translate(-4, -4);
cbb.min.x() += 4;
cbb.max -= Vec2d(4., 4.);
// leave space for origin label
cbb.max.translate(0, -13);
cbb.max.y() -= 13;
// read new size
cw = cbb.size().x();
@ -113,7 +113,7 @@ void Bed_2D::repaint()
dc.DrawLine(wxPoint(origin_px.x(), origin_px.y()), wxPoint(x_end.x(), x_end.y()));
for (auto angle : { -arrow_angle, arrow_angle }){
auto end = x_end;
end.translate(-arrow_len, 0);
end.x() -= arrow_len;
end.rotate(angle, x_end);
dc.DrawLine(wxPoint(x_end.x(), x_end.y()), wxPoint(end.x(), end.y()));
}
@ -123,7 +123,7 @@ void Bed_2D::repaint()
dc.DrawLine(wxPoint(origin_px.x(), origin_px.y()), wxPoint(y_end.x(), y_end.y()));
for (auto angle : { -arrow_angle, arrow_angle }) {
auto end = y_end;
end.translate(0, +arrow_len);
end.y() += arrow_len;
end.rotate(angle, y_end);
dc.DrawLine(wxPoint(y_end.x(), y_end.y()), wxPoint(end.x(), end.y()));
}
@ -157,9 +157,7 @@ void Bed_2D::repaint()
// convert G - code coordinates into pixels
Point Bed_2D::to_pixels(Pointf point){
auto p = Pointf(point);
p.scale(m_scale_factor);
p.translate(m_shift);
auto p = point * m_scale_factor + m_shift;
return Point(p.x(), GetSize().GetHeight() - p.y());
}
@ -178,10 +176,7 @@ void Bed_2D::mouse_event(wxMouseEvent event){
// convert pixels into G - code coordinates
Pointf Bed_2D::to_units(Point point){
auto p = Pointf(point.x(), GetSize().GetHeight() - point.y());
p.translate(m_shift.negative());
p.scale(1 / m_scale_factor);
return p;
return (Pointf(point.x(), GetSize().GetHeight() - point.y()) - m_shift) * (1. / m_scale_factor);
}
void Bed_2D::set_pos(Pointf pos){

View file

@ -929,7 +929,7 @@ static void thick_lines_to_indexed_vertex_array(
bool is_closing = closed && is_last;
Vectorf v = Vectorf::new_unscale(line.vector());
v.scale(inv_len);
v *= inv_len;
Pointf a = Pointf::new_unscale(line.a);
Pointf b = Pointf::new_unscale(line.b);
@ -941,16 +941,16 @@ static void thick_lines_to_indexed_vertex_array(
double dist = 0.5 * width; // scaled
double dx = dist * v.x();
double dy = dist * v.y();
a1.translate(+dy, -dx);
a2.translate(-dy, +dx);
b1.translate(+dy, -dx);
b2.translate(-dy, +dx);
a1 += Vectorf(+dy, -dx);
a2 += Vectorf(-dy, +dx);
b1 += Vectorf(+dy, -dx);
b2 += Vectorf(-dy, +dx);
}
// calculate new XY normals
Vector n = line.normal();
Vectorf3 xy_right_normal = Vectorf3::new_unscale(n.x(), n.y(), 0);
xy_right_normal.scale(inv_len);
xy_right_normal *= inv_len;
int idx_a[4];
int idx_b[4];
@ -994,7 +994,7 @@ static void thick_lines_to_indexed_vertex_array(
} else {
// Continuing a previous segment.
// Share left / right vertices if possible.
double v_dot = dot(v_prev, v);
double v_dot = v_prev.dot(v);
bool sharp = v_dot < 0.707; // sin(45 degrees)
if (sharp) {
if (!bottom_z_different)
@ -1023,8 +1023,8 @@ static void thick_lines_to_indexed_vertex_array(
Geometry::ray_ray_intersection(b1_prev, v_prev, a1, v, intersection);
a1 = intersection;
a2 = 2. * a - intersection;
assert(length(a1.vector_to(a)) < width);
assert(length(a2.vector_to(a)) < width);
assert((a - a1).norm() < width);
assert((a - a2).norm() < width);
float *n_left_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[LEFT ] * 6;
float *p_left_prev = n_left_prev + 3;
float *n_right_prev = volume.vertices_and_normals_interleaved.data() + idx_prev[RIGHT] * 6;
@ -1035,7 +1035,7 @@ static void thick_lines_to_indexed_vertex_array(
p_right_prev[1] = float(a1.y());
xy_right_normal.x() += n_right_prev[0];
xy_right_normal.y() += n_right_prev[1];
xy_right_normal.scale(1. / length(xy_right_normal));
xy_right_normal *= 1. / xy_right_normal.norm();
n_left_prev [0] = float(-xy_right_normal.x());
n_left_prev [1] = float(-xy_right_normal.y());
n_right_prev[0] = float( xy_right_normal.x());
@ -1044,7 +1044,7 @@ static void thick_lines_to_indexed_vertex_array(
idx_a[RIGHT] = idx_prev[RIGHT];
}
}
else if (cross(v_prev, v) > 0.) {
else if (cross2(v_prev, v) > 0.) {
// Right turn. Fill in the right turn wedge.
volume.push_triangle(idx_prev[RIGHT], idx_a [RIGHT], idx_prev[TOP] );
volume.push_triangle(idx_prev[RIGHT], idx_prev[BOTTOM], idx_a [RIGHT] );
@ -1172,7 +1172,7 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
double height = heights[i];
double width = widths[i];
Vectorf3 unit_v = normalize(Vectorf3::new_unscale(line.vector()));
Vectorf3 unit_v = Vectorf3::new_unscale(line.vector()).normalized();
Vectorf3 n_top;
Vectorf3 n_right;
@ -1187,8 +1187,8 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
else
{
// generic segment
n_right = normalize(cross(unit_v, unit_positive_z));
n_top = normalize(cross(n_right, unit_v));
n_right = unit_v.cross(unit_positive_z).normalized();
n_top = n_right.cross(unit_v).normalized();
}
Vectorf3 rl_displacement = 0.5 * width * n_right;
@ -1247,9 +1247,9 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
{
// Continuing a previous segment.
// Share left / right vertices if possible.
double v_dot = dot(unit_v_prev, unit_v);
double v_dot = unit_v_prev.dot(unit_v);
bool is_sharp = v_dot < 0.707; // sin(45 degrees)
bool is_right_turn = dot(n_top_prev, cross(unit_v_prev, unit_v)) > 0.0;
bool is_right_turn = n_top_prev.dot(unit_v_prev.cross(unit_v)) > 0.0;
if (is_sharp)
{
@ -1272,7 +1272,7 @@ static void thick_lines_to_indexed_vertex_array(const Lines3& lines,
// At the crease angle of 45 degrees, the overshot at the corner will be less than (1-1/cos(PI/8)) = 8.2% over an arc.
// averages normals
Vectorf3 average_n_right = normalize(0.5 * (n_right + n_right_prev));
Vectorf3 average_n_right = 0.5 * (n_right + n_right_prev).normalized();
Vectorf3 average_n_left = -average_n_right;
Vectorf3 average_rl_displacement = 0.5 * width * average_n_right;

View file

@ -179,7 +179,7 @@ void BedShapePanel::set_shape(ConfigOptionPoints* points)
double avg_dist = 0;
for (auto pt: polygon.points)
{
double distance = center.distance_to(pt);
double distance = (pt - center).cast<double>().norm();
vertex_distances.push_back(distance);
avg_dist += distance;
}

View file

@ -1177,7 +1177,7 @@ void GLCanvas3D::Gizmos::update_hover_state(const GLCanvas3D& canvas, const Poin
// we currently use circular icons for gizmo, so we check the radius
if (it->second->get_state() != GLGizmoBase::On)
{
bool inside = length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size;
bool inside = (mouse_pos - Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size;
it->second->set_state(inside ? GLGizmoBase::Hover : GLGizmoBase::Off);
}
top_y += (tex_size + OverlayGapY);
@ -1201,7 +1201,7 @@ void GLCanvas3D::Gizmos::update_on_off_state(const GLCanvas3D& canvas, const Poi
float half_tex_size = 0.5f * tex_size;
// we currently use circular icons for gizmo, so we check the radius
if (length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size)
if ((mouse_pos - Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)
{
if ((it->second->get_state() == GLGizmoBase::On))
{
@ -1267,7 +1267,7 @@ bool GLCanvas3D::Gizmos::overlay_contains_mouse(const GLCanvas3D& canvas, const
float half_tex_size = 0.5f * tex_size;
// we currently use circular icons for gizmo, so we check the radius
if (length(Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size).vector_to(mouse_pos)) < half_tex_size)
if ((mouse_pos - Pointf(OverlayOffsetX + half_tex_size, top_y + half_tex_size)).norm() < half_tex_size)
return true;
top_y += (tex_size + OverlayGapY);
@ -3114,7 +3114,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
m_mouse.drag.start_position_3D = pos3d;
// Remember the shift to to the object center.The object center will later be used
// to limit the object placement close to the bed.
m_mouse.drag.volume_center_offset = pos3d.vector_to(volume_bbox.center());
m_mouse.drag.volume_center_offset = volume_bbox.center() - pos3d;
}
}
else if (evt.RightDown())
@ -3136,7 +3136,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
Pointf3 cur_pos = Linef3(_mouse_to_3d(pos, &z0), _mouse_to_3d(pos, &z1)).intersect_plane(m_mouse.drag.start_position_3D.z());
// Clip the new position, so the object center remains close to the bed.
cur_pos.translate(m_mouse.drag.volume_center_offset);
cur_pos += m_mouse.drag.volume_center_offset;
Point cur_pos2(scale_(cur_pos.x()), scale_(cur_pos.y()));
if (!m_bed.contains(cur_pos2))
{
@ -3144,10 +3144,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
cur_pos.x() = unscale(ip.x());
cur_pos.y() = unscale(ip.y());
}
cur_pos.translate(m_mouse.drag.volume_center_offset.negative());
cur_pos -= m_mouse.drag.volume_center_offset;
// Calculate the translation vector.
Vectorf3 vector = m_mouse.drag.start_position_3D.vector_to(cur_pos);
Vectorf3 vector = cur_pos - m_mouse.drag.start_position_3D;
// Get the volume being dragged.
GLVolume* volume = m_volumes.volumes[m_mouse.drag.move_volume_idx];
// Get all volumes belonging to the same group, if any.
@ -3169,11 +3169,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// Apply new temporary volume origin and ignore Z.
for (GLVolume* v : volumes)
{
Pointf3 origin = v->get_origin();
origin.translate(vector.x(), vector.y(), 0.0);
v->set_origin(origin);
}
v->set_origin(v->get_origin() + Vectorf3(vector.x(), vector.y(), 0.0));
m_mouse.drag.start_position_3D = cur_pos;
m_gizmos.refresh();
@ -3275,9 +3271,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
float z = 0.0f;
const Pointf3& cur_pos = _mouse_to_3d(pos, &z);
Pointf3 orig = _mouse_to_3d(m_mouse.drag.start_position_2D, &z);
Pointf3 camera_target = m_camera.target;
camera_target.translate(orig.vector_to(cur_pos).negative());
m_camera.target = camera_target;
m_camera.target += orig - cur_pos;
m_on_viewport_changed_callback.call();
@ -3571,11 +3565,11 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co
{
// project vertex on the plane perpendicular to camera forward axis
Pointf3 pos(v.x() - bb_center.x(), v.y() - bb_center.y(), v.z() - bb_center.z());
Pointf3 proj_on_plane = pos - dot(pos, forward) * forward;
Pointf3 proj_on_plane = pos - pos.dot(forward) * forward;
// calculates vertex coordinate along camera xy axes
coordf_t x_on_plane = dot(proj_on_plane, right);
coordf_t y_on_plane = dot(proj_on_plane, up);
coordf_t x_on_plane = proj_on_plane.dot(right);
coordf_t y_on_plane = proj_on_plane.dot(up);
max_x = std::max(max_x, margin_factor * std::abs(x_on_plane));
max_y = std::max(max_y, margin_factor * std::abs(y_on_plane));
@ -3653,7 +3647,7 @@ void GLCanvas3D::_camera_tranform() const
::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f); // pitch
::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw
Pointf3 neg_target = m_camera.target.negative();
Pointf3 neg_target = - m_camera.target;
::glTranslatef((GLfloat)neg_target.x(), (GLfloat)neg_target.y(), (GLfloat)neg_target.z());
}

View file

@ -235,13 +235,13 @@ void GLGizmoRotate::on_set_state()
void GLGizmoRotate::on_update(const Pointf& mouse_pos)
{
Vectorf orig_dir(1.0, 0.0);
Vectorf new_dir = normalize(mouse_pos - m_center);
coordf_t theta = ::acos(clamp(-1.0, 1.0, dot(new_dir, orig_dir)));
if (cross(orig_dir, new_dir) < 0.0)
Vectorf new_dir = (mouse_pos - m_center).normalized();
coordf_t theta = ::acos(clamp(-1.0, 1.0, new_dir.dot(orig_dir)));
if (cross2(orig_dir, new_dir) < 0.0)
theta = 2.0 * (coordf_t)PI - theta;
// snap
if (length(m_center.vector_to(mouse_pos)) < 2.0 * (double)m_radius / 3.0)
if ((mouse_pos - m_center).norm() < 2.0 * (double)m_radius / 3.0)
{
coordf_t step = 2.0 * (coordf_t)PI / (coordf_t)SnapRegionsCount;
theta = step * (coordf_t)std::round(theta / step);
@ -444,8 +444,8 @@ void GLGizmoScale::on_update(const Pointf& mouse_pos)
{
Pointf center(0.5 * (m_grabbers[1].center.x() + m_grabbers[0].center.x()), 0.5 * (m_grabbers[3].center.y() + m_grabbers[0].center.y()));
coordf_t orig_len = length(m_starting_drag_position - center);
coordf_t new_len = length(mouse_pos - center);
coordf_t orig_len = (m_starting_drag_position - center).norm();
coordf_t new_len = (mouse_pos - center).norm();
coordf_t ratio = (orig_len != 0.0) ? new_len / orig_len : 1.0;
m_scale = m_starting_scale * (float)ratio;

View file

@ -894,10 +894,7 @@ void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFl
const std::vector<double> &init_matrix = (config.option<ConfigOptionFloats>("wiping_volumes_matrix"))->values;
const std::vector<double> &init_extruders = (config.option<ConfigOptionFloats>("wiping_volumes_extruders"))->values;
#pragma warning(push)
#pragma warning(disable:4244) // disable Visual Studio's warning: conversion from 'double' to 'float', possible loss of data
WipingDialog dlg(parent,std::vector<float>(init_matrix.begin(),init_matrix.end()),std::vector<float>(init_extruders.begin(),init_extruders.end()));
#pragma warning(pop)
WipingDialog dlg(parent,cast<float>(init_matrix),cast<float>(init_extruders));
if (dlg.ShowModal() == wxID_OK) {
std::vector<float> matrix = dlg.get_matrix();

View file

@ -261,7 +261,7 @@ std::vector<float> Chart::get_ramming_speed(float sampling) const {
std::vector<std::pair<float,float>> Chart::get_buttons() const {
std::vector<std::pair<float, float>> buttons_out;
for (const auto& button : m_buttons)
buttons_out.push_back(std::make_pair(button.get_pos().m_x,button.get_pos().m_y));
buttons_out.push_back(std::make_pair(float(button.get_pos().m_x),float(button.get_pos().m_y)));
return buttons_out;
}