| 636 | } |
| 637 | |
| 638 | void FeatureBuilder::SerializeForMwm(SupportingData & data, serial::GeometryCodingParams const & params) const |
| 639 | { |
| 640 | data.m_buffer.clear(); |
| 641 | |
| 642 | PushBackByteSink<Buffer> sink(data.m_buffer); |
| 643 | FeatureParams(m_params).Write(sink); |
| 644 | |
| 645 | GeomType const type = m_params.GetGeomType(); |
| 646 | CHECK(type != GeomType::Undefined, ()); |
| 647 | if (type == GeomType::Point) |
| 648 | { |
| 649 | uint64_t const encoded = |
| 650 | coding::EncodePointDeltaAsUint(PointDToPointU(m_center, params.GetCoordBits()), params.GetBasePoint()); |
| 651 | CHECK_GREATER(bits::NumHiZeroBits64(encoded), 1, ()); |
| 652 | WriteVarUint(sink, encoded << 1); // Relations control bit |
| 653 | return; |
| 654 | } |
| 655 | |
| 656 | uint8_t const ptsCount = base::asserted_cast<uint8_t>(data.m_innerPts.size()); |
| 657 | uint8_t trgCount = base::asserted_cast<uint8_t>(data.m_innerTrg.size()); |
| 658 | if (trgCount > 0) |
| 659 | { |
| 660 | CHECK_GREATER(trgCount, 2, ()); |
| 661 | trgCount -= 2; |
| 662 | } |
| 663 | |
| 664 | { |
| 665 | BitWriter<PushBackByteSink<Buffer>> bitSink(sink); |
| 666 | |
| 667 | if (type == GeomType::Line) |
| 668 | { |
| 669 | bitSink.Write(ptsCount != 0 ? ptsCount : data.m_ptsMask, 4); |
| 670 | bitSink.Write(ptsCount == 0 ? 1 : 0, 1); |
| 671 | } |
| 672 | else |
| 673 | { |
| 674 | CHECK_EQUAL(type, GeomType::Area, ()); |
| 675 | bitSink.Write(trgCount != 0 ? trgCount : data.m_trgMask, 4); |
| 676 | bitSink.Write(trgCount == 0 ? 1 : 0, 1); |
| 677 | } |
| 678 | |
| 679 | // Relations control bit |
| 680 | bitSink.Write(0, 1); |
| 681 | } |
| 682 | |
| 683 | if (type == GeomType::Line) |
| 684 | { |
| 685 | if (ptsCount > 0) |
| 686 | { |
| 687 | if (ptsCount > 2) |
| 688 | { |
| 689 | uint32_t v = data.m_ptsSimpMask; |
| 690 | int const count = (ptsCount - 2 + 3) / 4; |
| 691 | CHECK_LESS(count, 4, ()); |
| 692 | for (int i = 0; i < count; ++i) |
| 693 | { |
| 694 | WriteToSink(sink, static_cast<uint8_t>(v)); |
| 695 | v >>= 8; |
no test coverage detected